Reputation: 450
How to catch an ESC KeyPress using WndProc?
Upvotes: 2
Views: 9719
Reputation: 63
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);
}
Upvotes: 5
Reputation: 6464
(msg==WM_KEYDOWN) && (wParam==VK_ESCAPE) ... ops it was c#... sorry , that is win32 api way
Upvotes: 0
Reputation: 34592
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){ //... }
Upvotes: 3