When SendInput is called. how to prevent it?

I have a win 32 application written in C ++ that sets a low level keyboard hook. now i want to sendInput to any application like word / notepad. how to do it?

I have already done enough using findwindow / sendmessage. for all of these, I need to know the edit controls. finding editing is very difficult.

since SendInput works for any Windows application, I want to use it. The problem is that I get a call to my callback function with the key pressed.

for example, I pressed A and I want to send the Unicode character U + 0BAF to the windows of the active application. in this case, suppose it is a notepad.

the problem is that I get two characters U + 0BAF and A in notepad.

A is sent because I call CallNextHookEx (NULL, nCode, wParam, lParam);

if I return 1 after sendInput, then nothing is sent to notepad.

any suggestion?

+3
source share
1 answer

If I understand your problem correctly, you should ignore the "nested" key events
follow these steps:

LRESULT CALLBACK hook_proc( int code, WPARAM wParam, LPARAM lParam ) { KBDLLHOOKSTRUCT* kbd = (KBDLLHOOKSTRUCT*)lParam; // Ignore injected events if (code < 0 || (kbd->flags & 0x10)) { return CallNextHookEx(kbdhook, code, wParam, lParam); } ... 

Update: Additionally you must eat characters and notify about some other routines.
for character click through windows messages.

Example:

 ... // Pseudocode if (kbd->vkCode is character) { if (WM_KEYDOWN == wParam) { PostMessage(mainwnd, WM_MY_KEYDOWN, kbd->vkCode, 0); return 1; // eat the char, ie 'a' } } return CallNextHookEx(kbdhook, code, wParam, lParam); 

And in some other module you are processing WM_MY_KEYDOWN

 ie, #define WM_MY_KEYDOWN (WM_USER + 1) 

and call the appropriate procedure that will generate new key events.

+2
source

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


All Articles