2012-08-13 87 views
3

我已经定义了一个HotKeyCtrl +空格来激活我的Windows窗体。当表格处理这个HotKey时,系统看不到这个事件。随后有什么方法可以解开这些击键? (也就是说,注销HotKey不处理(取消注册)系统范围的“热键”

这是我曾尝试:

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); 
} 
+0

这是没有道理的。如果你尝试做这个工作,那么你最终会再次触发WM_HOTKEY消息。这将不会顺利。 – 2012-08-13 13:48:59

回答

0

创建一个全局布尔变量。将其值设置为false。

在Windows KeyDown事件中,检查该bool变量是否为true,从方法返回。

当您想要解除这些键击时,将其值设置为true,并且当您想要处理这些击键时,将其值设置为false。

public bool flag = false; 

public void Window_KeyDown(object sender, KeyEventArgs e) 
{ 
    if (flag) 
     return; 

    //.. Code Here something 
} 

现在,你只需要设置这个标志值来处理或未经处理过的键盘。

+0

我发布了我的代码。我想我不明白你的解决方案。我是新手! – Sakura 2012-08-13 13:23:42