When I run keyToggle('w, 'down') it only taps the button once in text editors/chrome.
For example, my code:
robot.keyToggle('w', 'down');
setTimeout(function(){
robot.keyToggle('w', 'up');
}, 2000);
Only results in one 'w' character being entered in notepad or chrome.
However, if I run the code then switch to a game (Portal 2) it acts like it's holding it down and runs the character forwards, but the key stays down indefinitely (keyToggle up does nothing) and character keeps running forward.
So the functionality of this just seems like it's not working as expected for some reason. Note this was tested with the game running and without it running (just in the desktop using notepad/chrome URL bar).
Code:
var robot = require('robotjs');
robot.setKeyboardDelay(500);
function testWASD() {
console.log('testing');
toggleKey('w', 'down');
setTimeout(function(){
toggleKey('w', 'up');
}, 2000);
}
function toggleKey(key, direction) {
console.log('key:', key, ' direction:', direction);
robot.keyToggle(key, direction);
}
setTimeout(testWASD, 1000);
Found out this was the same solution as found here https://github.com/octalmage/robotjs/issues/252
Required rebuilding the project with some lines commented out as in this issue:
The same thing is occuring to me with minecraft. I am just pressing and releasing the "w" key to move forward and it doesn't release it. The character just keeps walking forward. I deleted the lines in keypress.c but nothing changed.
Most helpful comment
The same thing is occuring to me with minecraft. I am just pressing and releasing the "w" key to move forward and it doesn't release it. The character just keeps walking forward. I deleted the lines in keypress.c but nothing changed.