{"id":18578743,"url":"https://github.com/cdleveille/gamepad-helper","last_synced_at":"2025-04-10T10:31:22.226Z","repository":{"id":44793796,"uuid":"389398889","full_name":"cdleveille/gamepad-helper","owner":"cdleveille","description":"Lightweight, zero-dependency wrapper class for the HTML5 Gamepad API.","archived":false,"fork":false,"pushed_at":"2023-09-27T02:06:44.000Z","size":89,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T19:39:36.332Z","etag":null,"topics":["gamepad","gamepad-api","html5","javascript","javascript-game","js","npm","npm-package","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/gamepad-helper","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cdleveille.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-25T17:00:57.000Z","updated_at":"2023-11-09T05:14:06.000Z","dependencies_parsed_at":"2024-11-06T23:39:19.381Z","dependency_job_id":null,"html_url":"https://github.com/cdleveille/gamepad-helper","commit_stats":{"total_commits":23,"total_committers":1,"mean_commits":23.0,"dds":0.0,"last_synced_commit":"3c7fffa9a1821962cd2f93329c3a6ca975e5f5f1"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdleveille%2Fgamepad-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdleveille%2Fgamepad-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdleveille%2Fgamepad-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdleveille%2Fgamepad-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cdleveille","download_url":"https://codeload.github.com/cdleveille/gamepad-helper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248199136,"owners_count":21063641,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gamepad","gamepad-api","html5","javascript","javascript-game","js","npm","npm-package","typescript"],"created_at":"2024-11-06T23:37:13.403Z","updated_at":"2025-04-10T10:31:21.895Z","avatar_url":"https://github.com/cdleveille.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gamepad-helper\r\n\r\nLightweight, zero-dependency wrapper class for the HTML5 Gamepad API.\r\n\r\n```bash\r\n$ npm i gamepad-helper\r\n\r\n$ yarn add gamepad-helper\r\n```\r\n\r\nSimply install the package via npm or yarn. You will need to use a module bundler like [webpack](https://webpack.js.org/) to access it in your client-side code.\r\n\r\nThe `GamepadHelper` class can be imported and used by calling the `GamepadHelper.update()` static method within your game loop.\r\n\r\n```javascript\r\nimport { GamepadHelper } from \"gamepad-helper\";\r\n\r\n// ...within game loop\r\nGamepadHelper.update();\r\n```\r\n\r\nWhen a button on a connected gamepad is pressed or released, a `CustomEvent` will be dispatched to the document containing a `detail` property identifying the gamepad/button that was pressed/released.\r\n\r\nThere are two `CustomEvent` types:\r\n\r\n-   `gamepadbuttondown` - dispatched when the `value` property of any button changes from `0` to `1`\r\n-   `gamepadbuttonup` - dispatched when the `value` property of any button changes from `1` to `0`\r\n\r\nHere is an example that simply logs the gamepad/button that was pressed down:\r\n\r\n```javascript\r\n// JavaScript\r\ndocument.addEventListener(\"gamepadbuttondown\", (event) =\u003e {\r\n\tconst { button, gamepad } = event.detail;\r\n\tconsole.log(`button ${button} on gamepad ${gamepad} was pressed down`);\r\n});\r\n\r\n// TypeScript\r\nimport type { IGamepadButtonEventDetail } from \"gamepad-helper\";\r\ndocument.addEventListener(\"gamepadbuttondown\", (event: CustomEvent\u003cIGamepadButtonEventDetail\u003e) =\u003e {\r\n\tconst { button, gamepad } = event.detail;\r\n\tconsole.log(`button ${button} on gamepad ${gamepad} was pressed down`);\r\n});\r\n```\r\n\r\nHere is an example which causes player 1 to jump if button 0 on gamepad 0 is released:\r\n\r\n```javascript\r\n// JavaScript\r\ndocument.addEventListener(\"gamepadbuttonup\", (event) =\u003e {\r\n\tconst { button, gamepad } = event.detail;\r\n\tif (gamepad === 0 \u0026\u0026 button === 0) {\r\n\t\tplayer1.jump();\r\n\t}\r\n});\r\n\r\n// TypeScript\r\nimport type { IGamepadButtonEventDetail } from \"gamepad-helper\";\r\ndocument.addEventListener(\"gamepadbuttonup\", (event: CustomEvent\u003cIGamepadButtonEventDetail\u003e) =\u003e {\r\n\tconst { button, gamepad } = event.detail;\r\n\tif (gamepad === 0 \u0026\u0026 button === 0) {\r\n\t\tplayer1.jump();\r\n\t}\r\n});\r\n```\r\n\r\nThe instantaneous state of any button or axis on a connected gamepad can also be queried via the `GamepadHelper.getButtonValue()` and `GamepadHelper.getAxisValue()` static methods.\r\n\r\nTo log informational output to the console, set `GamepadHelper.logOutput` to `true` (`false` by default):\r\n\r\n```javascript\r\nGamepadHelper.logOutput = true;\r\n```\r\n\r\n```text\r\ngamepad 0 connected\r\ngamepad 0: button 0 is down\r\ngamepad 0: button 0 is up\r\n```\r\n\r\nCheck it out on npm:\r\n\r\n-   https://www.npmjs.com/package/gamepad-helper\r\n\r\nMore info on the Gamepad API:\r\n\r\n-   https://www.w3.org/TR/gamepad/\r\n-   https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API/Using_the_Gamepad_API\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdleveille%2Fgamepad-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcdleveille%2Fgamepad-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdleveille%2Fgamepad-helper/lists"}