robotjs: typeString() and keyTap() slow even with 1ms delay
robot.setKeyboardDelay(1); robot.typeString('*cough');
is much slower than having *cough set in the clipboard and doing
robot.keyToggle('control','down') robot.keyTap('v');
I think it could be the blocking nature of the module, and the fact that my PC is very slow.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 14
- Comments: 28 (4 by maintainers)
Commits related to this issue
- fix: 修复丢字问题 方法来自 https://github.com/octalmage/robotjs/issues/530#issuecomment-858416432 — committed to zbczbc2006/robotjs by deleted user 3 years ago
https://github.com/octalmage/robotjs/blob/master/src/keypress.c#L17
tapKey uses toggleKeyCode which calls WIN32_KEY_EVENT_WAIT once for a key and twice for a key with modifiers and therefore it can generate an additional delay of max 250ms. i dunno why there is a extra sleep call. i forked the repository and removed it and it works fine. < 2ms per call instead of 300ms +
Note to others with this issue, installing directly from git seems to work:
(This is undesirable because, in general, the git source is not necessarily the same as the npm package contents. Also because it doesn’t specify a version constraint. But it’s better than nothing and in this case seems to work …)
@fttx nope. i searched for weeks until i swapped to this package https://nutjs.dev/
The temporary fix i used was copy text and paste.
It uses X_KEY_EVENT_WAIT on linux and therefore the sleep is the same as on windows.
@lucasguaru You could always try to patch it with patch-package if you need to have it fixed locally.
@ricardopolo sometimes I want to hide the fact that I’m using a bot. Typing impossibly fast is a dead giveaway. That said, typeString isn’t designed to be slow… typeStringDelayed is. Everything looks great with #560 …