开发者

How to catch ESC key press with WndProc?

How to catch an ESC KeyPress using WndProc?开发者_开发问答


Another option (for forms):

protected override bool ProcessKeyPreview(ref System.Windows.Forms.Message m)
{
  int VK_ESCAPE = 27;
  if (m.Msg == Win32Constants.WM_KEYDOWN && (int)m.WParam == VK_ESCAPE)
  {
    // ...
  }
  return base.ProcessKeyPreview(ref m);
}


Why are you doing it this way? Why not set the PreviewKey property of the Form to true and set a global event handler for KeyUp and check it...

if (e.KeyCode == Keys.Esc){
   //...
}


You need to catch the WM_CHAR message and check WParam.


(msg==WM_KEYDOWN) && (wParam==VK_ESCAPE) ... ops it was c#... sorry , that is win32 api way

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜