{"id":23705460,"url":"https://github.com/r-unic/mechanism","last_synced_at":"2025-04-11T16:07:44.057Z","repository":{"id":270015458,"uuid":"908866022","full_name":"R-unic/mechanism","owner":"R-unic","description":"An elegant input wrapper for Roblox","archived":false,"fork":false,"pushed_at":"2025-03-30T01:10:12.000Z","size":65,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T11:12:31.075Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/R-unic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-12-27T06:47:16.000Z","updated_at":"2025-03-30T01:10:15.000Z","dependencies_parsed_at":"2024-12-28T01:45:18.704Z","dependency_job_id":null,"html_url":"https://github.com/R-unic/mechanism","commit_stats":null,"previous_names":["r-unic/mechanism"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R-unic%2Fmechanism","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R-unic%2Fmechanism/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R-unic%2Fmechanism/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R-unic%2Fmechanism/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/R-unic","download_url":"https://codeload.github.com/R-unic/mechanism/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248438501,"owners_count":21103409,"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-12-30T14:36:49.234Z","updated_at":"2025-04-11T16:07:44.031Z","avatar_url":"https://github.com/R-unic.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mechanism\nAn elegant composable input library for Roblox\n\n## Examples\n\n### Creating an InputManager\nAn `InputManager` is a context to bind actions to. It is disposable and unbinds all actions when destroyed.\u003cbr\u003e\nThe constructor takes a `useAllGamepads` parameter, which when false only uses `Gamepad1` and not any other gamepad input type.\n```ts\nimport { InputManager, StandardActionBuilder } from \"@rbxts/mechanism\";\n\nconst input = new InputManager;\nconst action = new StandardActionBuilder().setID(\"testID\");\ninput.bind(action);\ninput.unbind(action);\ninput.unbind(\"testID\");\n```\n\n### StandardAction\n```ts\nimport { InputManager, StandardActionBuilder } from \"@rbxts/mechanism\";\n\nconst input = new InputManager;\nconst crouchAction = new StandardActionBuilder(\"C\", \"LeftCtrl\")\n  .setProcessed(false) // only activates when gameProcessedEvent is false, false by default\n  .setCooldown(0.25); // can only be activated every 0.25 seconds\n  .setInputQueueing(false); // if this were true, it would queue every input made during a cooldown to be activated after the cooldown is over\n\ncrouchAction.activated.Connect(() =\u003e print(\"crouched\"));\ncrouchAction.deactivated.Connect(() =\u003e print(\"stood\"));\n\ninput.bind(crouchAction);\n```\n\n### AxisAction\n```ts\nimport { InputManager, AxisActionBuilder } from \"@rbxts/mechanism\";\n\nconst input = new InputManager;\nconst scrollAction = new AxisActionBuilder(\"MouseWheel\");\n\nscrollAction.updated.Connect(() =\u003e print(\"scroll position:\", scrollAction.position.Z));\n\ninput.bind(scrollAction);\n```\n\n### RepeatAction\nA `RepeatAction` is an input that must be repeated multiple times to activate.\n```ts\nimport { InputManager, RepeatActionBuilder } from \"@rbxts/mechanism\";\n\nconst input = new InputManager;\nconst sprintAction = new RepeatActionBuilder(\"W\")\n  .setRepeats(2) // takes 2 presses to activate\n  .setTiming(0.3); // each press must be within 0.3 seconds of each other, 0 by default (which is infinite time between presses)\n\nsprintAction.activated.Connect(() =\u003e print(\"sprinting\"));\nsprintAction.deactivated.Connect(() =\u003e print(\"walking\"));\n\ninput.bind(sprintAction);\n```\n\n### CompositeAction\nA `CompositeAction` is an action composed of multiple inputs that must all be simultaneously pressed to activate the action. The action is deactivated when one of the inputs is released.\n```ts\nimport { InputManager, CompositeActionBuilder } from \"@rbxts/mechanism\";\n\nconst input = new InputManager;\nconst toggleAction = new CompositeActionBuilder(\"LeftCtrl\", \"LeftAlt\", \"M\")\n  .setTiming(0.5); // each press must be within 0.5 seconds of each other\n\ntoggleAction.activated.Connect(() =\u003e print(\"toggled\"));\n\ninput.bind(toggleAction);\n```\n\n### SequentialAction\nA `SequentialAction` is an action composed of multiple inputs that must all be pressed in order to activate the action. The action is deactivated when one of the last input in the sequence is released.\n```ts\nimport { InputManager, SequentialActionBuilder } from \"@rbxts/mechanism\";\n\nconst input = new InputManager;\nconst menAction = new SequentialActionBuilder(\"M\", \"E\", \"N\")\n  .setTiming(0.5); // each press must be within 0.5 seconds of each other\n\nmenAction.activated.Connect(() =\u003e print(\"typed 'men' quickly\"));\n\ninput.bind(menAction);\n```\n\n### UniqueAction\nA `UniqueAction` is an action composed of multiple child actions and is only active when exactly one of the child actions is active.\n```ts\nimport { InputManager, UniqueActionBuilder } from \"@rbxts/mechanism\";\n\nconst input = new InputManager;\nconst cOrVAction = new UniqueActionBuilder(\n  new StandardActionBuilder(\"C\"),\n  new StandardActionBuilder(\"V\")\n);\n\ncOrVAction.activated.Connect(() =\u003e print(\"pressed C or V exclusively\"));\n\ninput.bind(cOrVAction);\n```\n\n### DynamicAction\nA `DynamicAction` is an action containing one interchangable action.\n```ts\nimport { InputManager, DynamicAction } from \"@rbxts/mechanism\";\n\nconst input = new InputManager;\nconst crouchAction = new DynamicAction(new StandardActionBuilder(\"C\")); // default bind\n\nkeybinds.changed.Connect(keybinds =\u003e \n  crouchAction.updateAction(new StandardActionBuilder(keybinds.crouch)) // update bind based on data\n);\n\ncrouchAction.activated.Connect(() =\u003e print(\"crouched\"));\ncrouchAction.deactivated.Connect(() =\u003e print(\"stood\"));\n\ninput.bind(crouchAction);\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-unic%2Fmechanism","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fr-unic%2Fmechanism","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-unic%2Fmechanism/lists"}