Created
November 9, 2016 04:53
-
-
Save karanjthakkar/9a5df91c1726ba53896228f51185740e to your computer and use it in GitHub Desktop.
Khalid keystate example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*eslint fp/no-unused-expression: 0, fp/no-nil: 0 */ | |
const Keystate = { | |
rightPressedKey: false, | |
leftPressedKey: false, | |
spacePressedKey: false, | |
rPressedKey: false, | |
addListeners: function() { | |
document.addEventListener("keyup", e => { | |
if (e.keyCode === 37) { | |
Keystate.leftPressedKey = false; | |
} else if (e.keyCode === 39) { | |
Keystate.rightPressedKey = false; | |
} else if (e.keyCode === 32) { | |
Keystate.spacePressedKey = false; | |
} else if (e.keyCode === 82) { | |
Keystate.rPressedKey = false; | |
} | |
}); | |
document.addEventListener('keydown', e => { | |
if (e.keyCode === 37) { | |
Keystate.leftPressedKey = true; | |
} else if (e.keyCode === 39) { | |
Keystate.rightPressedKey = true; | |
} else if (e.keyCode === 32) { | |
Keystate.spacePressedKey = true; | |
} else if (e.keyCode === 82) { | |
Keystate.rPressedKey = true; | |
} | |
}); | |
} | |
}; | |
export default Keystate; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment