Click here to Skip to main content
16,008,183 members
Home / Discussions / C#
   

C#

 
GeneralRe: Dll and HINSTANCE Pin
Nish Nishant16-Aug-02 8:09
sitebuilderNish Nishant16-Aug-02 8:09 
GeneralRe: Dll and HINSTANCE Pin
leppie16-Aug-02 8:33
leppie16-Aug-02 8:33 
GeneralRe: Dll and HINSTANCE Pin
Nish Nishant16-Aug-02 9:48
sitebuilderNish Nishant16-Aug-02 9:48 
GeneralRe: Dll and HINSTANCE Pin
leppie16-Aug-02 10:49
leppie16-Aug-02 10:49 
GeneralI'm becoming crazy about keys Pin
Anonymous16-Aug-02 5:49
Anonymous16-Aug-02 5:49 
GeneralRe: I'm becoming crazy about keys Pin
leppie16-Aug-02 6:30
leppie16-Aug-02 6:30 
GeneralRe: I'm becoming crazy about keys Pin
nitro66618-Aug-02 6:34
nitro66618-Aug-02 6:34 
GeneralRe: I'm becoming crazy about keys Pin
James T. Johnson16-Aug-02 8:41
James T. Johnson16-Aug-02 8:41 
This works for me

First the definitions:
[DllImport("user32.dll", SetLastError=true)]
public static extern bool RegisterHotKey(
    IntPtr hWnd,         // handle to window
    int id,            // hot key identifier
    KeyModifiers fsModifiers,  // key-modifier options
    Keys vk            // virtual-key code
    );
 
[DllImport("user32.dll", SetLastError=true)]
public static extern bool UnregisterHotKey(
    IntPtr hWnd,  // handle to window
    int id      // hot key identifier
    );
 
[Flags()]
public enum KeyModifiers
{
    Alt = 1,
    Control = 2,
    Shift = 4,
    Windows = 8
}
Now a sample use of the code:

In Form load:
bool success = RegisterHotKey(Handle, 100, 
    KeyModifiers.Control | KeyModifiers.Shift, Keys.J);
System.Diagnostics.Trace.WriteLine(
    "Success = " + success.ToString());
In Form closed or closing:
UnregisterHotKey(Handle, 100);
And finally override the WndProc so the message can be handled.
protected override void WndProc( ref Message m )
{
	const int WM_HOTKEY = 0x0312;
 
	switch(m.Msg)
	{
	case WM_HOTKEY:
		MessageBox.Show("Hotkey pressed");
		break;
	}
 
	base.WndProc(ref m );
}
HTH,

James
"And we are all men; apart from the females." - Colin Davies
GeneralRe: I'm becoming crazy about keys Pin
nitro66618-Aug-02 9:23
nitro66618-Aug-02 9:23 
GeneralRe: I'm becoming crazy about keys Pin
James T. Johnson18-Aug-02 9:24
James T. Johnson18-Aug-02 9:24 
GeneralRe: I'm becoming crazy about keys Pin
leppie19-Aug-02 0:00
leppie19-Aug-02 0:00 
GeneralRe: I'm becoming crazy about keys Pin
James T. Johnson20-Aug-02 5:06
James T. Johnson20-Aug-02 5:06 
GeneralRe: I'm becoming crazy about keys Pin
leppie20-Aug-02 5:25
leppie20-Aug-02 5:25 
GeneralRe: I'm becoming crazy about keys Pin
James T. Johnson20-Aug-02 5:32
James T. Johnson20-Aug-02 5:32 
GeneralRe: I'm becoming crazy about keys Pin
leppie20-Aug-02 5:45
leppie20-Aug-02 5:45 
GeneralRe: I'm becoming crazy about keys Pin
James T. Johnson20-Aug-02 6:02
James T. Johnson20-Aug-02 6:02 
GeneralRe: I'm becoming crazy about keys Pin
leppie20-Aug-02 6:11
leppie20-Aug-02 6:11 
GeneralRe: I'm becoming crazy about keys Pin
James T. Johnson20-Aug-02 6:19
James T. Johnson20-Aug-02 6:19 
QuestionAuto Tab? Pin
Johnny Zee16-Aug-02 5:32
sussJohnny Zee16-Aug-02 5:32 
AnswerRe: Auto Tab? Pin
leppie16-Aug-02 6:42
leppie16-Aug-02 6:42 
GeneralTo console or not to console... Pin
Ryan Cromwell16-Aug-02 3:20
Ryan Cromwell16-Aug-02 3:20 
GeneralRe: To console or not to console... Pin
Ryan Cromwell16-Aug-02 4:03
Ryan Cromwell16-Aug-02 4:03 
GeneralResources Pin
leppie16-Aug-02 0:48
leppie16-Aug-02 0:48 
GeneralRe: Resources Pin
Nnamdi Onyeyiri16-Aug-02 0:55
Nnamdi Onyeyiri16-Aug-02 0:55 
GeneralRe: Resources Pin
James T. Johnson16-Aug-02 1:32
James T. Johnson16-Aug-02 1:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.