views:

355

answers:

3

Hi,

I wish to build my own application which can send keyboard commands(messages) to the Windows OS.

For example when I press ctrl+shit+n, I wish to launch the notepad.exe . How can I do that? Do you have some advices for me about the concept used.

I've read that is possible when are used keyboard hooks? That's the only way? Do you know a free and open-source application which does this as simple is possible?

+1  A: 

Your particular example can be done without any programming at all, by right clicking on Notepad, selecting Properties, and setting the "hot key" (various Windows versions might call it by a different name) to Ctrl+Shift+N.

If you still would like to write a program to do this, have a look at the RegisterHotKey Win32 API function.

Greg Hewgill
ty, but i really wish to write the program :)
dole doug
+2  A: 

AutoHotkey is a free, open-source utility for Windows.
You can automate many tasks with the above utility, check it out.

Nick D
+1  A: 

Things to bear in mind:

A system-wide keyboard hook requires the writing of a DLL. There's example keyboard hook code on my website here.

Hooks cannot be installed from a low to a high integrity level application in Vista and Windows 7. So there's no guarantee your hook will work, depending upon what the foreground application is when the key gets hit.

As Greg pointed out, a lot of the time, RegisterHotKey is a much simpler solution for this problem.

Bob Moore