如何用WndProc捕捉ESC按键?

时间:2010-03-21 13:33:37

标签: c# .net winforms

如何使用WndProc捕获ESC KeyPress?

4 个答案:

答案 0 :(得分:4)

另一种选择(表格):

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

答案 1 :(得分:3)

你为什么这样做?为什么不将表单的PreviewKey属性设置为true并为KeyUp设置一个全局事件处理程序并检查它...

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

答案 2 :(得分:0)

您需要抓住WM_CHAR消息并检查WParam

答案 3 :(得分:0)

(msg == WM_KEYDOWN)&& (wParam == VK_ESCAPE)...操作它是c#...抱歉,这是win32 api方式

相关问题