{"id":17197195,"url":"https://github.com/thomaslevesque/nhotkey","last_synced_at":"2026-01-23T14:53:18.999Z","repository":{"id":13295170,"uuid":"15981201","full_name":"thomaslevesque/NHotkey","owner":"thomaslevesque","description":"A managed library to handle global hotkeys in Windows Forms and WPF applications","archived":false,"fork":false,"pushed_at":"2024-07-04T01:26:49.000Z","size":70,"stargazers_count":326,"open_issues_count":4,"forks_count":56,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-05-08T18:39:43.621Z","etag":null,"topics":["csharp","dotnet","global-hotkeys","windows","wpf"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thomaslevesque.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2014-01-16T21:15:47.000Z","updated_at":"2025-05-07T15:35:47.000Z","dependencies_parsed_at":"2024-10-15T01:55:49.026Z","dependency_job_id":"ed3b4f51-e7f2-4726-ae8d-f69688104f35","html_url":"https://github.com/thomaslevesque/NHotkey","commit_stats":{"total_commits":38,"total_committers":4,"mean_commits":9.5,"dds":0.4736842105263158,"last_synced_commit":"01301963b9fe42c74ea3fa0ff7d702e48eff0377"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomaslevesque%2FNHotkey","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomaslevesque%2FNHotkey/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomaslevesque%2FNHotkey/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomaslevesque%2FNHotkey/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thomaslevesque","download_url":"https://codeload.github.com/thomaslevesque/NHotkey/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254471060,"owners_count":22076585,"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":["csharp","dotnet","global-hotkeys","windows","wpf"],"created_at":"2024-10-15T01:55:46.934Z","updated_at":"2026-01-23T14:53:18.993Z","avatar_url":"https://github.com/thomaslevesque.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"NHotkey\n=======\n\n[![NuGet version](https://img.shields.io/nuget/v/NHotkey.svg?logo=nuget\u0026label=NHotkey)](https://www.nuget.org/packages/NHotkey)\n[![NuGet version](https://img.shields.io/nuget/v/NHotkey.Wpf.svg?logo=nuget\u0026label=NHotkey.Wpf)](https://www.nuget.org/packages/NHotkey.Wpf)\n[![NuGet version](https://img.shields.io/nuget/v/NHotkey.WindowsForms.svg?logo=nuget\u0026label=NHotkey.WindowsForms)](https://www.nuget.org/packages/NHotkey.WindowsForms)\n[![AppVeyor build](https://img.shields.io/appveyor/ci/thomaslevesque/nhotkey.svg?logo=appveyor\u0026logoColor=cccccc)](https://ci.appveyor.com/project/thomaslevesque/nhotkey)\n\nEasily handle shortcut keys even when your WPF or WinForms app doesn't have focus. Declare hotkeys in XAML with the familiar `KeyBinding` syntax.\n\nNuget packages:\n- for WPF: [NHotkey.Wpf](http://www.nuget.org/packages/NHotkey.Wpf/)\n- for Windows Forms: [NHotkey.WindowsForms](http://www.nuget.org/packages/NHotkey.WindowsForms/)\n\n### Windows Forms usage\n\nAdd a reference to `NHotkey.dll` and `NHotkey.WindowsForms.dll`. In the file where you want to\nhandle hotkeys, import the `NHotkey.WindowsForms` namespace:\n\n```csharp\n    using NHotkey.WindowsForms;\n```\n\nDuring initialization, add some hotkeys:\n\n```csharp\n    HotkeyManager.Current.AddOrReplace(\"Increment\", ModKeys.Control | ModKeys.Alt | Keys.Add, OnIncrement);\n    HotkeyManager.Current.AddOrReplace(\"Decrement\", ModKeys.Control | ModKeys.Alt | Keys.Subtract, OnDecrement);\n```\n\n- the first parameter is an application-defined name for the hotkey; it can be anything you like,\nas long as it's unique;\n- the second parameter is the combination of keys for which you want to register a hotkey;\n- the last parameter is a delegate of type `EventHandler\u003cHotkeyEventArgs\u003e` that will be called\nwhen this hotkey is pressed. For instance:\n\n```csharp\n    private void OnIncrement(object sender, HotkeyEventArgs e)\n    {\n        Value++;\n        e.Handled = true;\n    }\n\n    private void OnDecrement(object sender, HotkeyEventArgs e)\n    {\n        Value--;\n        e.Handled = true;\n    }\n```\n\nIf you want to handle several hotkeys with the same handler, you can check the `Name`\nproperty of the `HotkeyEventArgs`:\n\n```csharp\n    private void OnIncrementOrDecrement(object sender, HotkeyEventArgs e)\n    {\n        switch (e.Name)\n        {\n            case \"Increment\":\n                Value++;\n                break;\n            case \"Decrement\":\n                Value--;\n                break;\n        }\n        e.Handled = true;\n    }\n```\n\nNotes regarding the Windows key:\n- The standard `Keys` enum does not include the Windows key as a modifier, so NHotkey defines a `ModKeys` class that\n  exposes all modifier keys, including the Windows key. You can just use `ModKeys` instead of `Keys` for the modifiers.\n- Keep in mind that the operating system reserves some combinations involving the Windows key. Trying to register such\n  combinations as hotkeys will fail.\n\n### WPF usage\n\nThe approach for WPF is very similar to the one for Windows Forms; the exposed API is slightly\ndifferent to account for the differences between WinForms and WPF. The WPF version also\nsupports `KeyBindings`.\n\nAdd a reference to `NHotkey.dll` and `NHotkey.Wpf.dll`. In the file where you want to\nhandle hotkeys, import the `NHotkey.Wpf` namespace:\n\n```csharp\n    using NHotkey.Wpf;\n```\n\nDuring initialization, add some hotkeys:\n\n```csharp\n    HotkeyManager.Current.AddOrReplace(\"Increment\", Key.Add, ModifierKeys.Control | ModifierKeys.Alt, OnIncrement);\n    HotkeyManager.Current.AddOrReplace(\"Decrement\", Key.Subtract, ModifierKeys.Control | ModifierKeys.Alt, OnDecrement);\n```\n\n- the first parameter is an application-defined name for the hotkey; it can be anything you like,\nas long as it's unique;\n- the second and third parameters are the key and modifiers for which you want to register a hotkey;\n- the last parameter is a delegate of type `EventHandler\u003cHotkeyEventArgs\u003e` that will be called\nwhen this hotkey is pressed.\n\nTo support applications that use the MVVM pattern, you can also specify hotkeys in XAML using\n`InputBindings`. Just declare `KeyBindings` as usual, and set the `HotkeyManager.RegisterGlobalHotkey`\nattached property to `true`:\n\n```xml\n    ...\n    \u003cWindow.InputBindings\u003e\n        \u003cKeyBinding Gesture=\"Ctrl+Alt+Add\" Command=\"{Binding IncrementCommand}\"\n                    HotkeyManager.RegisterGlobalHotkey=\"True\" /\u003e\n        \u003cKeyBinding Gesture=\"Ctrl+Alt+Subtract\" Command=\"{Binding DecrementCommand}\"\n                    HotkeyManager.RegisterGlobalHotkey=\"True\" /\u003e\n    \u003c/Window.InputBindings\u003e\n    ...\n```\n\n**Known limitations of this feature**\n\n- the `HotkeyManager` can't detect if you remove a `KeyBinding`; it only relies on the\nattached property being set to true or false. If you want to remove a KeyBinding at runtime,\nmake sure you set `HotkeyManager.RegisterGlobalHotkey` to false, otherwise it will\nstill be registered\n- changing the keys or modifiers of a `KeyBinding` at runtime is currently not supported. If\nyou need to modify a `KeyBinding` at runtime, you need to set `HotkeyManager.RegisterGlobalHotkey`\nto false, change the key, and set `HotkeyManager.RegisterGlobalHotkey` to true again.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomaslevesque%2Fnhotkey","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthomaslevesque%2Fnhotkey","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomaslevesque%2Fnhotkey/lists"}