Krombik / keysender

Node.js Desktop Automation for Windows.
MIT License
82 stars 9 forks source link

keyboard.toggleKey not woks as expected #7

Closed ch3rn1k closed 2 years ago

ch3rn1k commented 2 years ago

Can you explain how keyboard.toggleKey should work? I expected that after using keyboard.toggleKey(['ctrl', 'v'], true) it should hold an 'Ctrl+V' key and keyboard.toggleKey(['ctrl', 'v'], false) should release it. But I'm getting single paste as keyboard.sendKey(['ctrl', 'v'])

Am I doing something wrong?

ch3rn1k commented 2 years ago

Sample code:

const win = new Hardware();

win.keyboard.toggleKey(['ctrl', 'v'], true);
setTimeout(() => win.keyboard.toggleKey(['ctrl', 'v'], false), 2000);

Expected it should hold Ctrl+V and it will paste data in some input for 2 second (if caret is active), but I'm only getting single paste

Krombik commented 2 years ago

Toggle works as expected (you can open keyboardchecker and check it), but I found a bug with the false toggle (does not release the last key and releases the first key 2 times) and fixed it in the last version (2.0.4). If you want to paste a copy within 2 seconds, you can simply call the sendKey method in a loop.