none
Global Application Keypress event RRS feed

  • Question

  • Hello,

    I would like to implement a F5/Refresh but the problem is that keypress/keydown event only applies to the focused control.
    Is there any way how I can implement a Global Application . Keypress event?
    thanks for reading,
    Andy
    Wednesday, March 10, 2010 2:54 PM

Answers

  • Hello Aussie,

    you know the interface IMessageFilter and the method AddMessageFilter? This interface filter all messages sent to the form. You can filter the F5 key on method PreFilterMessage(ref Message m). Maybe this can help you.


    • Marked as answer by Harry Zhu Monday, March 22, 2010 2:23 AM
    Wednesday, March 10, 2010 3:15 PM
  • Hello Andy,

    We could use Window API to hook into Keyboard events. Here are some resources for this topic you could refer to.

    Processing Global Mouse and Keyboard Hooks in C#:
    http://www.codeproject.com/KB/cs/globalhook.aspx.

    Low-Level Keyboard Hook in C#:
    http://blogs.msdn.com/toub/archive/2006/05/03/589423.aspx.

    Hope this helps,
    Bessie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Harry Zhu Monday, March 22, 2010 2:23 AM
    Friday, March 12, 2010 6:45 AM
  • If its just a form them you can set KeyPreview to true on the form. Then it will get KeyPress events for all the controls on the form before they do. If its across the app then you need to do it on the message queue handler which you passed to Application.Run in the Main method

    HTH Ciaran http://wannabedeveloper.spaces.live.com
    • Marked as answer by Harry Zhu Monday, March 22, 2010 2:23 AM
    Wednesday, March 10, 2010 3:30 PM

All replies

  • Hello Aussie,

    you know the interface IMessageFilter and the method AddMessageFilter? This interface filter all messages sent to the form. You can filter the F5 key on method PreFilterMessage(ref Message m). Maybe this can help you.


    • Marked as answer by Harry Zhu Monday, March 22, 2010 2:23 AM
    Wednesday, March 10, 2010 3:15 PM
  • If its just a form them you can set KeyPreview to true on the form. Then it will get KeyPress events for all the controls on the form before they do. If its across the app then you need to do it on the message queue handler which you passed to Application.Run in the Main method

    HTH Ciaran http://wannabedeveloper.spaces.live.com
    • Marked as answer by Harry Zhu Monday, March 22, 2010 2:23 AM
    Wednesday, March 10, 2010 3:30 PM
  • Hello Andy,

    We could use Window API to hook into Keyboard events. Here are some resources for this topic you could refer to.

    Processing Global Mouse and Keyboard Hooks in C#:
    http://www.codeproject.com/KB/cs/globalhook.aspx.

    Low-Level Keyboard Hook in C#:
    http://blogs.msdn.com/toub/archive/2006/05/03/589423.aspx.

    Hope this helps,
    Bessie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Harry Zhu Monday, March 22, 2010 2:23 AM
    Friday, March 12, 2010 6:45 AM