I'm making a simple canvas-based Javascript/HTML game for school. I have a character, moving left or right on a 2d level. Originally, I just added an event listener and in a switch to determine which key was pressed, I would increment the character's location by a certain number of pixels. This caused movement to be very jerky and difficult to work with.
What I want to happen is have smooth movement while the key is pressed, the stop immediately when it is released.
I was thinking that if there were some sort of "while key down" functionality, then I could use that.
If that is the best way to do this, how could I do that, and if there is a better way, I'd love to know it.
NOTE: I'd rather not have to use external libraries. I'm fine with jQuery, but I don't want to have to learn a whole new way to do my game.