You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// print the current versionconsole.log('Keyboard VERSION: ',Keyboard.VERSION)// instantiateconstkeyboard=newKeyboard()// watch all keys downkeyboard.watch.down(keyCode=>{console.log('down',keyCode)})// watch all keys upkeyboard.watch.up(keyCode=>{console.log('up',keyCode)})// listen for Q downkeyboard.on.down('KeyQ',keyCode=>{console.log(`${keyCode} is down.`)})// listen for L, K or Space downkeyboard.on.down('KeyL KeyK Space',keyCode=>{console.log(`${keyCode} is down.`)constL=keyboard.key('KeyL').isDownconstK=keyboard.key('KeyK').isDownconstSpace=keyboard.key('Space').isDownif(L&&K&&Space){console.log('All 3 keys are down!')}})// listen for L upkeyboard.on.up('KeyL',()=>{console.log('KeyL is up.')})// listen for key E or R down (once)keyboard.once.down('KeyE KeyR',keyCode=>{console.log(`${keyCode} is down.`)})// check if W is downkeyboard.key('KeyW').isDown// check if U is upkeyboard.key('KeyU').isDown// check if pausedkeyboard.isPaused// pause all events (except .once())keyboard.pause()// resume all eventskeyboard.resume()// destroy all events once you are donekeyboard.destroy()
KeyCode
This library always uses the keyCode (KeyboardEvent.code).
Why? Read this:
The code attribute
First up is the code attribute. This is set to a string representing the key that was pressed to generate the KeyboardEvent, without taking the current keyboard layout (for example, QWERTY vs. Dvorak), locale (for example, English vs. French), or any modifier keys into account. This is useful when you care about which physical key was pressed, rather than which character it corresponds to. For example, if you’re a writing a game, you might want a certain set of keys to move the player in different directions, and that mapping should ideally be independent of keyboard layout.