user3795767
user3795767

Reputation: 1

JavaScript keyup handling

I'm building a GIF animation based movement system for my game.

The question is, once the keycode (lets say 37) is down, how do I detect if/when that certain key is up?

I want to move the charater and play the GIF while the key is down, but I need to stop the animation and stop the character from moving when the key is up.

Upvotes: 0

Views: 45

Answers (1)

Legendary_Linux
Legendary_Linux

Reputation: 1559

I assume you're using the onkeydown event described here to catch an action:
http://www.w3schools.com/jsref/event_onkeydown.asp

Why not use the opposite function to detect when an action should stop? It's called onkeyup, and it's described here:
http://www.w3schools.com/jsref/event_onkeyup.asp

Upvotes: 1

Related Questions