Haha, wow, you're not kidding about the craziness of keyboard inputs. That stuff is nutty!
I'm also discovering that Processing.js and Processing have very different ideas about what a "char" is. JS seems to always treat it as a number, whereas Processing treats it like a character. My sketch is full of code like:
- String s = "";
- void addLetter(char c) {
- s = s + c;
- }
In Processing, if I say "addLetter(key)", it does what I expect: appends the key I pressed to the end of the string, so typing "abc" results in a string "abc". In JavaScript, bizarrely, the same code converts the char into a number before appending it to the string, so typing "abc" gives you "979899"! Likewise, tests like this work fine in Processing, but fail in Processing.js:
- char c = key;
if (c >= 'a' && c <= 'z') { - addLetter(c);
- } else {
- // it's not a letter
- }
I'm starting to think it might be less work for me to just bite the bullet and develop this as an iOS app... ;-)