ProcessCmdKey - wait for KeyUp?

前端 未结 2 2074
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-18 07:59

I\'m having the following issue in a WinForms app. I\'m trying to implement Hotkeys and I need to process Key messages whenever the control is active, no matter if the focus

2条回答
  •  清酒与你
    2020-12-18 08:44

    const int WM_KEYDOWN = 0x100;
    const int WM_KEYUP = 0x101;
    
    protected override bool ProcessKeyPreview(ref Message m)
    {
        if (m.Msg == WM_KEYDOWN && (Keys)m.WParam == Keys.NumPad6)
        {
            //Do something
        }
        else if (m.Msg == WM_KEYUP && (Keys)m.WParam == Keys.NumPad6)
        {
            //Do something
        }
    
        return base.ProcessKeyPreview(ref m);
    }
    

提交回复
热议问题