Upon calling keyToggle('a', 'down'), the key gets registered as pressed, but when calling keyToggle again, this time with the following parameters keyToggle('a', 'up'), the 'a' key isn't released.
keyToggle('a', 'u') should release the key 'a' if pressed.
keyToggle('a', 'u') leaves the 'a' key in pressed state.
I have tested this solution on my machine, but I don't want to submit a pull request because I fear I might break something.
In keypress.c at line 100 there is a piece of code that modifies the scan code if the KEYUP flag is set. Upon removing this block of code, the API _seems_ to be working as intended. Please check if the if statement is really necessary as it seems to be breaking the code.
I'm building a gamepad that responds to commands and I've realized the bug in keyToggle.
Was having the same issues as Hrastnik and as he suggested I commented out the block in keypress.c at line 100. This solved the issue for me aswell.
/* Set the scan code for keyup */
//if ( flags & KEYEVENTF_KEYUP ) {
// scan |= 0x80;
//}
Big thanks!
You're a hero! This solution was exactly what I needed. It's really strange to me, because the official key-release example for keybd_event() does not OR the scancode with 0x80. I saw some olds specs for PS/2 keyboards that involved doing it, but it seems to just break key releases in many modern apps for some reason.
@hrastnik Solution fixed it for me. Thanks so much!
This solution is not working for me in Minecraft...
@jorrharris can you please create a reproducible code in another issue? Closing that one as it is stale
thank
Why isn't this being merged into the original package?
https://github.com/psigen/robotjs/commit/0ac61e43633c27712643218ca5148f6fb214c425
It seem that some games / game engine possibly hijack or change the way keyup are handled...
The resulting behavior is the first keypress work, other doesn't... unless the key is manually pressed in between.
Removing the line 100 from keypress.c actually fix the problem for Star Citizen on my end.
Since it may interfere with other activity, a change in the C code to have this check performed or not would be a long term solution to avoid people running their own fork.
Most helpful comment
Was having the same issues as Hrastnik and as he suggested I commented out the block in keypress.c at line 100. This solved the issue for me aswell.
/* Set the scan code for keyup */ //if ( flags & KEYEVENTF_KEYUP ) { // scan |= 0x80; //}Big thanks!