Hi, Langars,
Based on my understanding, you want to set HotKeys in your Application duringthe installation process,don't you?
However, this cannot be done during the installation process.
Because the RegisterHotKey method will needa handler to receive the HotKey.
http://msdn2.microsoft.com/en-us/library/ms646309.aspx
"If this parameter is NULL, WM_HOTKEY messages are posted to the message queue of the calling thread and must be processed in the message loop. Then you may lose the message."
So you should Register the HotKey when the Form is showing and Unregister it when the Form is closing.
For example.
Code Block
private const int WM_HOTKEY = 0x0312;
DllImport("user32.dll", SetLastError = true)]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, KeyModifiers fsModifiers, Keys vk);
DllImport("user32.dll", SetLastError = true)]
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
private const int id = 100;
private void button1_Click(object sender, EventArgs e)
public enum KeyModifiers
private void Form1_Load(object sender, EventArgs e)
this.Handle, id, KeyModifiers.Alt, Keys.A); //Register Alt+A
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
this.Handle, id);
protected override void WndProc(ref Message m)
if (m.Msg == WM_HOTKEY)
Console.WriteLine("HotKey Clicked");
base.WndProc(ref m);
Hi, Langars,
Based on my understanding, you want to set HotKeys in your Application duringthe installation process,don't you?
However, this cannot be done during the installation process.
Because the RegisterHotKey method will needa handler to receive the HotKey.
http://msdn2.microsoft.com/en-us/library/ms646309.aspx
"If this parameter is NULL, WM_HOTKEY messages are posted to the message queue of the calling thread and must be processed in the message loop. Then you may lose the message."
So you should Register the HotKey when the Form is showing and Unregister it when the Form is closing.
For example.
Code Block
private const int WM_HOTKEY = 0x0312;
DllImport("user32.dll", SetLastError = true)]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, KeyModifiers fsModifiers, Keys vk);
DllImport("user32.dll", SetLastError = true)]
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
private const int id = 100;
private void button1_Click(object sender, EventArgs e)
public enum KeyModifiers
private void Form1_Load(object sender, EventArgs e)
this.Handle, id, KeyModifiers.Alt, Keys.A); //Register Alt+A
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
this.Handle, id);
protected override void WndProc(ref Message m)
if (m.Msg == WM_HOTKEY)
Console.WriteLine("HotKey Clicked");
base.WndProc(ref m);
You can use google to search for other answers
|