How can I simulate Ctrl+Alt+H using keybd_event() ? The following code , doesn’t work :
keybd_event((byte)Convert.ToInt32(Keys.Control), (byte)MapVirtualKey(Convert.ToInt32(Keys.Control), 0), 0, 0);
keybd_event((byte)Convert.ToInt32(Keys.Alt), (byte)MapVirtualKey(Convert.ToInt32(Keys.Alt), 0), 0, 0);
keybd_event((byte)Keys.H, (byte)MapVirtualKey(Convert.ToInt32(Keys.H), 0), 0, 0);
keybd_event((byte)Keys.H, (byte)MapVirtualKey(Convert.ToInt32(Keys.H), 0), KEYEVENTF_KEYUP, 0);
keybd_event((byte)Convert.ToInt32(Keys.Alt), (byte)MapVirtualKey(Convert.ToInt32(Keys.Alt), 0), KEYEVENTF_KEYUP, 0);
keybd_event((byte)Convert.ToInt32(Keys.Control), (byte)MapVirtualKey(Convert.ToInt32(Keys.Control), 0), KEYEVENTF_KEYUP, 0);
You can use SendKeys to do this:
http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx
EDIT
(See comments below…)
You want to launch a windows shortcut on your desktop that you have setup with a specific set of hot keys. In this case CTRL+ALT+H. You want to write an app that will execute that shortcut key combination.
In order for this to work your desktop will have to have “focus”. This means that no other windows should be up. So, start your application, minimize all other windows, and then press the button on your application. Here is the code you should have behind your button:
This will minimize the current window thus giving focus to your desktop. It will then send the CTRL and ALT and H keys to the desktop which will launch your shortcut.