All Projects → vaneenige → Unswitch

vaneenige / Unswitch

Licence: mit
🕹 A tiny event handler for Switch controllers!

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Unswitch

stick
Platform-agnostic asynchronous gamepad, joystick and flightstick library for the Rust Programming Language
Stars: ✭ 41 (-92.86%)
Mutual labels:  controller, joystick, gamepad
Segacontroller
Arduino library to read Sega Genesis (Mega Drive) and Master System (Mark III) controllers.
Stars: ✭ 55 (-90.42%)
Mutual labels:  controller, gamepad, joystick
Gilrs
Game Input Library for Rust - Mirror of https://gitlab.com/gilrs-project/gilrs
Stars: ✭ 81 (-85.89%)
Mutual labels:  gamepad, joystick, input
ControlBlockService2
This is the driver for the ControlBlock re.v 2.X, a power switch and input/output/gameapd gadget for the Raspberry Pi
Stars: ✭ 18 (-96.86%)
Mutual labels:  switch, gamepad
Antimicrox
Graphical program used to map keyboard buttons and mouse controls to a gamepad. Useful for playing games with no gamepad support.
Stars: ✭ 226 (-60.63%)
Mutual labels:  controller, gamepad
Node Xbox Controller
🎮 [UNMAINTAINED] Interface for Xbox 360 game controller into Node.js
Stars: ✭ 253 (-55.92%)
Mutual labels:  controller, gamepad
DualSenseWindows UE4
Unreal Engine 4 port of the Windows API for the PS5 DualSense controller created at Ohjurot/DualSense-Windows
Stars: ✭ 25 (-95.64%)
Mutual labels:  controller, gamepad
XB1ControllerBatteryIndicator
A tray application that shows a battery indicator for an Xbox-ish controller and gives a notification when the battery level drops to (almost) empty.
Stars: ✭ 536 (-6.62%)
Mutual labels:  controller, gamepad
mi-360
Xbox360 controller emulation for Xiaomi Gamepad, with vibration support
Stars: ✭ 118 (-79.44%)
Mutual labels:  joystick, gamepad
VGamepad
Server-Side Installer & Instructions
Stars: ✭ 19 (-96.69%)
Mutual labels:  controller, gamepad
joypad.js
JavaScript library that lets you connect and use various gaming controllers with browsers that support the Gamepad API. Less than 5KB in size with zero dependencies and support for button press, axis movement events and vibration play effect.
Stars: ✭ 97 (-83.1%)
Mutual labels:  joystick, gamepad
SwitchXBOXController
Turn your Nintendo Switch into an XBOX360 controller to play on your Windows computer
Stars: ✭ 46 (-91.99%)
Mutual labels:  controller, switch
Controllerx
Create controller-based automations with ease to control your home devices and scenes.
Stars: ✭ 141 (-75.44%)
Mutual labels:  controller, switch
Borealis
Hardware accelerated, controller and TV oriented UI library for PC and Nintendo Switch (libnx).
Stars: ✭ 135 (-76.48%)
Mutual labels:  controller, gamepad
rapp
Cross-platform entry point library
Stars: ✭ 57 (-90.07%)
Mutual labels:  input, controller
Nintendoextensionctrl
Arduino library for communicating with Nintendo extension controllers
Stars: ✭ 67 (-88.33%)
Mutual labels:  controller, joystick
Zwtopselectvcview
快速导入多个控制器,通过顶部选择菜单切换控制器,实现一个页面多个控制器切换处理.(It's an so easy way to add your all kinds of childControllers into superViewController, then you can slide around or just click on the topButton which is automatically building in the topView to switch your childViewController.)
Stars: ✭ 61 (-89.37%)
Mutual labels:  controller, switch
Sys Con
Nintendo Switch sysmodule that allows support for third-party controllers
Stars: ✭ 603 (+5.05%)
Mutual labels:  controller, switch
Vjoy
Virtual Joystick
Stars: ✭ 284 (-50.52%)
Mutual labels:  gamepad, joystick
RockerView
A game controller view
Stars: ✭ 21 (-96.34%)
Mutual labels:  controller, joystick

Unswitch

npm version gzip size license dependencies

Unswitch is a tiny event handler for Switch controllers on the web based on the Gamepad API. Attach callbacks to button presses (up & down) and the joystick!

Install

$ npm install --save unswitch

Use script tags or modules? Check out the version on unpkg!

Setup

Connecting a Switch controller is easy: pair it with bluetooth and you're ready to go! This library doesn't listen to connected or disconnected events but in some cases it might be useful. Here's how you can listen to these events:

window.addEventListener("gamepadconnected", ({ gamepad }) => {});
window.addEventListener("gamepaddisconnected", ({ gamepad }) => {});

Usage

// Import the library
import Unswitch from 'unswitch';

// Observe a controller
const unswitch = new Unswitch({
  side: 'L', // or R
  buttons: (button, pressed, side) => console.log(`Catch-all - button: ${button} was ${pressed ? 'pressed' : 'released'} on the ${side} side`),
  b: p => {},
  a: p => {},
  y: p => {},
  x: p => {},
  sl: p => {},
  sr: p => {},
  minus: p => {},
  plus: p => {},
  lstick: p => {},
  rstick: p => {},
  home: p => {},
  screenshot: p => {},
  bumper: p => {}, // L or R
  trigger: p => {}, // ZL or ZR
  axes: p => {},
});

function render() {
  // Call the update function manually
  unswitch.update();
  requestAnimationFrame(render);
}

render();

Please note that it's not required to pass all button-functions to Unswitch and will only be executed when you provide them. You are able to use the buttons function to catch all button presses and implement your own logic using the provided data. The buttons function will always be executed when provided, even when the button is also passed as property.

It's possible to connect up to two controllers at the same time. To make this work side is to be passed with either L (left) or R (right) for the controllers respectively. Calling unswitch.update() will check every button for a change in state. If a callback is provided the new state is passed along. The axis works in the same way, but instead of a boolean it will return a number from 0 to 8. Number 0 to 7 are for the joystick positions going clockwise, number 8 is used as default (center).

Have a look at the demo on Codepen!

Contribute

Are you excited about this library and have interesting ideas on how to improve it? Please tell me or contribute directly! 🙌

npm install > npm run demo > http://localhost:8080

License

MIT © Colin van Eenige

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].