Windows Develop Bookmark and Share   
 index > ClickOnce and Setup & Deployment Projects > How to set shortcut key for a windows application during setup and deployment project?
 

How to set shortcut key for a windows application during setup and deployment project?

Hi

We are using Visual Studio 2005 and we having a windows application in c#. now we want to set a shortcut key for a application. how we set a shortcut key for a application. Can you help me anybody?


Thanks,
Sankar R.
Langars  Friday, November 16, 2007 11:32 AM

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

Custom Search

More Threads

• Performance Counter Instances (InstanceName) how to deploy?
• Error 2835: The control ErrorIcon was not found on dialog ErrorDialog
• Why my program is not multi-language when i do a setup project ?
• How to change publisher?
• CAB on Virtual Machines
• Problem uninstalling windows service with Setup Project
• ClickOnce install succeeds but get old ver
• No touch deployment question
• Problems Deploying Publish/Windows Install of VB 2005 App
• Verisign Certificate