Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added left and right control keys #261

Merged
merged 3 commits into from
Nov 24, 2019
Merged

Conversation

Deathnerd
Copy link
Contributor

I have a use case where my application has to distinguish between left and right control keys (automating Farming Simulator). I think this is all that needs to be done. I've looked up the proper Linux, MacOS, and Windows keycodes (or at least what a quick Googlin' says is proper). It builds in my Debian Jessie VM. My Windows environment isn't set up for C/C++ development and I don't have access to a Mac so this would need to be built and tested on those systems.

I noticed there are two references in the keypress.c (if (flags & MOD_CONTROL) WIN32_KEY_EVENT_WAIT(K_CONTROL, dwFlags); and if (flags & MOD_CONTROL) X_KEY_EVENT_WAIT(display, K_CONTROL, is_press);) for Windows and Linux respectively to (I'm guessing) deal with using the ctrl keys as modifiers. Would this need modifying here to make sure that the proper ctrl key is used as a modifier?

I'm pretty much flying blind here, but the ability to distinguish between left and right control keys is a must have for me (and I'm sure others). I'm willing to work with the maintainers on making sure this code is correct and working.

Thanks

@danieltian
Copy link

danieltian commented Jun 6, 2017

I also need Right Control. I tried building this PR on Windows, and this is the output I get:

$ node-gyp rebuild
gyp info it worked if it ends with ok
gyp info using node-gyp@3.6.2
gyp info using node@6.7.0 | win32 | x64
gyp info spawn c:\Python27\python.EXE
gyp info spawn args [ 'c:\\Users\\Daniel\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'msvs',
gyp info spawn args   '-G',
gyp info spawn args   'msvs_version=auto',
gyp info spawn args   '-I',
gyp info spawn args   'c:\\Users\\Daniel\\Desktop\\Projects\\elgato-stream-deck-test\\node_modules\\robotjs\\build\\config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'c:\\Users\\Daniel\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\Daniel\\.node-gyp\\6.7.0\\include\\node\\common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=C:\\Users\\Daniel\\.node-gyp\\6.7.0',
gyp info spawn args   '-Dnode_gyp_dir=c:\\Users\\Daniel\\AppData\\Roaming\\npm\\node_modules\\node-gyp',
gyp info spawn args   '-Dnode_lib_file=C:\\Users\\Daniel\\.node-gyp\\6.7.0\\<(target_arch)\\node.lib',
gyp info spawn args   '-Dmodule_root_dir=c:\\Users\\Daniel\\Desktop\\Projects\\elgato-stream-deck-test\\node_modules\\robotjs',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'c:\\Users\\Daniel\\Desktop\\Projects\\elgato-stream-deck-test\\node_modules\\robotjs\\build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe
gyp info spawn args [ 'build/binding.sln',
gyp info spawn args   '/clp:Verbosity=minimal',
gyp info spawn args   '/nologo',
gyp info spawn args   '/p:Configuration=Release;Platform=x64' ]
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  robotjs.cc
  win_delay_load_hook.cc
c:\users\daniel\desktop\projects\elgato-stream-deck-test\node_modules\robotjs\src\os.h(26): warnin
g C4005: 'STRICT': macro redefinition (compiling source file ..\src\robotjs.cc) [c:\Users\Daniel\D
esktop\Projects\elgato-stream-deck-test\node_modules\robotjs\build\robotjs.vcxproj]
  C:\Program Files (x86)\Windows Kits\8.1\Include\shared\minwindef.h(23): note: see previous defin
  ition of 'STRICT' (compiling source file ..\src\robotjs.cc)
..\src\robotjs.cc(593): warning C4267: 'argument': conversion from 'size_t' to 'const unsigned int
', possible loss of data [c:\Users\Daniel\Desktop\Projects\elgato-stream-deck-test\node_modules\ro
botjs\build\robotjs.vcxproj]
..\src\robotjs.cc(729): warning C4267: 'initializing': conversion from 'size_t' to 'uint32_t', pos
sible loss of data [c:\Users\Daniel\Desktop\Projects\elgato-stream-deck-test\node_modules\robotjs\
build\robotjs.vcxproj]
c:\users\daniel\desktop\projects\elgato-stream-deck-test\node_modules\nan\nan_new.h(208): warning
C4244: 'argument': conversion from 'size_t' to 'double', possible loss of data (compiling source f
ile ..\src\robotjs.cc) [c:\Users\Daniel\Desktop\Projects\elgato-stream-deck-test\node_modules\robo
tjs\build\robotjs.vcxproj]
  ..\src\robotjs.cc(669): note: see reference to function template instantiation 'v8::Local<v8::Nu
  mber> Nan::New<v8::Number,size_t>(A0)' being compiled
          with
          [
              A0=size_t
          ]
  deadbeef_rand.c
  mouse.c
  keypress.c
  keycode.c
  screen.c
  screengrab.c
  snprintf.c
  MMBitmap.c
..\src\deadbeef_rand.c(26): warning C4267: 'return': conversion from 'size_t' to 'uint32_t', possi
ble loss of data [c:\Users\Daniel\Desktop\Projects\elgato-stream-deck-test\node_modules\robotjs\bu
ild\robotjs.vcxproj]
..\src\mouse.c(114): warning C4267: '=': conversion from 'size_t' to 'LONG', possible loss of data
 [c:\Users\Daniel\Desktop\Projects\elgato-stream-deck-test\node_modules\robotjs\build\robotjs.vcxp
roj]
..\src\mouse.c(115): warning C4267: '=': conversion from 'size_t' to 'LONG', possible loss of data
 [c:\Users\Daniel\Desktop\Projects\elgato-stream-deck-test\node_modules\robotjs\build\robotjs.vcxp
roj]
..\src\mouse.c(349): warning C4244: '+=': conversion from 'double' to 'size_t', possible loss of d
ata [c:\Users\Daniel\Desktop\Projects\elgato-stream-deck-test\node_modules\robotjs\build\robotjs.v
cxproj]
..\src\mouse.c(350): warning C4244: '+=': conversion from 'double' to 'size_t', possible loss of d
ata [c:\Users\Daniel\Desktop\Projects\elgato-stream-deck-test\node_modules\robotjs\build\robotjs.v
cxproj]
..\src\snprintf.c(965): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of da
ta [c:\Users\Daniel\Desktop\Projects\elgato-stream-deck-test\node_modules\robotjs\build\robotjs.vc
xproj]
..\src\snprintf.c(911): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible
 loss of data [c:\Users\Daniel\Desktop\Projects\elgato-stream-deck-test\node_modules\robotjs\build
\robotjs.vcxproj]
..\src\snprintf.c(939): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible
 loss of data [c:\Users\Daniel\Desktop\Projects\elgato-stream-deck-test\node_modules\robotjs\build
\robotjs.vcxproj]
..\src\snprintf.c(956): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible
 loss of data [c:\Users\Daniel\Desktop\Projects\elgato-stream-deck-test\node_modules\robotjs\build
\robotjs.vcxproj]
..\src\screengrab.c(118): warning C4267: 'function': conversion from 'size_t' to 'int', possible l
oss of data [c:\Users\Daniel\Desktop\Projects\elgato-stream-deck-test\node_modules\robotjs\build\r
obotjs.vcxproj]
..\src\snprintf.c(976): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible
 loss of data [c:\Users\Daniel\Desktop\Projects\elgato-stream-deck-test\node_modules\robotjs\build
\robotjs.vcxproj]
..\src\screengrab.c(119): warning C4267: 'function': conversion from 'size_t' to 'int', possible l
oss of data [c:\Users\Daniel\Desktop\Projects\elgato-stream-deck-test\node_modules\robotjs\build\r
obotjs.vcxproj]
..\src\snprintf.c(988): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible
 loss of data [c:\Users\Daniel\Desktop\Projects\elgato-stream-deck-test\node_modules\robotjs\build
\robotjs.vcxproj]
     Creating library c:\Users\Daniel\Desktop\Projects\elgato-stream-deck-test\node_modules\robotj
  s\build\Release\robotjs.lib and object c:\Users\Daniel\Desktop\Projects\elgato-stream-deck-test\
  node_modules\robotjs\build\Release\robotjs.exp
  Generating code
  Finished generating code
  robotjs.vcxproj -> c:\Users\Daniel\Desktop\Projects\elgato-stream-deck-test\node_modules\robotjs
  \build\Release\\robotjs.node
gyp info ok

Which looks like it built fine. But when I try to use right control, I get the following exception:

c:\Users\Daniel\Desktop\Projects\elgato-stream-deck-test\server.js:88
      robot.keyTap('c', 'right_control');
            ^

Error: Invalid key flag specified.
    at Error (native)

@danieltian
Copy link

I figured it out, using this won't work:

robot.keyTap('c', 'right_control');

because right_control is not defined in CheckKeyFlags in robotjs.cc. To fix it, you need to split the key press into a separate key toggle:

robot.keyToggle('right_control', 'down');
robot.keyTap('c');
robot.keyToggle('right_control', 'up');

@Deathnerd
Copy link
Contributor Author

@danieltian Thanks for testing on Windows! Now if only we could get a Mac build tested...

@rj0495
Copy link

rj0495 commented Jun 26, 2017

Mac build looks like it's working. Should be merged. But I'd say fix the bug as mentioned above.

@Deathnerd
Copy link
Contributor Author

Awesome. Thanks @rj0495 . I'll have to get my environment set up again (drive died on me in a spectacular way a week or so ago) and get the bug taken care of.

This is to fix the bug in octalmage#261 . Haven't tested it yet since I don't have a working environment yet, but I cannot find anything in the platform documentations that specify a left or right control mask different from the mask that is currently assigned to `MOD_CONTROL` in `keypress.h`. 

Oh, and this also extends the functionality to `right_shift` as well
@octalmage
Copy link
Owner

Sorry everyone, releasing and building is currently difficult since I have to spin up a bunch of VMs. I'm going to work on getting TravisCI publishing so it's easier to test and deploy. Thanks for the PR!

@Deathnerd
Copy link
Contributor Author

Deathnerd commented Feb 24, 2018

Oh. Wow. I suppose I should fix that bug... unless I already did and I forgot

Edit: Looks like I did. I guess I'll go see what the appveyor hub-ub is all about

Edit - Electric Boogaloo: Looks like Appveyor was running old versions of Node that don't like the unit tests

@Deathnerd
Copy link
Contributor Author

Oh and no problem! Happy that I was able to extend and help others :)

@oktapodia
Copy link
Collaborator

Thank you for your PR!

@oktapodia oktapodia merged commit 87bec5a into octalmage:master Nov 24, 2019
8KCool pushed a commit to 8KCool/robotJS that referenced this pull request Feb 18, 2023
This is to fix the bug in octalmage/robotjs#261 . Haven't tested it yet since I don't have a working environment yet, but I cannot find anything in the platform documentations that specify a left or right control mask different from the mask that is currently assigned to `MOD_CONTROL` in `keypress.h`. 

Oh, and this also extends the functionality to `right_shift` as well
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants