A spec change that keeps coming back to haunt me
peter | 24 June, 2011 | 13:22At some point, the way firefox handles keyboard events changed. I’m not sure exactly when it happened, all I know is that it broke how I was dealing with keyboard interaction on almost every demo I’ve written (for example,the mocap demo and MotionView). When I wrote the demos, the keydown event would be fired once, when the user initially pressed the key (it still works this way on the other browsers as far as I can tell), but at some point that I missed it got changed to firing on every update for as long as the key is held (or until you press another key, at which point the keydown event will start firing repeatedly for that key). Several of the demos and tests I have written relied on the keydown event to start moving something in the scene (usually the camera). Unfortunately, when the event switched over to firing repeatedly as long as a key is held, this caused uncontrollable acceleration which could only be countered by holding a key for the opposite movement a corresponding amount of time.
I accommodated for this by adding a check into the function that handles that event to compare the key most recently pressed to the previous key pressed (which starts off as a value of -1, and must be reset to that whenever the most recent key pressed is released) and only causes the movement if they do not match. I think I’ve added this into the various demos that require it, but if you find any of them have weird camera movement that just doesn’t behave right, let me know in the comments.
