{"_id":"@absulit/gamepad.js","_rev":"4-5782384b9d259aa2b9a6fa7c8030fd97","name":"@absulit/gamepad.js","dist-tags":{"latest":"2.0.3"},"versions":{"2.0.0":{"name":"@absulit/gamepad.js","version":"2.0.0","keywords":["control","gaming","controller","xbox","playstation","logitech","gamepad"],"author":{"name":"absulit"},"license":"MIT","_id":"@absulit/gamepad.js@2.0.0","maintainers":[{"name":"absulit","email":"absulitnow@gmail.com"}],"homepage":"https://github.com/Absulit/gamepad.js#readme","bugs":{"url":"https://github.com/Absulit/gamepad.js/issues"},"dist":{"shasum":"328c77d935540b72ae71f691c37d982ad33125b5","tarball":"https://registry.npmjs.org/@absulit/gamepad.js/-/gamepad.js-2.0.0.tgz","fileCount":7,"integrity":"sha512-uGc0vdSeLmlYhiG+lnffYEYRypwLkHHA0B+xVaHApvkWeHN/u8CwKniB8UeusjczwVq7ourcBEd2Kb8aMtXUTw==","signatures":[{"sig":"MEQCIFL7yOffy7E7VS19cA2+nqRd4ExaNJD+3vwlfIE2y9WoAiAVpoCn7BzilQCLT81VQGugq1cA1CJCuDUo86DFxet8BQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":28683},"main":"build/gamepad.min.js","gitHead":"e9539b61b79e8caa2ef7c0d8c7290cf7d6072650","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"absulit","email":"absulitnow@gmail.com"},"repository":{"url":"git+https://github.com/Absulit/gamepad.js.git","type":"git"},"_npmVersion":"9.2.0","description":"Custom implementation of the Gamepad API for gamepads.","directories":{"src":"src","build":"build","example":"example"},"_nodeVersion":"18.19.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/gamepad.js_2.0.0_1752788620222_0.7306745000456425","host":"s3://npm-registry-packages-npm-production"}},"2.0.1":{"name":"@absulit/gamepad.js","version":"2.0.1","keywords":["control","gaming","controller","xbox","playstation","logitech","gamepad"],"author":{"name":"absulit"},"license":"MIT","_id":"@absulit/gamepad.js@2.0.1","maintainers":[{"name":"absulit","email":"absulitnow@gmail.com"}],"homepage":"https://github.com/Absulit/gamepad.js#readme","bugs":{"url":"https://github.com/Absulit/gamepad.js/issues"},"dist":{"shasum":"d9341921a4b728798ed54bd741f0817a5fc6433f","tarball":"https://registry.npmjs.org/@absulit/gamepad.js/-/gamepad.js-2.0.1.tgz","fileCount":8,"integrity":"sha512-LxJZ6iN7tu88/DLEALp3mVEPn9bmBmxmQ3lnlaHMJPGmRN9jvfgpxvzYhGSgoD5N2cLVpVfnW7zEAP1TFAEFew==","signatures":[{"sig":"MEYCIQCg+0EwwObIDrx5BfqwfFe0C0KR5AIE1x1vTW2doZAn6gIhAIqn/WzK186aAMl8dVSekC2GBpItfNupB5Bt2UcFq/F2","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":44509},"main":"build/gamepad.min.js","type":"module","gitHead":"85ee7ddd2bf78663c0c7fcedefb9719eb9461636","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"absulit","email":"absulitnow@gmail.com"},"repository":{"url":"git+https://github.com/Absulit/gamepad.js.git","type":"git"},"_npmVersion":"9.2.0","description":"Custom implementation of the Gamepad API for gamepads.","directories":{"src":"src","build":"build","example":"example"},"_nodeVersion":"18.19.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/gamepad.js_2.0.1_1752875690663_0.8070239111660353","host":"s3://npm-registry-packages-npm-production"}},"2.0.2":{"name":"@absulit/gamepad.js","version":"2.0.2","keywords":["control","gaming","controller","xbox","playstation","logitech","gamepad"],"author":{"name":"absulit"},"license":"MIT","_id":"@absulit/gamepad.js@2.0.2","maintainers":[{"name":"absulit","email":"absulitnow@gmail.com"}],"homepage":"https://github.com/Absulit/gamepad.js#readme","bugs":{"url":"https://github.com/Absulit/gamepad.js/issues"},"dist":{"shasum":"f7d2f1605c86e2e875f6921f3c8a4525d6e556c7","tarball":"https://registry.npmjs.org/@absulit/gamepad.js/-/gamepad.js-2.0.2.tgz","fileCount":9,"integrity":"sha512-nufNOfrtCb+iO0fMkX2EFy7wVm7YNfakgwY+ZLNVIoIcGn3o+qDntF+8RE5Z8raUmRpaaA1YDKIIqPdm7AejPQ==","signatures":[{"sig":"MEQCIFDIlncYjZBkYIOhsKoysomfVHI8Z6AavrN8GPchTRwFAiAXQs2leqGr6x+d+1obQaJFMynf4Del2NXnuNdUGJJ+2w==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":56098},"main":"build/gamepad.min.js","type":"module","gitHead":"a28b8ca5304d3155654142739506c54ba83a7940","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"absulit","email":"absulitnow@gmail.com"},"repository":{"url":"git+https://github.com/Absulit/gamepad.js.git","type":"git"},"_npmVersion":"9.2.0","description":"Custom implementation (wrapper) of the Gamepad API for gamepads.","directories":{"src":"src","build":"build","example":"example"},"_nodeVersion":"18.19.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/gamepad.js_2.0.2_1752974776493_0.02782772848054127","host":"s3://npm-registry-packages-npm-production"}},"2.0.3":{"name":"@absulit/gamepad.js","version":"2.0.3","type":"module","publishConfig":{"access":"public"},"description":"Custom implementation (wrapper) of the Gamepad API for gamepads.","main":"build/gamepad.min.js","directories":{"src":"src","build":"build","example":"example"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/Absulit/gamepad.js.git"},"keywords":["control","gaming","controller","xbox","playstation","logitech","gamepad"],"author":{"name":"absulit"},"license":"MIT","bugs":{"url":"https://github.com/Absulit/gamepad.js/issues"},"homepage":"https://github.com/Absulit/gamepad.js#readme","_id":"@absulit/gamepad.js@2.0.3","gitHead":"71d37e04e1b61a1d40920696d1880410e232aa53","_nodeVersion":"20.19.3","_npmVersion":"10.8.2","dist":{"integrity":"sha512-uMlkmb+6nutOYxswmOVlSsyAa65sa8PUQIbxFQSdrQIu0VHkFO+sBlvg7DszWcxmOn3Y7+v+UTISnhqs3kHJBA==","shasum":"7efd54d6209faa74eb0e06fd69ee9e00915cae3e","tarball":"https://registry.npmjs.org/@absulit/gamepad.js/-/gamepad.js-2.0.3.tgz","fileCount":9,"unpackedSize":56422,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@absulit%2fgamepad.js@2.0.3","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDukBWF+DVHh2ASWmFzZvckapLYKjl1G4PwC9feqAITeQIhAKOosXkdnSVGB1m5GH3whzJCkBXbfwi01Ksvbjx5CGs+"}]},"_npmUser":{"name":"absulit","email":"absulitnow@gmail.com"},"maintainers":[{"name":"absulit","email":"absulitnow@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/gamepad.js_2.0.3_1753058003958_0.9437721355284081"},"_hasShrinkwrap":false}},"time":{"created":"2025-07-17T21:43:40.098Z","modified":"2025-07-21T00:33:24.559Z","2.0.0":"2025-07-17T21:43:40.408Z","2.0.1":"2025-07-18T21:54:50.857Z","2.0.2":"2025-07-20T01:26:16.691Z","2.0.3":"2025-07-21T00:33:24.125Z"},"bugs":{"url":"https://github.com/Absulit/gamepad.js/issues"},"author":{"name":"absulit"},"license":"MIT","homepage":"https://github.com/Absulit/gamepad.js#readme","keywords":["control","gaming","controller","xbox","playstation","logitech","gamepad"],"repository":{"type":"git","url":"git+https://github.com/Absulit/gamepad.js.git"},"description":"Custom implementation (wrapper) of the Gamepad API for gamepads.","maintainers":[{"name":"absulit","email":"absulitnow@gmail.com"}],"readme":"# gamepad.js\n\n![static content to pages](https://github.com/absulit/gamepad.js/actions/workflows/static.yml/badge.svg)\n\nCustom implementation (wrapper) of the Gamepad API for ~~VR and~~ gamepads.\n\nFirst version of the library from 2017, refactored in 2025.\n\nWorks with XBOX and Logitech controllers. I have to test more devices. I will update here when I do so. Or test and [open an issue with a video recording of the tested device.](https://github.com/Absulit/gamepad.js/issues)\n\n# Install\n\n### cdn\n\n```\nhttps://cdn.jsdelivr.net/npm/@absulit/gamepad.js@<version>/build/gamepad.min.js\n\nhttps://cdn.jsdelivr.net/npm/@absulit/gamepad.js@<version>/build/gamepad.module.js\n```\n\n### npm\n```sh\nnpm i @absulit/gamepad.js\n```\n### bun\n```sh\nbunx jsr add @absulit/gamepadjs\n```\n\n# Example:\n\n### Live examples here:\n- [Test control buttons](https://absulit.github.io/gamepad.js/example/base/)\n\n- [Test with a 3d character](https://absulit.github.io/gamepad.js/example/character/)\n\n- [Test with 2 controls](https://absulit.github.io/gamepad.js/example/controls/)\n\n\n```html\n<!-- From example/base/index.html -->\n\n<script type=\"importmap\">\n    {\n        \"imports\": {\n            \"gamepad\": \"https://cdn.jsdelivr.net/npm/@absulit/gamepad.js@<version>/build/gamepad.min.js\",\n        }\n    }\n</script>\n```\n\n```javascript\n// From example/base/main.js\n\nimport { Button, Control, GamepadJS, gamepadInfo } from 'gamepad';\n\n// if no gamepadInfo is set it defaults to one of the controllers\nconst g = new GamepadJS(gamepadInfo)\n\n\ng.onConnected(e => {\n    console.log('---- Gamepad.CONNECTED', e);\n\n    /** @type {Control} */\n    const control = e.detail\n    console.log(control.buttons)\n    const { A, RJX } = control.buttons;\n\n    A.addEventListener(Button.PUSHED, e => {\n        console.log('A - PUSHED');\n    })\n\n    // syntactic sugar\n    A.onPushed(e => {\n        console.log('A - PUSHED 2', e);\n    })\n\n    A.addEventListener(Button.RELEASED, e => {\n        console.log('A - RELEASED');\n    })\n})\n\ng.onDisconnected(e => {\n    console.log('---- Gamepad.DISCONNECTED');\n})\n\nfunction update() {\n    requestAnimationFrame(update);\n\n    output.innerText = '';\n    g.update(controls => {\n        // Controls are named after the index when they are added,\n        // it also depends on how many the browser allows (Chrome has 4 slots)\n        const { control0 } = controls;\n\n        // `touched` property in control verifies if a button has been clicked on it\n        // this to distinguish it from other controls\n        if (control0?.touched) {\n            // the control has a list of buttons and axes, but all listed as buttons\n            const { buttons } = control0;\n            // the names of the buttons are based on the mapping (see gamepadMapping.js)\n            const { A, B, X, Y, LB, RB, LT, RT, VIEW, MENU } = buttons;\n            const { LJB, RJB, UP, DOWN, LEFT, RIGHT } = buttons;\n            // joyticks are returned in `buttons`\n            const { LJX, RJX } = buttons;\n\n            // a button has a `touched` property, if true it has been touched\n            if (A.touched) {\n                console.log('A PRESSED')\n            }\n\n            if (B.touched) {\n                console.log('B PRESSED')\n            }\n\n            // you can detect two or more buttons touched\n            if (A.touched && B.touched) {\n                // you can vibrate the control an amount of time\n                control0.vibrate(100)\n            }\n\n            // triggers have a value property with the amount pressed\n            if (RT.touched) {\n                // you can vibrate the control based on the trigger value\n                control0.vibrate(100, RT.value)\n            }\n\n            if (RJX.touched) {\n                // Joysticks have a rotation angle\n                // and the amount per axis\n                console.log(RJX.angle);\n                console.log(RJX.x);\n                console.log(RJX.y);\n            }\n        }\n    })\n}\n\nupdate()\n\n\n\n// This is old code I need to review. Leaving as a placeholder for now.\n\n// Threejs Mesh called handLeft and handRight for the Touch Controllers hands\n// handLeft.position.fromArray(left.pose.position);\n// handLeft.quaternion.fromArray( left.pose.orientation );\n// handRight.position.fromArray(right.pose.position);\n// handRight.quaternion.fromArray(right.pose.orientation);\n\n```\n\n## example assets\n\nGamepad assets from the example directory from kenney.nl\n[input prompts pixel](https://kenney.nl/assets/input-prompts-pixel-16)\nCreated/distributed by Kenney ([www.kenney.nl](www.kenney.nl))\nLicense: [(Creative Commons Zero, CC0)](https://creativecommons.org/publicdomain/zero/1.0/)\n\n\nSub asset made by [swonky](https://opengameart.org/users/zwonky):\n[submarines](https://opengameart.org/content/submarines-in-arne16)\n\n## bundle and minification\n\n```sh\n# run script to build es6 module and min\nsh build.sh\n```\n","readmeFilename":"README.md"}