3

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

For example when I press the combination ctrl+shift+n, I wish to launch the notepad.exe . How can I do that? Do you have some advice 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?

ajaysinghdav10d
  • 1,771
  • 3
  • 23
  • 33
dole doug
  • 34,070
  • 20
  • 68
  • 87

3 Answers3

3

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
  • 951,095
  • 183
  • 1,149
  • 1,285
3

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

Nick Dandoulakis
  • 42,588
  • 16
  • 104
  • 136
2

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/8/10. 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
  • 6,788
  • 3
  • 29
  • 42