[英]Unhandling (unregistering) a system-wide 'HotKey'
I have defined a HotKey
Ctrl + Space to activate my Windows Form. 我已经定义了一个
HotKey
Ctrl + Space来激活我的Windows窗体。 When the form handles this HotKey
, this event is not seen by the system. 当表单处理此
HotKey
,系统不会看到此事件。 Is there subsequently any way to unhandle these keystrokes? 有没有办法解开这些击键? (That is, unregister the
HotKey
.) (即取消注册
HotKey
。)
Here is what I have tried: 这是我尝试过的:
private int tuyen_HotKey_Active = 1208132019;
private void Reg_HotKey(bool mode)
{
if (mode)
{
RegisterHotKey(this.Handle, tuyen_HotKey_Active, 2, 32); // Ctrl + Space
}
else
{
UnregisterHotKey(this.Handle, tuyen_HotKey_Active);
}
}
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0312) if(m.WParam.ToInt32() == tuyen_HotKey_Active)
{
// Do something here. I want Ctrl + Space keystroke to be
// unhandled here so that it can be seen by the system.
}
base.WndProc(ref m);
}
Create a global bool variable. 创建一个全局bool变量。 Set its value to false.
将其值设置为false。
In Windows KeyDown event check if that bool variable is true return from method. 在Windows KeyDown事件中检查bool变量是否为true返回方法。
When you want to unhandle these keystrokes set its value to true and when you want to handle these keystrokes set its value to false. 如果要取消处理这些击键,请将其值设置为true,当您想要处理这些击键时,请将其值设置为false。
public bool flag = false;
public void Window_KeyDown(object sender, KeyEventArgs e)
{
if (flag)
return;
//.. Code Here something
}
Now you just have to set this flag value to handle or unhandle your keystrokes. 现在,您只需设置此标志值即可处理或取消处理您的击键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.