oblitum / Interception

The Interception API aims to build a portable programming interface that allows one to intercept and control a range of input devices.
http://oblita.com/interception
1.37k stars 267 forks source link

Possible Bug? #112

Open git-eternal opened 3 years ago

git-eternal commented 3 years ago

The Problem I am trying to re-map the users keys and have it press Z and X when they press the remapped keys. I have an option called "bind mode" that activates by pressing CTRL+ALT. Once they are in bind mode, I have a low level keyboard hook that reads the 2 new key values into 2 variables (of type short that store the vk key codes) and I use a function to convert the VK keys into the Linux Key code format you use in the driver. This all runs on a separate thread (I run the keyboard filter; aka interception stuff on one thread and the keyboard callback on another). Both do not have any sleeps (I doubt it would be a race condition since it works the first time, but I'm honestly not sure).

This is what the conversion does, its simple: Example with A key: 0x41 (windows VK code) gets converted to 0x1e (linux key code). This all works fine.

When I do it the first time, it works totally fine (the keys remap and everything works perfectly) (when I press Q it presses Z, when i press W it presses X). But when i press CTRL+ALT again and choose my 2 binds once more, when I press them, nothing happens (the keys themselves don't even work). It seems the strokes code gets set to 0 (even though it says the correct code before I interception_send the stroke)

Execution Example Here's an example of the execution. I bind it to QW first, works fine. Then i bind it to GH, and it sends 0 instead of 34 and 35 respectively. And no, my converter is correct. It does this with any other key. If i were to do GH first, it'll work, but if i remap to QW, it wont allow me to press QW (and just sends 0 in its place). image

The code Here's the entire function for where I filter keyboard input, enable/disable bind mode and remap their keys (this runs on a thread): https://pastebin.com/gTxUazJS

Conclusion I tried a bunch of stuff to fix this. I tried destroying the context early (after they press CTRL+ALT), I tried x64/x86 interception, I tried changing a bunch of my logic, making temp variables to store the previous stroke code and then sending them, and a myriad of other methods, but the stroke's code keeps getting set to 0 the 2nd time (and beyond) I re-bind my keys. I am unsure if this is simply a limitation or a bug within the driver, or there is some race condition or something going wrong due to my keyboard hook and the driver being ran on a thread with 0 sleeps. I can show more code and explain more about what I'm trying to do if needed (the whole file is only around ~140 lines). Would appreciate any assistance, thanks in advance!