octalmage / robotjs

Node.js Desktop Automation.
http://robotjs.io
MIT License
12.37k stars 961 forks source link

Using KeyToggle to hold down a key is not working (Mac Big Sur 11.4) #683

Closed Valachio closed 3 years ago

Valachio commented 3 years ago

I am trying to perform a shift-click. In other words, do a left mouse click whilst holding down the shift key, by using keyToggle(). I've tried several variations of the code but could not get it to work.

I first tried to do the following:

robot.keyToggle('shift', 'down');
robot.mouseClick();

It did not work, so I tried to use shift as a modifier key:

robot.keyToggle('shift', 'down', 'shift')
robot.mouseClick();

It also did not work. Then I tried to set the keyboard delay:

robot.setKeyboardDelay(3000);
robot.keyToggle('shift', 'down');
robot.mouseClick();

It also did not work. Then I tried to see if simply holding down a key works. I tried several keys:

robot.setKeyboardDelay(3000);
// I also tried "backspace", "a", "5"
robot.keyToggle('down', 'down');

All of them do not hold down the key. The current behavior is simply a single tap, so keyToggle() effectively works the same as keyTap() in my tests right now.

I'm not sure if I'm doing something wrong or there's some unexpected behavior in Mac. I researched several older posts on problems with holding down a key, such as this one and this one but trying some of the solutions in these posts, I still cannot use keyToggle() to perform a key hold.

My Environment:

JonasMatos0 commented 3 years ago

Hi, @Valachio Just tried here on PopOS and robot.keyToggle('shift', 'down') holds the shift smoothly. For MacOS there is this old thread https://github.com/octalmage/robotjs/issues/208 suggesting the use of Robot.keyToggle(String.fromCharCode(16), 'down', 'shift')

Can you try that out?