{"id":17482802,"url":"https://github.com/creationix/node-gamepad","last_synced_at":"2025-03-17T12:08:26.111Z","repository":{"id":21779120,"uuid":"25101470","full_name":"creationix/node-gamepad","owner":"creationix","description":"node.js bindings for Alex Diener's cross-platform gamepad code","archived":false,"fork":false,"pushed_at":"2022-12-07T17:52:22.000Z","size":249,"stargazers_count":100,"open_issues_count":17,"forks_count":25,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-04T23:35:48.786Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://forums.tigsource.com/index.php?topic=10675.0","language":"C","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/creationix.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}},"created_at":"2014-10-12T00:54:17.000Z","updated_at":"2025-02-10T21:11:40.000Z","dependencies_parsed_at":"2023-01-13T21:40:26.951Z","dependency_job_id":null,"html_url":"https://github.com/creationix/node-gamepad","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creationix%2Fnode-gamepad","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creationix%2Fnode-gamepad/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creationix%2Fnode-gamepad/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creationix%2Fnode-gamepad/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/creationix","download_url":"https://codeload.github.com/creationix/node-gamepad/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244031021,"owners_count":20386534,"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":[],"created_at":"2024-10-18T23:45:00.110Z","updated_at":"2025-03-17T12:08:26.092Z","avatar_url":"https://github.com/creationix.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"node-gamepad\n============\n\n[![Build Status](https://travis-ci.org/creationix/node-gamepad.svg?branch=master)](https://travis-ci.org/creationix/node-gamepad)\n[![Build status](https://ci.appveyor.com/api/projects/status/eumj8o5ubun88q8b/branch/master?svg=true)](https://ci.appveyor.com/project/creationix/node-gamepad/branch/master)\n\nBindings for Alex Diener's cross-platform gamepad code\n\nThe library is tiny and included inside this addon so you don't need any special libraries installed on your system like SDL.\n\nTo install as a dependency simple type the following in your project's folder:\n\n```sh\nnpm install gamepad\n```\n\n## Examples\n\n```js\nvar gamepad = require(\"gamepad\");\n\n// Initialize the library\ngamepad.init()\n\n// List the state of all currently attached devices\nfor (var i = 0, l = gamepad.numDevices(); i \u003c l; i++) {\n  console.log(i, gamepad.deviceAtIndex());\n}\n\n// Create a game loop and poll for events\nsetInterval(gamepad.processEvents, 16);\n// Scan for new gamepads as a slower rate\nsetInterval(gamepad.detectDevices, 500);\n\n// Listen for move events on all gamepads\ngamepad.on(\"move\", function (id, axis, value) {\n  console.log(\"move\", {\n    id: id,\n    axis: axis,\n    value: value,\n  });\n});\n\n// Listen for button up events on all gamepads\ngamepad.on(\"up\", function (id, num) {\n  console.log(\"up\", {\n    id: id,\n    num: num,\n  });\n});\n\n// Listen for button down events on all gamepads\ngamepad.on(\"down\", function (id, num) {\n  console.log(\"down\", {\n    id: id,\n    num: num,\n  });\n});\n\n```\n\n## Events\n\nThere are 5 event types `attach`, `remove`, `down`, `up`, and `move`.  All pass the session id of the gamepad as the first argument.\n\nThe `attach` event also passes current state as the second arg to attach.\n\nThe `down` and `up` events also pass in the button id and timestamp after device session id.\n\nThe `move` event passes axis, value, old value and timestamp after session id.\n\n## Functions\n\n### gamepad.init()\n\nInitializes gamepad library and detects initial devices. Call this before any\nother library function. If you want to receive attach events callbacks from\ndevices detected in `gamepad.init()`, you must listen for `attach` before\ncalling `gamepad.init()`.\n\n### gamepad.shutdown()\n\nTears down all data structures created by the gamepad library and releases any\nmemory that was allocated. It is not necessary to call this function at\napplication termination, but it's provided in case you want to free memory\nassociated with gamepads at some earlier time.\n\n### numDevices()\n\nReturns the number of currently attached gamepad devices.\n\n### deviceAtIndex(deviceIndex)\n\nReturns the specified gamepad's current state, or `undefined` if deviceIndex is\nout of bounds.\n\n### detectDevices()\n\nPolls for any devices that have been attached since the last call to\n`gamepad.detectDevices()` or `gamepad.init()`. If any new devices are found, the\n`attach` event will be emitted once per newly detected device.\n\nNote that depending on implementation, you may receive button and axis event\ncallbacks for devices that have not yet been detected with\n`gamepad.detectDevices()`. You can safely ignore these events, but be aware that\nyour callbacks might receive a device ID that hasn't been emitted as an `attach`\nevent yet.\n\n### processEvents()\n\nReads pending input from all attached devices and emits the appropriate events,\nif any have been registered.\n\n## Developing\n\n### Publishing a release\n\nThis repository uses `prebuild` to create pre-built binaries (hosted on GitHub) for Windows, macOS, and Linux.\n\nTo trigger a new release, simply push a new tag. The TravisCI and Appveyor build scripts will see that tag, and publish binaries for it.\n\nOnce the builds have completed, the release can be published to npm via the normal command: `npm publish`. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreationix%2Fnode-gamepad","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcreationix%2Fnode-gamepad","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreationix%2Fnode-gamepad/lists"}