octalmage / robotjs

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

Please release the fixes #628

Closed RichardRNStudio closed 3 years ago

RichardRNStudio commented 3 years ago

Hey, I really approciate for this package, but I would like to see the following fix in the release. I was need to fork the repository and use npm link to reach this fix, but I would like to keep updated this package in the future.

Best regards, Richard

https://github.com/octalmage/robotjs/blob/master/src/keypress.c#L17

#if defined(IS_WINDOWS)
    #define WIN32_KEY_EVENT_WAIT(key, flags) \
        (win32KeyEvent(key, flags), Sleep(DEADBEEF_RANDRANGE(63, 125)))
#elif defined(USE_X11)
    #define X_KEY_EVENT(display, key, is_press) \
        (XTestFakeKeyEvent(display, \
                           XKeysymToKeycode(display, key), \
                           is_press, CurrentTime), \
         XSync(display, false))
    #define X_KEY_EVENT_WAIT(display, key, is_press) \
        (X_KEY_EVENT(display, key, is_press), \
         microsleep(DEADBEEF_UNIFORM(62.5, 125.0)))
#endif

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 +

Originally posted by @Kyusung4698 in https://github.com/octalmage/robotjs/issues/530#issuecomment-570795846

anonymousperson1209 commented 3 years ago

If you install with npm i git+https://github.com/octalmage/robotjs instead of npm i robotjs the issue is bypassed.

RichardRNStudio commented 3 years ago

Thank you, it's a good idea!

MLateralus commented 3 years ago

Removing the Sleep entirely causes the typeString to sometimes skip double occurances, in the words like: "Annoying" -> "Anoying" or "soon" -> "son"

I found that changing the values to border Sleep(DEADBEEF_RANDRANGE(11, 22) resolves this issue

Glutch commented 2 years ago

If you install with npm i git+https://github.com/octalmage/robotjs instead of npm i robotjs the issue is bypassed.

This didnt install for me, i had to switch to python2.7 i assumed, and changed the PATH. But this didn't work either and gives me the following error. Any suggestions?


npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@3.8.0
npm ERR! gyp info using node@16.13.0 | win32 | x64
npm ERR! gyp http GET https://nodejs.org/download/release/v16.13.0/node-v16.13.0-headers.tar.gz
npm ERR! gyp http 200 https://nodejs.org/download/release/v16.13.0/node-v16.13.0-headers.tar.gz
npm ERR! gyp http GET https://nodejs.org/download/release/v16.13.0/SHASUMS256.txt
npm ERR! gyp http GET https://nodejs.org/download/release/v16.13.0/win-x86/node.lib
npm ERR! gyp http GET https://nodejs.org/download/release/v16.13.0/win-x64/node.lib
npm ERR! gyp http 200 https://nodejs.org/download/release/v16.13.0/SHASUMS256.txt
npm ERR! gyp http 200 https://nodejs.org/download/release/v16.13.0/win-x86/node.lib
npm ERR! gyp http 200 https://nodejs.org/download/release/v16.13.0/win-x64/node.lib
npm ERR! (node:3636) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only.
npm ERR! (Use `node --trace-deprecation ...` to show where the warning was created)
npm ERR! gyp info spawn C:\Python27\python.EXE
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   'C:\\Users\\glutch\\AppData\\Local\\npm-cache\\_cacache\\tmp\\git-clonetSUDMX\\node_modules\\node-gyp\\gyp\\gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'msvs',
npm ERR! gyp info spawn args   '-G',
npm ERR! gyp info spawn args   'msvs_version=2015',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'C:\\Users\\glutch\\AppData\\Local\\npm-cache\\_cacache\\tmp\\git-clonetSUDMX\\build\\config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'C:\\Users\\glutch\\AppData\\Local\\npm-cache\\_cacache\\tmp\\git-clonetSUDMX\\node_modules\\node-gyp\\addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'C:\\Users\\glutch\\.node-gyp\\16.13.0\\include\\node\\common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=C:\\Users\\glutch\\.node-gyp\\16.13.0',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=C:\\Users\\glutch\\AppData\\Local\\npm-cache\\_cacache\\tmp\\git-clonetSUDMX\\node_modules\\node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=C:\\Users\\glutch\\.node-gyp\\16.13.0\\<(target_arch)\\node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=C:\\Users\\glutch\\AppData\\Local\\npm-cache\\_cacache\\tmp\\git-clonetSUDMX',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'C:\\Users\\glutch\\AppData\\Local\\npm-cache\\_cacache\\tmp\\git-clonetSUDMX\\build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp info spawn C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\15.0\Bin\MSBuild.exe
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   'build/binding.sln',
npm ERR! gyp info spawn args   '/clp:Verbosity=minimal',
npm ERR! gyp info spawn args   '/nologo',
npm ERR! gyp info spawn args   '/p:Configuration=Release;Platform=x64'
npm ERR! gyp info spawn args ]
npm ERR! gyp ERR! UNCAUGHT EXCEPTION
npm ERR! gyp ERR! stack Error: spawn C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\15.0\Bin\MSBuild.exe ENOENT
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:282:19)
npm ERR! gyp ERR! stack     at onErrorNT (node:internal/child_process:477:16)
npm ERR! gyp ERR! stack     at processTicksAndRejections (node:internal/process/task_queues:83:21)
npm ERR! gyp ERR! System Windows_NT 10.0.22000
npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\glutch\\AppData\\Local\\npm-cache\\_cacache\\tmp\\git-clonetSUDMX\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd C:\Users\glutch\AppData\Local\npm-cache\_cacache\tmp\git-clonetSUDMX
npm ERR! gyp ERR! node -v v16.13.0
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! This is a bug in `node-gyp`.
npm ERR! gyp ERR! Try to update node-gyp and file an Issue if it does not help:
npm ERR! gyp ERR!     <https://github.com/nodejs/node-gyp/issues>
npm ERR! npm ERR! code 7
npm ERR! npm ERR! path C:\Users\glutch\AppData\Local\npm-cache\_cacache\tmp\git-clonetSUDMX
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command C:\Windows\system32\cmd.exe /d /s /c prebuild-install || node-gyp rebuild