3

I use a device driver that captures the input from a reader (RFID) and sends it to the keyboard buffer (keyboard wedge). The captured data can (and must) be transformed intermediately with java script.

This javascript is processed within the driver context - unfortunately the javascript gets the captured "binary" data in a DATA variable of type string.

You can imagine what javascript does: it interprets the input as unicode and thus does not let you address byte by byte within the string - it changes arbitrarily between 1 ...4 bytes length depending on the value.

I simply need to get the binary string transformed to its readable string format: xf9268970 should read "f9268970". Whatever I tried sucked so far.

Thanks for any tip!

3
  • Are you capturing it in a text field, or are you listening to keystrokes and capturing the ASCII values? Commented May 4, 2012 at 15:17
  • Do you have access to the driver source? Commented May 4, 2012 at 15:55
  • Nope - no access to the driver source. It is a generic Windows driver (a keyboard wedge directing COM input to the keyboard - with javascript transformation) Commented May 9, 2012 at 13:18

2 Answers 2

1

First, a disclaimer. I haven't worked with binary data and javascript but maybe this could help.

Maybe you could loop through the string and use charAt to look at each character. From what I understand charAt returns an ASCII value (not unicode). So instead of 4 bytes you would get 2 bytes(?)

var character;
for (var i = 0; i < str.length; i++) {
    character = str.charAt(i);
}

Maybe this reference will point you in the right direction: charAt reference

Sign up to request clarification or add additional context in comments.

2 Comments

Unfortunately charAt and string length do not work on a one-character-per-code basis as you can see in the following example html page - it returns length=1 even if the code is 6 bytes long :-(
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script> var test = String.fromCharCode(0xFE707f75fe45); var out = '<b>fromCharCode(0xFE707f75fe45):</b>' + '<br>' + 'length= ' + test.length + '<br>' + 'charAt(0)= ' + test.charAt(0) + '<br>' + 'charAt(1)= ' + test.charAt(1) + '<br>' ; document.writeln(out); </script> </head>
0

I think you should be listening for keystrokes individually and recording the values in a variable instead of reading a text box.

5 Comments

As said: I cannot influence the way the data gets to the javascript as it is a driver-built-in javascript feature. I just get what the scanner reads. -Klaus
Because it is a keyboard wedge, you should be able to hook up a key listener in your own JS code. I've done this with a bardcode scanner that uses a keyboard wedge.
You mean a key listener in the receiving input field?? But there are many - some within web pages, could even be an Excel cell ... so this might be the wrong place to do!
A key listener is universal. It does not depend of focus on an input, although you CAN make it so it drops out of the function if the input element does not have focus just by setting your own flag.
I am afraid this goes beyond my capabilities ...and exceeds the effort I am willing to spend incl. support as this adjusted wedge should be rolled out to many computers, not just mine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.