Obtain the key messages of other programs and use the hook function

Source: Internet
Author: User


Using system. runtime. interopservices;

/// <Summary>
/// Register hotkeys
/// </Summary>
/// <Param name = "hwnd"> handle to window </param>
/// <Param name = "ID"> Hot Key Identifier </param>
/// <Param name = "fsmodifiers"> key-modifier options </param>
/// <Param name = "VK"> virtual-key code </param>
/// <Returns> </returns>
[Dllimport ("user32.dll", setlasterror = true)]
Public static extern bool registerhotkey (intptr hwnd, int ID, keymodifiers fsmodifiers, keys VK );

/// <Summary>
/// Unregister hotkeys
/// </Summary>
/// <Param name = "hwnd"> handle to window </param>
/// <Param name = "ID"> Hot Key Identifier </param>
/// <Returns> </returns>
[Dllimport ("user32.dll", setlasterror = true)]
Public static extern bool unregisterhotkey (intptr hwnd, int ID );

/// <Summary>
/// Keys for Combination
/// </Summary>
[Flags ()]
Public Enum keymodifiers {
None = 0,
Alt = 1,
Control = 2,
Shift = 4,
Windows = 8
}

/// <Summary>
/// Override the wndproc, when lose focus it can also activate the registered hot keys
/// </Summary>
/// <Param name = "M"> </param>
Protected override void wndproc (ref message m)
{
Const int wm_hotkey = 0x0312; // press the hotkey
Switch (M. msg)
{
Case wm_hotkey:
Callscr ();
Break;
}
Base. wndproc (ref m );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.