How can I do something ~ after the event happened in C #?

I am using the following project to handle global keyboard and mouse in my C # application.

This project is basically a wrapper for invoking the SetWindowsHookEx Win API using the WH_MOUSE_LL or WH_KEYBOARD_LL constants. It also manages a certain state and, as a rule, makes this capture method quite free.

I use this for the mouse gesture recognition software I'm working on. Basically, I have a setting so that it detects when a global hotkey is pressed (e.g. CTRL), then the user moves the mouse in the form of a predefined gesture, and then releases the global hotkey.

An event for KeyDown is handled and tells my program to start recording mouse locations until it receives a KeyUp event. This works great, and allows users to easily enter mouse gestures. As soon as the KeyUp event is triggered and it detects the corresponding gesture, it is supposed to send certain keystrokes to the active window that the user defined for this specific gesture that they just drew.

I use the SendKeys.Send / SendWait methods to send output to the current window.

My problem is this: when the user releases his global hotkey (e.g. CTRL), he fires the KeyUp event. My program takes the recorded mouse points and detects the corresponding gesture and tries to send the correct input via SendKeys.

However, since all this is in the KeyUp event, this global hotkey has not finished processing. So, for example, if I defined a gesture to send the key "A" when it is detected, and my global hotkey is CTRL when it is detected, SendKeys will send "A", but for now CTRL is still down. So instead of just sending A, I get CTRL-A. So, in this example, instead of physically sending a single “A” character, he selects everything through the CTRL-A combination. Although the user has issued CTRL (global hotkey), he is still viewed down by the system.

KeyUp , - , , SendKeys?

+3
1

SendKeys (, 100 ), , , KeyUp.

( PostMessage) , , "" SendKeys . , - "". ( .NET, P/Invoke API, , WndProc ...

+3

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


All Articles