/keyb

Poll the state of the keyboard.

Primary LanguageJavaScript

Keyb

A javascript utility for polling the state of the keyboard.

Usage

For any given frame of your game loop, you can poll if a key is being pressed using Keyb.isPressed(keyname):

if(Keyb.isPressed("W")) {
    player.position.y -= 1
}
if(Keyb.isPressed("S")) {
    player.position.y += 1
}
if(Keyb.isPressed("A")) {
    player.position.x -= 1
}
if(Keyb.isPressed("D")) {
    player.position.x += 1
}

All methods accept a keyname as defined in vkey, such as 1 or A or <enter>. Visit their test page to identify what keyname to use for each key on the keyboard.

License

This project is licensed under the MIT license.