Created
August 28, 2017 23:16
-
-
Save pta2002/1e551c770ceac87a20f3b7aa3cdcf0a9 to your computer and use it in GitHub Desktop.
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
import $ from 'jquery' | |
let keys = {} | |
$(document).keydown((e) => { | |
keys[e.key] = true | |
}) | |
$(document).keyup((e) => { | |
keys[e.key] = false | |
}) | |
module.exports = { | |
isDown(key) { | |
if (keys[key]) | |
return true | |
return false | |
}, | |
Key(key) { | |
return { | |
isDown() { | |
if (keys[key]) | |
return true | |
return false | |
}, | |
onDown(callback) { | |
$(document).keydown((e) => { | |
if (e.key === key) | |
callback() | |
}) | |
}, | |
onUp(callback) { | |
$(document).keyup((e) => { | |
if (e.key === key) | |
callback() | |
}) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment