{"id":21047453,"url":"https://github.com/niklashigi/contro","last_synced_at":"2025-05-15T19:31:49.634Z","repository":{"id":57206607,"uuid":"115257895","full_name":"niklashigi/contro","owner":"niklashigi","description":":video_game: Game controls done right.","archived":false,"fork":false,"pushed_at":"2020-04-18T15:38:19.000Z","size":502,"stargazers_count":52,"open_issues_count":6,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-11T21:48:13.471Z","etag":null,"topics":["controls","game-development","gamepad","javascript-library","keyboard","mouse","zero-dependency"],"latest_commit_sha":null,"homepage":"https://npm.im/contro","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/niklashigi.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":"2017-12-24T11:14:58.000Z","updated_at":"2024-11-28T18:45:02.000Z","dependencies_parsed_at":"2022-09-08T17:01:10.776Z","dependency_job_id":null,"html_url":"https://github.com/niklashigi/contro","commit_stats":null,"previous_names":["niklashigi/contro","shroudedcode/contro"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklashigi%2Fcontro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklashigi%2Fcontro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklashigi%2Fcontro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklashigi%2Fcontro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/niklashigi","download_url":"https://codeload.github.com/niklashigi/contro/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254407402,"owners_count":22066235,"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":["controls","game-development","gamepad","javascript-library","keyboard","mouse","zero-dependency"],"created_at":"2024-11-19T14:37:07.695Z","updated_at":"2025-05-15T19:31:49.220Z","avatar_url":"https://github.com/niklashigi.png","language":"TypeScript","readme":"\u003ch1 align=\"center\"\u003e\n  \u003cbr\u003e\n\t\u003cbr\u003e\n  \u003cimg width=\"320\" src=\"/images/header.png\"\u003e\n\t\u003cbr\u003e\n\t\u003cbr\u003e\n\t\u003cbr\u003e\n\u003c/h1\u003e\n\n\u003e Game controls done right.\n\n[![build status][build-badge]][build-link]\n[![coverage][coverage-badge]][coverage-link]\n[![npm version][npm-version-badge]][npm-link]\n[![monthly downloads][npm-downloads-badge]][npm-link]\n\n### What is Contro?\n\nContro is a **library** that offers **simple abstractions** on top of existing **Web input APIs** and allows game developers to easily implement controls for **keyboard**, **mouse** and **gamepad**.\n\n## Installation\n\nThe easiest way to include Contro in your application is using the `unpkg` CDN:\n\n```html\n\u003cscript src=\"https://unpkg.com/contro@2\"\u003e\u003c/script\u003e\n```\n\nIf you're using `npm`, you can also install it using `npm i contro`.\n\n## Usage\n\n1. Import the Contro classes and functions using [Object destructuring][object-destructuring].\n\n```js\nconst { Mouse, Keyboard, Gamepad, or, and } = Contro\n// OR\nimport { Mouse, Keyboard, Gamepad, or, and } from 'contro'\n```\n\n2. Create instances of the components you want to use.\n\n```js\nconst keyboard = new Keyboard()\nconst gamepad = new Gamepad()\n```\n\n3. Prepare the controls using the control methods and the operator functions `and` and `or`.\n\n```js\nconst controls = {\n  jump: or(gamepad.button('A').trigger, keyboard.key('Space').trigger),\n  menu: or(gamepad.button('Back').trigger, keyboard.key('Esc').trigger),\n  inventory: or(gamepad.button('LB').trigger, keyboard.key('E').trigger),\n  map: or(gamepad.button('RB').trigger, keyboard.key('M').trigger),\n  statusOverlay: or(gamepad.button('RB'), keyboard.key('Tab')),\n}\n```\n\n4. In your game loop, display the relevant `.label`'s and '`.query()` the controls.\n\n```js\nfunction gameLoop() {\n  // Update the UI to reflect the player's input device(s)\n  game.jumpButton.text = controls.jump.label\n  game.menuButton.text = controls.menu.label\n  // ...\n\n  // Query the controls and do something\n  if (controls.jump.query()) game.player.jump()\n  if (controls.menu.query()) game.openMenu()\n  game.statusOverlay.visible = controls.statusOverlay.query()\n  // ...\n\n  requestAnimationFrame(gameLoop)\n}\n```\n\nNote that all of the code starting with `game.` is fictional and just serves as an example.\n\n---\n\n#### Not convinced yet? Check out [this demo][demo]!\n\u003e Wanna learn more? Check out [the docs][docs]!\n\n[demo]: https://codepen.io/shroudedcode/pen/qpPqmB\n[docs]: /docs/README.md\n[object-destructuring]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Object_destructuring\n\n[build-link]: https://travis-ci.org/shroudedcode/contro\n[build-badge]: https://img.shields.io/travis/shroudedcode/contro.svg?style=flat-square\n\n[coverage-link]: https://codecov.io/gh/shroudedcode/contro\n[coverage-badge]: https://img.shields.io/codecov/c/github/shroudedcode/contro.svg?style=flat-square\n\n[npm-link]: https://www.npmjs.com/package/contro\n[npm-version-badge]: https://img.shields.io/npm/v/contro.svg?style=flat-square\n[npm-downloads-badge]: https://img.shields.io/npm/dm/contro.svg?style=flat-square\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniklashigi%2Fcontro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fniklashigi%2Fcontro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniklashigi%2Fcontro/lists"}