
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
responsive-gamepad
Advanced tools
Handle Keyboard, Gamepad, and Touch Controls in the browser under a single API, (< 5KB).
This is a quick Tl;DR on installing and using responsive-gamepad:
npm install --save responsive-gamepad
import { ResponsiveGamepad } from 'responsive-gamepad';
ResponsiveGamepad.enable();
ResponsiveGamepad.getState();
Please see the Input Map section for what Responsive Gamepad Keys represent on a "Standard" Controller.
responsive-gamepad
See the demo/index.js, for a proper usage, and touch input example
npm install --save responsive-gamepad
Additional information/exports concerning can be found in the Input Map section.
For user journeys, and common How-To use cases, see the design directory
First, import the ResponsiveGamepad
singleton service with:
import ResponsiveGamepad from 'responsive-gamepad'
Properties accessed from: ResponsiveGamepad
.
getVersion()
: string - Returns the current version of the lib.
enable()
: void - Enables ResponsiveGamepad
, and listens for events.
disable()
: void - Removes all listeners from ResponsiveGamepad, and stops listening.
isEnabled()
: boolean - Returns if ResponsiveGamepad
is currently enabled.
addPlugin(myPlugin)
: function - Adds a plugin to be used with the lib. Returns a function to remove the added plugin.
getState()
: ResponsiveGamepadState - Returns an object with the current state of ResponsiveGamepad. See the Demo and the Input Map.
onInputsChange(ArrayOfResponsiveGamepadInputs, callback)
: function - Function to listen for changes on the array of specified ResponsiveGamepad.RESPONSIVE_GAMEPAD_INPUTS
, and calls a callback whenever they change. Returns a function to stop listening.
clearInputMap()
: Remove all input mappings. Useful if you don't want (some of) the default input map.
Properties accessed from: ResponsiveGamepad.Keyboard
.
enableIgnoreWhenInputElementFocused()
: void - Enables ignoring ResponsiveGamepad Keyboard input when focused on form input type elements. Enabled by default.
disableIgnoreWhenInputElementFocused()
: void - Disables the above.
enableIgnoreWhenModifierState()
: void - Enables ignoring ResponsiveGamepad Keyboard input when a Modifier key is pressed. See KeyboardEvent.getModifierState() for more reference. Enabled by default.
disableIgnoreWhenModifierState()
: void - Disables the above.
setKeysToResponsiveGamepadInput(ArrayOfKeyboardEventCodes, ResponsiveGamepadInput)
: void - Function used for modifying the input map. Takes and array of KeyboardEvent.code and a single ResponsiveGamepad.RESPONSIVE_GAMEPAD_INPUTS
.
Properties accessed from: ResponsiveGamepad.Gamepad
.
getState(PlayerIndex: number)
: GamepadState - Function that takes in a player index (0, 1, 2) from the connected gamepads. Returns a ResponsiveGamepad.getState()
like Object. Can be used for multiplayer.
setGamepadButtonsToResponsiveGamepadInput(ArrayOfGamepadButtonIds, NonAxisResponsiveGamepadInput)
: void - Function used for modifying the input map. Takes and array of Gamepad Button Ids and a single ResponsiveGamepad.RESPONSIVE_GAMEPAD_INPUTS
.
setGamepadAxisToResponsiveGamepadInput(GamepadAxisIds, AxisResponsiveGamepadInput)
: void - Function used for modifying the input map. Takes a single Gamepad Axis Id and a single ResponsiveGamepad.RESPONSIVE_GAMEPAD_INPUTS
.
Properties accessed from: ResponsiveGamepad.TouchInput
.
The functions that add inputs to the ResponsiveGamepad
have additional functionality outside of what is shown below. When inputs are added, they will have styles applied to help with them being touchable. Also, When the touch input becomes active, it will add the CSS class active
to the element.
addButtonInput(HTMLElement, ResponsiveGamepadInput)
: void - Function that takes in a HTML Element (e.g document.getElementById
), and a ResponsiveGamepad.RESPONSIVE_GAMEPAD_INPUTS
. Will add the element as an interactive button for the ResponsiveGamepad.
addDpadInput(HTMLElement, configurationObject)
: void - Function that takes in a HTML Element (e.g document.getElementById
), and a configurationObject
. Will add the element as an interactive dpad for the DPAD_UP
, DPAD_RIGHT
, DPAD_LEFT
, and DPAD_DOWN
inputs. The configuration object is outilined below:
const configurationObject = {
allowMultipleDirections: false // False by default. This will allow for multiple directions (diagonal) inputs.
}
addLeftAnalogInput(HTMLElement)
: void - Function that takes in a HTML Element (e.g document.getElementById
). Will add the element as an interactive virtual joystick for the LEFT_ANALOG_HORIZONTAL_AXIS
, LEFT_ANALOG_VERTICAL_AXIS
, LEFT_ANALOG_UP
, LEFT_ANALOG_RIGHT
, LEFT_ANALOG_DOWN
, LEFT_ANALOG_LEFT
inputs.
addRightAnalogInput(HTMLElement)
: void - Function that takes in a HTML Element (e.g document.getElementById
). Will add the element as an interactive virtual joystick for the RIGHT_ANALOG_HORIZONTAL_AXIS
, RIGHT_ANALOG_VERTICAL_AXIS
, RIGHT_ANALOG_UP
, RIGHT_ANALOG_RIGHT
, RIGHT_ANALOG_DOWN
, RIGHT_ANALOG_LEFT
inputs.
The default input map is based on the "Standard" controller. Here is a modified image from the w3c gamepad draft on how it correlates to the default input map:
Note: The X in something like INPUT_X
represents one of the many directions or axis it represents
To see how the keyboard relates to the input map, please see the default input map. The library uses KeyBoardEvent.code to denote all of it's keyboard keys.
Plugins allow for modifying the output from getState(). Which can allow for functionality like:
Merging multiple inputs into one
Adding additional keys for something like another input source.
Etc...
responsive-gamepad
Plugins should follow the rollup plugin conventions:
Plugins should have a clear name with responsive-gamepad-plugin-
prefix.
Include rollup-plugin
keyword in package.json.
Document your plugin in English.
For and example, see the demo ExamplePlugin.
Plugins are simply functions that return an object. See the following example, for what functions the return object could have:
export default function ReadmePlugin() {
return {
onAddPlugin: () => {
// Called when the plugin is added with: 'ResponsiveGamepad.addPlugin()'
},
onGetState: (CurrentResponsiveGamepadState) => {
// Called whenever 'ResponsiveGamepad.getState()' is called.
return CurrentResponsiveGamepadState
}
}
}
Open a PR to have your plugin featured here!
Feel free to fork the project, open up a PR, and give any contributions! I'd suggest opening an issue first however, just so everyone is aware and can discuss the proposed changes.
Just your standard node app. Install Node with nvm, git clone
the project, and npm install
, and you should be good to go!
# Command to serve the demo/lib and watch for changes (No livereload)
npm start
# Alias for npm start
npm run dev
# Build the library and demo souce
npm run build
LICENSE under Apache 2.0
Touch Input SVGS on the responsive gamepad demo, are Google Material Icons
XInput vs. DirectInput - Microsoft Article, Reddit thread
FAQs
Handle Keyboard, Gamepad, and Touch Controls under a single API
We found that responsive-gamepad demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.