Check key state?

Announcements, questions
Post Reply
Traveller
Posts: 5
Joined: 01 Mar 2021, 18:31

Check key state?

Post by Traveller » 02 Mar 2021, 19:20

I'm working on a project to use my second keyboard to do all sorts of cool stuff, for which I'm using LUAMacros for some tasks, and sending all the encoded key event data to a C# programme that does the rest.
I've noticed that although LUAMacros handles the KeyUp and KeyDown events when lmc_set_handler is suitable applied, it can do nothing to hide the state of a held key- for example, if you hold Ctrl on the 2nd (handled) keyboard and press V on the main (unhandled) keyboard, it is seen by the computer as a Ctrl + V combination. In an attempt to subdue this, I had the idea of sending a KeyUp event in my C# programme, which would get immediately handled by the same, thus triggering the virtual key in question to be marked as having been released.
In order to take care of the edge case in which the corresponding key of the main keyboard is simultaneously held (and thus I don't want to send a keyUp event), I was hoping to use LUAMacros to find out if the key is down on the main keyboard. Is there a function for getting the state of a key on a particular keyboard in LUAMacros?

admin
Site Admin
Posts: 725
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic
Contact:

Re: Check key state?

Post by admin » 03 Mar 2021, 08:59

No, there's not. Keyboard handling is event based so you can't check current state in windows api.
Petr Medek
LUAmacros author

Traveller
Posts: 5
Joined: 01 Mar 2021, 18:31

Re: Check key state?

Post by Traveller » 03 Mar 2021, 11:44

Thanks for the quick reply!
I guess I'll just handle the main keyboard events (simulating the actual key event) and make a virtual keyboard to reference. Sadly I've run into difficulties with the C# side of things. :( It turns out Windows isn't easily fooled.

Post Reply