Robotjs: keyToggle doesn't release key

Created on 5 Dec 2016  路  8Comments  路  Source: octalmage/robotjs

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.

Expected Behavior

keyToggle('a', 'u') should release the key 'a' if pressed.

Current Behavior

keyToggle('a', 'u') leaves the 'a' key in pressed state.

EDIT: SOLUTION!!!

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.

Steps to Reproduce (for bugs)

  1. Call robotjs.keyToggle('a', 'down')
  2. Confirm 'a' key is pressed.
  3. Call robotjs.keyToggle('a', 'up')
  4. Confirm 'a' key is still pressed when it should be released.

Context

I'm building a gamepad that responds to commands and I've realized the bug in keyToggle.

Your Environment

  • RobotJS version: 0.4.5
  • Node.js version: 6.7.0
  • npm version: 3.10.3
  • Operating System: Windows 10

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!

All 8 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

linonetwo picture linonetwo  路  12Comments

ylh888 picture ylh888  路  3Comments

HopefulLlama picture HopefulLlama  路  3Comments

EdSaleh picture EdSaleh  路  8Comments

vnsharma-systango picture vnsharma-systango  路  9Comments