How To: Application wide KeyUp

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a multi form (not MDI) application and I would like my program to
intercept keyboard input regardless witch form is active. I tried the usual
KeyUp event hander on the MainForm on the App first, but it didn’t do
anything because one of the controls of the form always seems to be selected.
Next, I tried to override the WndProc with the following code:

const int WM_KEYUP = 0x101;
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_KEYUP:
{
Keys keys = (Keys)m.WParam.ToInt32();
if (keys == Keys.P)
DoSomething();
break;
}
}
base.WndProc(ref m);
}

But that doesn’t do anything. I can intercept the MouseMove event for
example but the KeyUp doesn’t seem to reach this function at all (I tried to
put a break point to the first statement after the case but it never got
there) . Does anyone know what to do?
 
and that would only work for the class containing the WndProc anyway. i would
like it to be App wide.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top