I do not believe that there is something like the isKeyDown function, but you can write your own.
Basically, create an array whose length is the number of keys that you want to control. Then, using the keyUp and keyDown documents / pages / controls, update the array with this key state.
Then write a function that checks if a particular key is disabled and returns bool.
var keyEnum = { W_Key:0, A_Key:1, S_Key:2, D_Key:3 }; var keyArray = new Array(4); function onKeyDown() { // Detect which key was pressed if( key == 'w' ) keyArray[keyEnum.W_Key] = true; // Repeat for each key you care about... } function onKeyUp() { // Detect which key was released if( key == 'w' ) keyArray[keyEnum.W_Key] = false; // Repeat for each key you care about... } function isKeyDown(key) { return keyArray[key]; }
This should do what you want.
TJMonk15 Dec 01 '09 at 20:27 2009-12-01 20:27
source share