UNPKG

gamepad-node

Version:

Browser Gamepad API implementation for Node.js with native SDL2 bindings

35 lines (26 loc) 924 B
import sdl from '@kmamal/sdl'; console.log('Listening for ALL SDL events...\n'); let buttonCount = 0; let axisCount = 0; sdl.controller.on('deviceAdd', (e) => { console.log('DEVICE ADD:', e.device.name); }); sdl.controller.on('deviceRemove', (e) => { console.log('DEVICE REMOVE:', e.device.name); }); sdl.controller.on('buttonDown', (e) => { buttonCount++; console.log(`BUTTON DOWN #${buttonCount}:`, e.button, 'on', e.device.name); }); sdl.controller.on('buttonUp', (e) => { console.log('BUTTON UP:', e.button); }); sdl.controller.on('axisMotion', (e) => { if (Math.abs(e.value) > 0.2) { axisCount++; console.log(`AXIS MOTION #${axisCount}:`, e.axis, '=', e.value.toFixed(2)); } }); console.log('Controllers:', sdl.controller.devices.map(d => d.name)); console.log('\nPress buttons and move sticks...'); console.log('If nothing appears, SDL is not receiving events!\n');