locked
form-level keyboard hook RRS feed

  • Question

  •  

    Hi

     

    How do I call a specific function whenever a certain key is pressed in a given form (say F2) - I expect a keyboard hook comes into play here ?

     

    thanks

     Bruce

    Wednesday, November 21, 2007 1:17 AM

Answers

All replies

  • You can set the form's KeyPreview property to True.  Then, the KeyDown/KeyUp/KeyPress events will occur on the form before any control which might happen to have focus.

     

    See http://msdn2.microsoft.com/en-us/library/system.windows.forms.form.keypreview.aspx for documentation and examples.

     

    (I am assuming that you can modify the form's code.  Otherwise, you are correct in that you may need a use a "hook" technique.)

    Wednesday, November 21, 2007 2:06 AM
  • That's great - it's just what I was after !

     

    thanks for the reply.

    Bruce

    Wednesday, November 21, 2007 2:14 AM