July 20, 2010 Leave a comment
For the last week and a half, I’ve been working on making Processing.js (Pjs) keys and keystrokes work more like its Processing (p5) counterpart. Actually, it was originally already set for review but the reviewers didn’t wish to implement browser detection. So, I’ve been focusing on feature detection for keys within Pjs. Now this fix doesn’t seem very hard, only if the browser vendors actually standardized their key presses and key strokes. Instead, they like to use the method of “ours is better, so do it our way”, which isn’t very helpful to the developers. I’ll explain my situation and why I’m so stressed and frustrated about this particular fix.
Key codes are not a particular problem within this situation. Most of the keys/code values are either similar or there’s already existing code to account for different codes. Not something I’m worried about in terms of Pjs. Key strokes and repeating is the bigger hassle in this. There’s also the fact that some browsers use charCode instead of keyCode or vice versa. Those two combinations by themselves can create a huge mess. I’m just glad the actual codes aren’t completely different as well, or this would be an even bigger headache.
I’ll start off by saying that there’s three different type of key press events. First is keydown, when you push down a key. Then it’s counterpart is keyup, when you release a key. The last is keypress, which determines if a key is being held down. Coded keys are keys in the keyboard that can alter the given keycode when a key is pressed. The five main keys are Ctrl, Alt, Shift, Caps Lock and Num Lock. Char keys are essentially anything that can produce a character. The movement keys allow movement through the document and then there’s the F keys.
|char keys refires all events when key is being held down||char keys refires keypress event when key is being held down||char keys refires keypress and keydown event when key is being held down|
|coded keys do not get refired when being held down, keypress value does not exist||coded keys do not get refired when being held down, keypress value does not exist||coded keys do not get refired when being held down, keypress value does not exist|
|movement and f keys refire keydown and keyup events when held down, keypress value does not exist||movement and f keys refire the keypress event when held down||movement and fkeys refire the keydown event when held down, keypress value does not exist|
|All platforms deploy keydown event when a key is pressed and keyup event when a key is released.|
They may seem like minor differences but setting them from two differing places to one uniform place creates a lot of problems. When I was correcting small bugs that came up, another one would pop up and it just kept going until I lost track of what fixes I did for certain bugs. I’d end up having to restart from a clean slate to begin the comprehension again. Anyway, I know people are looking to get this working properly as I’m getting hits on my blog about keys in Pjs. I’ll make sure it gets in before 1.0!