Registration System hotkey

Source: Internet
Author: User

Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;
Using system. runtime. interopservices;

Namespace datasource
{
Public partial class hotkey: Form
{
[Dllimport ("USER32")]
Public static extern bool registerhotkey (intptr hwnd, int ID, uint control, keys VK );
// Register the hotkey API
[Dllimport ("USER32")]
Public static extern bool unregisterhotkey (intptr hwnd, int ID );

Public hotkey ()
{
Initializecomponent ();
}

Private void hotkey_load (Object sender, eventargs E)
{
// Register the hotkey (Form handle, hotkey ID, secondary key, and real key)
Registerhotkey (this. Handle, 888, 3, keys. B );

}

Private void hotkey_formclosing (Object sender, formclosingeventargs E)
{
// Delete the hotkey (handle, hotkey ID)
Unregisterhotkey (this. Handle, 888 );

}

Protected override void wndproc (ref message m)
{
Switch (M. msg)
{
Case 0x0312: // This is the registered hotkey message defined by the window message.
If (M. wparam. tostring (). Equals ("888") // if it is the hotkey we registered
If (this. Visible = false)
{
This. Visible = true;
}
Else
{
This. Visible = false;
}
Break;
}
Base. wndproc (ref m );
}

// Auxiliary key description:
// None = 0,
// Alt = 1,
// Crtl = 2,
// Shift = 4,
// Windows = 8

}
}

Related Article

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.