如何使用WndProc捕捉ESC KeyPress?
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){ //... }
您需要捕获WM_CHAR
消息并检查WParam
。
(msg == WM_KEYDOWN)&&(wParam == VK_ESCAPE)...操作是c#...抱歉,这是Win32 API方式
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.