GAMEPUT
Simple javascript input manager. Listen to key+mouse combinations easily. Now with experimental gamepad support.
Main functions
-
GAMEPUT.bind(combinations, callback, prevent_repeat): binds the given combinations to the callback. This function does not support gamepads yet - combinations: A group of space-separated combinations. A combination contains one or more keys and mouse buttons identified by their names and separated by plus signs.
- callback: The function to be called.
- prevent_repeat: if true, Gameput will fire the callback function only once even if the keys remain pressed. Optional. Default: true
-
GAMEPUT.isPressed(combinations): Returns true if any of the combinations is being pressed at the moment the function is called. -
GAMEPUT.getGamepads(): Returns the connected gamepads as an array. -
GAMEPUT.getAxis(name): Returns the state of the named axis, a number between -1.0 and 1.0.
Examples
- Listen to a
shift + Jorcontrol + 9combination:
GAMEPUT.bind("shift+j control+9", function(e) { /* Do stuff */ });
- Listen to a
G + Left mouse button:
GAMEPUT.bind("g+mouseleft", function(e) { /* Do other stuff */ });
- Is a combination pressed at some point?:
GAMEPUT.isPressed("p+e+altgr+mousecenter");
- Is the second right button of the third gamepad pressed?:
GAMEPUT.isPressed("gamepad3/R2")
- What is the state of the right vertical analogue stick of the first gamepad?
GAMEPUT.getAxis("gamepad1/rightanaloguevert")
- Is the button 836 of the first gamepad pressed?
GAMEPUT.isPressed("gamepad1/button/836")
Supported keys/buttons
Keyboard
backspacetabentershiftcontrolaltcapslockaltgrdelpagedownpageupendhomeleftuprightdown-
boardplus: The plus sign in the main keyboard (not the numeric pad) -
numpadplus: The plus sign in the numeric pad -
plus: Triggers by pressingboardplusornumpadplus. -
boardhyphen: Hyphen in the main keyboard -
numpadhyphen: Hyphen in the numeric pad -
hyphen:boardhyphenornumpadhyphen -
minus: Same ashyphen space-
leftwindows: Left Windows key -
rightwindows: Right Windows key -
windows:leftwindowsorrightwindows -
abcdefghijklmnopqrstuvwxyz -
numpad0numpad1numpad2numpad3numpad4numpad5numpad6numpad7numpad8numpad9: Numbers in the numeric pad -
board0board1board2board3board4board5board6board7board8board9: Numbers in the main keyboard -
0123456789: Numbers in the numeric pad or the main keyboard
Mouse
mouseleftmouserightmousecenter-
mousecentre: Same asmousecenter -
click: Any mouse button
Gamepad (experimental)
The gamepads have an special notation, as there can be more than one gamepad connected. The format is gamepad_name/button_or_axis_name
-
gamepad1gamepad2gamepad3gamepad4... : The gamepad names are just the word gamepad followed by its number -
1234L1L2R1R2startselectleftanaloguerightanaloguepaduppaddownpadleftpadright: The buttons of the gamepad. A gamepad might not have some of these buttons, but this list responds to a standard in gamepads. The analogue buttons are analogue sticks pressed. -
leftanaloguehorleftanaloguevertrightanaloguehorrightanaloguevert: The standard axes. When asking about an axis with theGAMEPUT.isPressedfunction, if will only return true if the axis is pressed beyond the 0.1 or the -0.1 threshold.
There's another way to ask about the buttons and axes, in case you don't like these names, or if you need more buttons and axes.
-
button/1button/2button/3button/4... : A button identified by its number. -
axis/1axis/2axis/3axis/4... : An axis identified by its number.