Global hotkeys in windowless .NET app

前端 未结 3 2096
隐瞒了意图╮
隐瞒了意图╮ 2021-01-22 11:06

I\'ve read similar questions around this issue, including Best way to tackle global hotkey processing in C#? and Set global hotkeys using C#. I\'ve also investigated a NuGet pac

3条回答
  •  無奈伤痛
    2021-01-22 11:47

    Using RegisterHotkey() is boilerplate to detect a hotkey press. I won't repeat it here, you can easily google sample code from the function name.

    It does however require a window, no workaround for that. It just doesn't have to be a visible window. By far the simplest way to create an invisible window is to use a Form class, like you do in any Winforms application, and set ShowInTaskbar = False, WindowState = Minimized, FormBorderStyle = FixedToolWindow. Call RegisterHotkey() in your OnLoad() method override, you'll need the Handle property. Easy peasy.

提交回复
热议问题