A copy of the licensing terms can be viewed below and at the beginning of the JSXinput.js file.
JSXinput encapsulates all its variables in an object named _jsxinput.
This frees you to name your variables anything you like, except "_jsxinput".
Also, a bit of advice about Firefox and gamepads:
Firefox's detection of gamepads is less consistent than Chrome's.
If you have connected gamepads and some are not detected by Firefox, I have found that reconnecting them to different USB ports can correct the issue.
Firefox also disables the gamepad entirely when not on https sites.
The purpose of the mapping menu is to allow the user to map the gamepad devices presented by the browser's DOM to JSpad objects, which more closely resemble the familiar gamepads we all cherish so.
When the mapping menu is exited, the function passed as the mappingExitCallback parameter is called.
mappingExitCallback is expected to be the function that resumes your game's logic after the player exits the controller mapping menu.
If you are familiar with a typical console game controller, you will likely find most JSpad methods intuitive.
JSpads represent the bulk of JSXinput's functionality and the remainder of this page describes their methods.
It is expected that this will be called once per game "tic"; likely near the beginning of your game loop.
They return either 0, 1, or in the case of analog buttons, a floating point value between 0.0 and 1.0 inclusive.
JSpad.X() - corresponds to the left face button in the conventional diamond arrangement.
JSpad.Y() - corresponds to the top face button in the conventional diamond arrangement.
JSpad.A() - corresponds to the bottom face button in the conventional diamond arrangement.
JSpad.B() - corresponds to the right face button in the conventional diamond arrangement.
JSpad.R1() - corresponds to the right front shoulder button.
JSpad.R2() - corresponds to the right rear shoulder button.
JSpad.R3() - corresponds to the right analog stick when pressed as a button.
JSpad.L1() - corresponds to the left front shoulder button.
JSpad.L2() - corresponds to the left rear shoulder button.
JSpad.L3() - corresponds to the left analog stick when pressed as a button.
JSpad.Start() - corresponds to the face button located to the right of the gamepad's center.
JSpad.Select() - corresponds to the face button located to the left of the gamepad's center.
They are intended to enable convenient detection of new button presses (and releases) by comparing the current button state to the previous button state.
They return either 0, 1, or in the case of analog buttons, a floating point value between 0.0 and 1.0 inclusive.
Since the correspondence between buttons and variable names is explained above, it is not repeated here.
JSpad.Xprev()
JSpad.Yprev()
JSpad.Aprev()
JSpad.Bprev()
JSpad.R1prev()
JSpad.R2prev()
JSpad.R3prev()
JSpad.L1prev()
JSpad.L2prev()
JSpad.L3prev()
JSpad.Startprev()
JSpad.Selectprev()
Since the correspondence between buttons and variable names is explained above, it is not repeated here.
JSpad.Xtics()
JSpad.Ytics()
JSpad.Atics()
JSpad.Btics()
JSpad.R1tics()
JSpad.R2tics()
JSpad.R3tics()
JSpad.L1tics()
JSpad.L2tics()
JSpad.L3tics()
JSpad.Starttics()
JSpad.Selecttics()
Since the correspondence between buttons and variable names is explained above, it is not repeated here.
JSpad.Xtime()
JSpad.Ytime()
JSpad.Atime()
JSpad.Btime()
JSpad.R1time()
JSpad.R2time()
JSpad.R3time()
JSpad.L1time()
JSpad.L2time()
JSpad.L3time()
JSpad.Starttime()
JSpad.Selecttime()
They are affected by the anti-drift scan performed in the mapping interface.
JSpad.Lx()
JSpad.Ly()
JSpad.Rx()
JSpad.Ry()
JSpad.dpadX()
JSpad.dpadY()
These methods, like the equivalent for buttons, each return the state of a directional pad's axis prior to the most recent call to JSXinput.update().
Like the methods above, they return -1, 0, or 1.
JSpad.dpadXprev()
JSpad.dpadYprev()
These methods, like the equivalent for buttons, each return the number of times JSXinput.update() has been called since the state of directional pad's axis was zero.
They return integers.
JSpad.dpadXtics()
JSpad.dpadYtics()
These methods, like the equivalent for buttons, each return how long the state of directional pad's axis has been nonzero.
They return the time in milliseconds expressed as an integer.
JSpad.dpadXtime()
JSpad.dpadYtime()
JSXinput adds event listeners to the connectpad and disconnectpad events during gamepad mapping (and removes them after).
If your application also adds event listeners to those events, to avoid conflicting with the events used by JSXinput, instead of using:
window.addEventListener("myConnectEventFunction", connectpad)
or:
window.addEventListener("myDisconnectEventFunction", disconnectpad)
Use the provided methods:
_jsxinput.addHostConnectpadEventListener("myConnectEventFunction")
and
_jsxinput.addHostDisconnectpadEventListener("myDisconnectEventFunction")
respectively.
Likewise, to remove gamepad events, instead of using:
window.removeEventListener("myConnectEventFunction", connectpad)
or:
window.removeEventListener("myDisconnectEventFunction", disconnectpad)
Use the provided methods:
_jsxinput.removeHostConnectpadEventListener("myConnectEventFunction")
and
_jsxinput.removeHostDisconnectpadEventListener("myDisconnectEventFunction")
respectively.
It can cost you only what you can afford to donate and could possibly benefit you.
Notable features include:
- JSXinput presents all gamepads consistently. (In the course of developing JSXinput, I have found that even two gamepads of the same make and model can be presented differently by the same browser!)
- Presents an abstraction of a gamepad, not just a list of axes and buttons.
- Methods for conveniently tracking gamepad state change.
- Allows users to map and remap devices.
- Preserves device mappings in a cookie so users won't need to remap devices unless they want to.
- Detects and eliminates analog input "drift".
- Respects computing resources: All UI elements and events are destroyed when not in use.
- Written in pure javascript without any additional dependencies. Use JSXinput with any javascript libraries you like. Or none at all!