{"id":28290182,"url":"https://github.com/jozzzzep/keybinder","last_synced_at":"2026-04-27T08:32:02.149Z","repository":{"id":47527745,"uuid":"315073346","full_name":"jozzzzep/KeyBinder","owner":"jozzzzep","description":"An easy to use tool for a key-binding system in Unity","archived":false,"fork":false,"pushed_at":"2022-12-28T13:04:30.000Z","size":1455,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-13T12:48:51.244Z","etag":null,"topics":["bind","binding","bindings","class","easy","easy-to-use","key","keybind","keybinder","keybinding","keybindings","keybinds","keycode","keycodes","simple","system","unity","unity3d"],"latest_commit_sha":null,"homepage":"","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/jozzzzep.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-22T15:48:49.000Z","updated_at":"2023-08-18T21:23:42.000Z","dependencies_parsed_at":"2023-01-31T06:31:04.754Z","dependency_job_id":null,"html_url":"https://github.com/jozzzzep/KeyBinder","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/jozzzzep/KeyBinder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jozzzzep%2FKeyBinder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jozzzzep%2FKeyBinder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jozzzzep%2FKeyBinder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jozzzzep%2FKeyBinder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jozzzzep","download_url":"https://codeload.github.com/jozzzzep/KeyBinder/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jozzzzep%2FKeyBinder/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32329463,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T23:26:28.701Z","status":"online","status_checked_at":"2026-04-27T02:00:06.769Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["bind","binding","bindings","class","easy","easy-to-use","key","keybind","keybinder","keybinding","keybindings","keybinds","keycode","keycodes","simple","system","unity","unity3d"],"created_at":"2025-05-22T02:12:31.326Z","updated_at":"2026-04-27T08:32:02.118Z","avatar_url":"https://github.com/jozzzzep.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"![img](https://i.imgur.com/zkpS6qA.png)  \n\n\u003cp align=\"center\"\u003e\n        \u003cimg src=\"https://img.shields.io/codefactor/grade/github/jozzzzep/KeyBinder/main\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/languages/code-size/jozzzzep/KeyBinder\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/license/jozzzzep/KeyBinder\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/v/release/jozzzzep/KeyBinder\"\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/followers/jozzzzep?style=social\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/watchers/jozzzzep/KeyBinder?style=social\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/stars/jozzzzep/KeyBinder?style=social\"\u003e\n\u003c/p\u003e\n\nAn easy to use tool for key-binding in Unity.  \nSupports input filtering (You can choose which keys are valid for binding).  \nThe tool has detaild documentation, and simple examples of usage.  \n\n#### Content \n- **[Documentation](#documentation-content)**  \n- **[Examples \u0026 Guide](#examples-and-guide)**\n- **[Importing](#importing-guide)**\n\n## Documentation Content:\n![img](https://i.imgur.com/swFyjTR.png)\n\n  - [KeyDetector](#keydetector)\n  - [Input Filtering](#input-filtering)\n    - [**InputFilter** class members](#inputfilter-class-members)\n    - [Filtering Methods](#filtering-method)\n    - [Filtering Guide](#input-filter-usage-examples)\n    - [**Advanced Filtering Guide**](#advanced-filtering-guide)\n      - [Filter Presets](#iinputfilterpreset)\n      - [Advanced Filtering Examples](#advanced-filtering-examples)\n\n## KeyDetector\nThe main class of the KeyBinder tool, used for detecting when a user/player presses a key.  \nAll these members are static, so you don't need to create an instance of a KeyDetector.  \n\n- **Properties**\n  - \u003ccode\u003eInputCheckIsActive\u003c/code\u003e  \n  Set to false by default  \n  Determines if the KeyDetector is currently checking for input  \n  To activate see methods: **InputCheckOnce** and **InputCheckSetActive** bellow\n\n  - \u003ccode\u003eInputFilter\u003c/code\u003e  \n  The input filter of the detector  \n  Filtering is disabled by default  \n  To activate read about [Input Filtering](#input-filtering)  \n  To disable filtering call - **DisableInputFilter()**\n\n  - \u003ccode\u003eLatestKey\u003c/code\u003e  \n  Returns the latest valid key the KeyDetector received\n\n- **Events**\n  - ``KeyReceived (KeyCode) ``  \n  Raised when a valid key has been received by the key detector\n\n  - ``InvalidKeyReceived (KeyCode)``  \n  Raised when an invalid key has been detected  \n  Will be raised only if there is an active input filtering  \n  When the InputFilter detects an invalid key it will raise this event\n\n\n- **Methods**\n  - \u003ccode\u003eInputCheckOnce (Action\\\u003cKeyCode\\\u003e)\u003c/code\u003e  \n  Waits until a key is detected, calls the action, and turns off input checking  \n  Call this if you want to stop the input checking after a single key press  \n  After the input detection, the Action you passed is removed from the event listeners  \n  If the detector receives an invalid key, it will continue checking for input\n\n  - \u003ccode\u003eInputCheckSetActive (bool)\u003c/code\u003e  \n  Set manually whether you want to check for input, keeps checking **until deactivation**  \n  Call this if you want to **keep checking** for the key the user/player is pressing  \n  The KeyDetector will keep checking for input and will activate events until you deactivates the input checking manually\n\n  - \u003ccode\u003eRemoveAllListeners ()\u003c/code\u003e  \n  Removes all the listeners from the KeyReceived event\n\n  - \u003ccode\u003eSetInputFilter (InputFilter)\u003c/code\u003e  \n   Used to set custom filtering for the KeyDetector  \n   Just call and input an InputFilter object  \n   It is reccomended to use the method bellow instead\n\n  - \u003ccode\u003eSetInputFilter (IInputFilterPreset)\u003c/code\u003e  \n  Used to set custom filtering for the KeyDetector  \n  Will create an input filter based on the preset you passed\n  \n  - \u003ccode\u003eDisableInputFilter ()\u003c/code\u003e  \n  Disables input filtering  \n  Sets the InputFilter of the detector to an empty filter\n\n# Input Filtering\nFor input filtering there is a class named **InputFilter**, a class the KeyDetector uses to filter input.  \nThat means that you can prevent the KeyDetector from detecting certain keys  \nThe KeyDetector has an empty inactive InputFilter by default (not filtering).  \n\nIf you want to use input filtering on the KeyDetector,  \nyou **need** to set it up **before** you check for input.  \nThe best practice it to do it inside the **Start()** or **Awake()** methods.  \nSee **[Examples](#input-filter-usage-examples)** \n\n\n### InputFilter class members:\n  - ``Keys``  \n   An array of KeyCode, containing the keys the filter is using for filtering  \n   If null/empty, the filter is inactive - see bellow\n\n  - ``FilteringActive``  \n  Returns a bool that determines whether the filter is filtering  \n  When an input filter is created this value is initialized to **true** \n  or **false**  \n  Only if the list of keys given to the filter is not empty and contains at least one key, the filter is activated (value set to **true**)\n  \n  - ``FilteringMethod``  \n  Returns an enum of type **InputFilter.Method**  \n  Can be either **Whitelist** or **Blacklist** - see bellow\n\n  ### Filtering Method\n  The key will be validated by the filter only if:  \n    - Whitelist   - it is inside the list of keys of the filter  \n    - Blacklist   - it is not inside the list of keys of the filter\n     \n    \n\n### Input Filter Usage Guide\nLets say you want the KeyDetector to only detect the keys:  \n**A, X, Q, Right Mouse Click, Left Mouse Click**  \nYou can do it like this:\n```csharp\nStart()\n{\n    // Create an array of KeyCodes or use an existing one\n    // It should contain all the keys you want to filter\n    KeyCode[] keysToFilter = \n    {\n        KeyCode.A,\n        KeyCode.X,\n        KeyCode.Q,\n        KeyCode.Mouse0, // left mouse button\n        KeyCode.Mouse1  // right mouse button\n    };\n\n    // 1 - Create and allocate a new InputFilter\n    // 2 - Pass the array of keys and choose filtering method\n    InputFilter inputFilter = new InputFilter(keysToFilter, InputFilter.Method.Whitelist);\n\n    // Call the method \"SetInputFilter\" and pass the filter \n    KeyDetector.SetInputFilter(inputFilter);\n}\n```\n---\nAlso, if you want instead that the KeyDetector will only detect the keys that are **not** inside the list  \nJust set the method to Blacklist like that:\n\n\n```csharp\nInputFilter inputFilter = new InputFilter(keysToFilter, InputFilter.Method.Blacklist);\n```\n---\nAlso, if you want to use the **Whitelist** filtering method  \nYou can call the constructor without specifing the method. Like so:\n\n```csharp\nInputFilter inputFilter = new InputFilter(keysToFilter);\n```\n\n## Advanced Filtering Guide\nAltough it is more advanced, and may look a bit complex -  \nIt is recommended to use input filter presets instead of creating a new InputFilter with a constructor.  \nThis way is a lot more professional and organized.  \nTo do this you need to create an input filter preset **class**.  \nAnd for this the KeyBinder tool has the interface **IInputFilterPreset**\n\n### IInputFilterPreset\nAnd interface used for creating a preset for an InputFilter  \nRecommended name for a preset class is to start it with ``InputFilterPreset``  \nJust create a class and implemet these members:\n \n  - ``KeyCode[] KeysList { get; }``  \n  An array of keys you want to be filtered\n\n  - ``InputFilter.Method FilteringMethod { get; }``  \n  The filtering method see [here](#filtering-method)\n\n---\n### Advanced Filtering Examples\nLets say you want the KeyDetector to only detect the keys:  \nA, X, Q, Right Mouse Click, Left Mouse Click  \nFirst open a new file and create a new class for the InputFilterPreset:  \n```csharp\nusing UnityEngine;\nusing KeyBinder;\n\n// use the interface IInputFilterPreset\npublic class InputFilterPresetExample : IInputFilterPreset\n{\n    // implement the array of keys like this\n    public KeyCode[] KeysList =\u003e new KeyCode[] \n    {\n        KeyCode.A,\n        KeyCode.X,\n        KeyCode.Q,\n        KeyCode.Mouse0, // left mouse button\n        KeyCode.Mouse1, // right mouse button\n    };\n\n    // choose a filtering method\n    public InputFilter.Method FilteringMethod =\u003e InputFilter.Method.Whitelist;\n}\n```\n\n---\nNow, you just need to call the method **SetInputFilter** in **Start()** or **Awake()** like so:\n```csharp\nStart()\n{\n    // Just create a new instance of the preset class we created before\n    KeyDetector.SetInputFilter(new InputFilterPresetExample());\n}\n```\nDone! Now your KeyDetector uses a filter based on the preset class you created.\n\n### Naming a filter preset\nName the class of the preset by starting with **\"InputFilterPreset\"** and then add anything you want  \nIn this case I added **\"Example\"** and named it **\"InputFilterPresetExample\"**\n  \n\n\n# Examples and Guide\n\nThis tool can be used in many ways.  \nHere are some examples:  \n\n- [**Example #1**](#example-1)\n- [**Example #2**](#example-2)\n- [**Unity Examples**](#unity-examples)\n\n## Example #1\nYou can can check which key the player/user pressed recently.  \nTo to that, turn on input checking in the KeyDetector class.  \nAfter checking, you can get the key that was pressed from the property \"LatestKey\"  \nYou can write the key name to the console like so:  \n```csharp\nusing KeyBinder; // important to use the KeyBinder namespace\nusing UnityEngine;\n\npublic class ExampleDebugScript : MonoBehaviour\n{\n    void Start()\n    {\n        KeyDetector.InputCheckSetActive(true); // turns on input checking\n    }\n\n    void Update()\n    {\n        Debug.Log(KeyDetector.LatestKey); // logs to the console the latest pressed key\n    }\n}\n```\n\n### Improve Efficiency\nYou can make it that it logs the key every time the detector detects a new key  \nInstead of updating every frame the latest key.  \nDo this inside the class ( no need for **Update()** ):\n\n```csharp\nvoid Start()\n{\n    KeyDetector.InputCheckSetActive(true); // turns on input checking\n\n    // adds the method \"DebugKey\" to the event \"KeyReceived\"\n    // it will call the method \"DebugKey\" every time a new key is detected\n    KeyDetector.KeyReceived += DebugKey; \n}\n\nvoid DebugKey(KeyCode keyCode)\n{\n    Debug.Log(KeyDetector.LatestKey); // logs to the console the latest pressed key\n}\n```\n\n## Example #2\nLet's say you have a game that uses a KeyCode variable for the shoot key.  \nWhenever the player presses the shoot key, the game will shoot a bullet.  \nAnd by default the shoot key is the key **X**:\n\n```csharp\nKeyCode shootKey = KeyCode.X;\n\nvoid Update()\n{\n    if (Input.GetKeyDown(shootKey))\n    {\n        Shoot()\n    }\n}\n\nvoid Shoot()\n{\n    // shooting behavior\n}\n\n```\n\nNow you want to let the player choose the key he wants to use for shooting.  \nTo do that add a method that sets the \"shootKey\" variable to a new KeyCode.\n\n```csharp\nvoid SetShootKey(KeyCode key)\n{\n    shootKey = key;\n}\n```\nAdd the namespace \"KeyBinder\" at the top of the script.\n\n```csharp\nusing KeyBinder;\n```\n\nYou already have a method for setting the keybind of the shoot key.  \nNowreate a new method named BindShootKey().  \nInside, call the function \"InputCheckOnce\" and pass the method SetShootKey as a parameter.\n\n```csharp\nvoid BindShootKey()\n{\n    KeyDetector.InputCheckOnce(SetShootKey);\n}\n```\nNow call this method every time you want the player to change the key for shooting.  \nIt will wait until a key is pressed, and will call the function \"SetShootKey\" with the new key.  \nIt will also automatically stops checking for input after the key is pressed.  \nSo you don't need to worry about stoping the input checking manually.  \n\n*You can also make the \"BindShootKey\" method - public, to assign it to a button in the UI.*\n\nThe KeyDetector also supports InputFiltering read about it [here](#input-filtering)\n\n\n## Unity examples\nClone the repository  \nIn the folder \"samples\" you can find a unity project named \"keybinder-unity-examples\"  \nInside this unity project you have many examples that show you what you can do with the tool  \n\n---\nIn the unity file browser, you will see these folders:\n\n![img](https://i.imgur.com/h12lUij.png)\n\nThen enter the \"Examples\" folder and you will see all the available examples\n\n![img](https://i.imgur.com/hgMAz43.png)\n \nIn every example folder you will have a different scene that shows the example\n\n![img](https://i.imgur.com/vgQz8Mt.png)\n\nNow just open the scene and press play to see what happens.  \nInside the project you have 6 examples.  \nYou can learn from every example how the tool works.  \n\n---\n\n### Importing Guide\n[**Click here to download**](https://github.com/jozzzzep/KeyBinder/raw/main/packages/KeyBinder.unitypackage), or go to the packages folder of the repository and download the package file.  \nThen import the package directly to your project like any other Unity package.  \nThis is he fastest and easiest way.  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjozzzzep%2Fkeybinder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjozzzzep%2Fkeybinder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjozzzzep%2Fkeybinder/lists"}