Keyboard hook in Windows C ++ or what?

I want to create my own application that can send keyboard commands (messages) on Windows.

For example, when I press the combination ctrl + shift + n, I want to run the notepad.exe file. How can i do this? You have some tips about the concept you are using.

I read that this is possible when using keyboard hooks? Is this the only way? Did you know that a free open source application that makes this as simple as possible?

+3
source share
3 answers

Your specific example can be executed without any programming whatsoever by right-clicking on Notepad, selecting Properties and selecting a hotkey (different versions of Windows may call it a different name) in Ctrl + Shift + N.

If you still want to write a program for this, look at the RegisterHotKey function of the Win32 API.

+3
source

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

+3
source

:

A system-wide keyboard hook requires a DLL entry. There's a sample keyboard hook code on my website here .

Hooks cannot be installed from a low-integrity application in Vista and Windows 7/8/10. Thus, there is no guarantee that your hook will work, depending on what the foreground application is at the touch of a key.

As Greg noted, a lot of time, RegisterHotKey is a much simpler solution to this problem.

+2
source

Source: https://habr.com/ru/post/1723328/


All Articles