Quantcast
Viewing latest article 8
Browse Latest Browse All 10

bug #1065 – Working on key

For my 0.3 release for dps909, Ive decided to work on bug #1065. The main problem behind this bug is the key, which should be the value of the key pressed, prints out the ascii value instead of the character. Typically this would be simple, but being that javascript does not have a char type, I thought it would be interesting to tackle. I was very lucky, pomax has created a sample program with a chart of all the key codes. Using this chart, I compared the codes that were printed using processing.js. Turns out the key mapping in processing.js was missing some keys, so I added them.
Next is to have the key print out a character instead of an ascii code. Typically this would just involve casting to char but javascript does not have a char type. So I tried this command:

String.fromCharCode(charCodeMap(e.keyCode, e.shiftKey));

This command would take the ascii value return by charCodeMap and return a string of the character. This would be great, but key should hold a char not string. When using the example program, int(key) no long returns the ascii value because it cannot cast the string to and interger. Next I tried this:

new Char(String.fromCharCode(charCodeMap(e.keyCode, e.shiftKey)).charAt(0));

Lets take that string value and create a processing.js Char type. This would work great but turns out that processing.js Char type returns the ascii value and not the character. To retrieve a character, toString() must be used. I can modify processing.js Char to work the way I want and return a character, but then I have broken Char in other places. Seems to be no perfect answer to this bug, functionality compared to p5 will be sacrficed somewhere. I guess I’m off to irc to see what other people think.


Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing latest article 8
Browse Latest Browse All 10

Trending Articles