[英]Replace global hotkey
I have a application that lives in the tray and I would like to define serveral hotkeys which will trigger events in my program. 我有一个应用程序驻留在任务栏中,我想定义一些服务器热键,这些热键将触发程序中的事件。
I found inspiration from the excellent answer by @AaronLS in this question: Set global hotkeys using C# 我在以下问题中从@AaronLS的出色答案中找到了灵感: 使用C#设置全局热键
If I register a hot key that are already defined by another application RegisterHotKey
will return false and not register it. 如果我注册了另一个应用程序已经定义的热键, RegisterHotKey
将返回false而不进行注册。 So how can I override or replace a hot key? 那么如何覆盖或替换热键?
So how can I override or replace a hot key? 那么如何覆盖或替换热键?
Ostensibly, you can't. 表面上看,你做不到。 That's by-design. 那是设计使然。 Imagine if programs could hijack other program's hotkeys at-will - that wouldn't be pleasant. 试想一下,如果程序可以随意劫持其他程序的热键-那将不是一件令人愉快的事情。
The Win32 UnregisterHotKey
function requires the caller to be the same thread that registered using RegisterHotKey
, which makes it impossible for another program to unregister another program's hotkeys: Win32 UnregisterHotKey
函数要求调用者与使用RegisterHotKey
线程相同,这使另一个程序无法取消注册另一个程序的热键:
UnregisterHotKey
function:UnregisterHotKey
函数:Frees a hot key previously registered by the calling thread . 释放先前由调用线程注册的热键。
What you can do is use Win32 to inject code into a remote process (assuming your own process has permsision to do this) then schedule code in that process's UI thread that then calls UnregisterHotKey
- but that's another question. 您可以使用Win32将代码注入到远程进程中(假设您自己的进程具有执行此操作的权限),然后在该进程的UI线程中安排代码,然后调用UnregisterHotKey
但这是另一个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.