Receiving input if the window is inactive (Windows)

Short version:

How can I receive input messages in Windows with C ++ / C when the window is not active?

Background Information:

I am currently working on an input system, which should not depend on any window, so it can be, for example, can also be used in the console.

My idea is to create an invisible window that receives only messages, which is possible using HWND_MESSAGE as hWndParent. It only accepts input messages when it is active, and I do not want this. It should always receive input (if the application does not request it no longer does this, for example, because it has lost focus).

I know that this is possible, one way or another, many applications support global shortcuts (for example, media players (playback control) or messengers (opening a contact list)), I just don’t know how to do this. Did you know?

+4
source share
2 answers

Parameters:

  • RegisterHotKey , if you need to register only one or several hot keys
  • SetWindowsHookEx with WH_KEYBOARD / WH_KEYBOARD_LL. Use when you need to filter out many or all keyboard events. However, the hook code must be implemented in a DLL (which is loaded into other processes). You need separate 32-bit and 64-bit versions of the DLL
+2
source

You need to configure the Windows keyboard input hook. Here is an example of how to do this; it is even easier to do in C ++

+1
source

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


All Articles