multithreading - make `SetWindowsHookEx` call functions in my thread context -


In order to use SetWindowsHookEx in a GUI application, you usually want in the bottom row There is a function in your thread whenever any event is said whenever it is said.

For example, if I'm creating a software to suppress all the keys on the system, then I want my GUI app AddKeyToList (int vkeycode) in any way whenever a key is pressed is called.

I am not an expert in the interior of Windows, but if I understand the document correctly, it is being called in reference to the SetWindowsHookEx thread, due to which they are hooked Therefore, to do what I have described:

  1. Create a DLL that has hook function, and there is a shared memory area that will share and communicate all the threads through its medium With each other

  2. Create a pInvoke in a hook function and a GUI program. In our example, the hook function will send the pressed key to our GUI program, and the GUI program will implement the AddKeyToList function in its reference.

This is incredibly complex for a relatively simple class (compared to the XRecord extension in the Unix world), and maybe even impossible if you have Qt Use something like .

There are any libraries (preferably open source) which have already implemented those mechanisms, and enable me to use a "mask", for example, my Thread in context is a WH_KEYBOARD_LL ?

Am I correct with my analysis, or is there a simple method to achieve what I have described?

Can Qt library help me with this task?

This is the default behavior for WH_KEYBOARD_LL hooks previously Callback is called in a single thread, which is called SetWindowsHookEx () Is called. This thread needs to pump a message loop for it so that you can work automatically when using your UI thread. And the callback code does not need to be present in DLL, it is not a global hook that requires DLL injection.

No additional work is required to be done.


Comments