none
怎样注册鼠标热键? RRS feed

  • 问题

  • 用API函数RegisterHotKey()可以注册键盘热键,能用它注册鼠标的热键吗?我想把鼠标的mousedown、Click、move等消息拦截到。如果可以的话,请给段示例的代码。谢谢!
    2011年5月23日 13:26

答案

  • hook应该可以。

    参见:ms-help://MS.MSDNQTR.v90.chs/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindowshookex.htm

    WH_KEYBOARD
    Installs a hook procedure that monitors keystroke messages. For more information, see the KeyboardProc hook procedure.
    WH_KEYBOARD_LL
    Windows NT/2000/XP: Installs a hook procedure that monitors low-level keyboard input events. For more information, see the LowLevelKeyboardProc hook procedure.
    WH_MOUSE
    Installs a hook procedure that monitors mouse messages. For more information, see the MouseProc hook procedure.
    WH_MOUSE_LL
    Windows NT/2000/XP: Installs a hook procedure that monitors low-level mouse input events. For more information, see the LowLevelMouseProc hook procedure.


    因为太笨,所以努力!
    2011年5月24日 3:55
  • Hi XPE,

    据我所知不能用RegisterHotKey来注册鼠标热键。

    我们可以选择用全局鼠标钩子来注册鼠标热键。

    大概的步骤是:

    1.使用SetWindowsHookEx安装钩子。在应用程序的InitInstance()中调用

    2.编写全局鼠标钩子回调函数LowLevelMouseProc

    3.在应用程序的ExitInstance()中卸载全局鼠标钩子

     

    Lucy


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年5月25日 8:57
    版主

全部回复

  • hook应该可以。

    参见:ms-help://MS.MSDNQTR.v90.chs/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindowshookex.htm

    WH_KEYBOARD
    Installs a hook procedure that monitors keystroke messages. For more information, see the KeyboardProc hook procedure.
    WH_KEYBOARD_LL
    Windows NT/2000/XP: Installs a hook procedure that monitors low-level keyboard input events. For more information, see the LowLevelKeyboardProc hook procedure.
    WH_MOUSE
    Installs a hook procedure that monitors mouse messages. For more information, see the MouseProc hook procedure.
    WH_MOUSE_LL
    Windows NT/2000/XP: Installs a hook procedure that monitors low-level mouse input events. For more information, see the LowLevelMouseProc hook procedure.


    因为太笨,所以努力!
    2011年5月24日 3:55
  • Hi XPE,

    据我所知不能用RegisterHotKey来注册鼠标热键。

    我们可以选择用全局鼠标钩子来注册鼠标热键。

    大概的步骤是:

    1.使用SetWindowsHookEx安装钩子。在应用程序的InitInstance()中调用

    2.编写全局鼠标钩子回调函数LowLevelMouseProc

    3.在应用程序的ExitInstance()中卸载全局鼠标钩子

     

    Lucy


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年5月25日 8:57
    版主
  • 你好,请参见此贴:http://blog.csdn.net/wangwenzhuang/archive/2010/09/29/5913695.aspx 可以屏蔽键盘和鼠标所有响应。在帖子最下方有源码下载。 希望对你有帮助。
    2011年5月26日 6:16