octalmage / robotjs

Node.js Desktop Automation.

Home Page:http://robotjs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Windows Support.

scottmas opened this issue · comments

Edit by octalmage:

Windows is completely supported! Just install from npm.

Known issues:

All known issues resolved!

  • getPixelColor returns "000000" no matter what in my VM, not sure if it's broken. Fixed in #43.
  • The sqrt functions in rgb.h cause errors, currently commented out in the windows-2 branch. Fixed in 8730e94.
  • The mssleep function needs to be cross platform. Replaced with microsleep.
  • moveMouse and moveMouseSmooth wouldn't work in my virtual machine. I'm guessing this is because it's a VM, but it would be cool if someone could confirm. This is working!

Original comment:
Hey Octa, I'm trying to use your add on for a node webkit project I'm working on but wasn't able to get very far since the package gets stuck on my windows machine while running the "node-gyp configure" command, just sitting there endlessly. I thought possible your NPM might not be up to date with this github repo, but still the same behavior when I cloned the repo and built it from scratch.

I notice in binding.gyp that your only condition is 'OS' == "mac". I'm not intimately familiar with building native node modules, so does this mean the package simply does not support window builds right now?

So my original question was actually resolved once I manually downloaded some nodejs.org packages (don't think it had anything to do with robotjs). And it appears from your source code at least that the library is designed to support windows machines.

However, now I have a different problem :(, the "node-gyp build" task breaks when run and I get a whole string of errors. Are our Windows build environment must be different? I'm running node v.0.10.30 on Windows 7 using Python 2.78 and the latest visual studio 2013.

I could post the complete error log if you would find that helpful, but to give you a sense, I'm getting errors such as the following:

..\src\ms_stdint.h(102): error C2371: 'int_fast16_t' : redefinition; different basic types [..\build\robotjs.vcxproj]
--or--
..\src\robotjs.cc(87): error C2065: 'MMKeyFlags' : undeclared identifier [..\build\robotjs.vcxproj]
--or--
..\src\robotjs.cc(142): error C2146: syntax error : missing ';' before identifier 'info' [..\build\robotjs.vcxproj]

Note, I'm also using node v0.10.30. Based on the feature enhancement you recently added to use the nan package in order to support newer versions, it seems likely this could be the case. Is this correct?

It seems to be a possible combination of missing libraries and syntax errors. Also, note that these errors occur whether building from npm or building directly from the repo.

Hey Scott!

My apologies for the delay. I've honestly never tried to build RobotJS on Windows and it's probably just missing a few libraries. I had a similar issue on Mac until I added that conditional.

I'll try to take a look today (need to set up a VM), and I may need your help testing a few things!

That would be awesome. Let me know how I could be useful with testing or something. As far as c++ goes, I'm sadly a complete n00b :(

I haven't forgot about this! I just really need a windows build environment.

Spent a few hours on this just now, didn't have much luck.

Here's the errors I'm getting on Windows XP using Visual Studio 2010:

c:\documents and settings\administrator\desktop\robotjs\robotjs\src\os.h(23): warning C4005: 'STRICT' : macro redefinition
          C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\windef.h(16) : see previous definition of 'STRICT'
c:\documents and settings\administrator\desktop\robotjs\robotjs\src\ms_stdint.h(101): error C2371: 'int_fast8_t' : redefinition; different basic types
          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\stdint.h(33) : see declaration of 'int_fast8_t'
c:\documents and settings\administrator\desktop\robotjs\robotjs\src\ms_stdint.h(102): error C2371: 'int_fast16_t' : redefinition; different basic types
          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\stdint.h(34) : see declaration of 'int_fast16_t'
c:\documents and settings\administrator\desktop\robotjs\robotjs\src\ms_stdint.h(106): error C2371: 'uint_fast16_t' : redefinition; different basic types
          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\stdint.h(38) : see declaration of 'uint_fast16_t'
c:\documents and settings\administrator\desktop\robotjs\robotjs\src\keycode.h(134): error C2059: syntax error : '}'
c:\documents and settings\administrator\desktop\robotjs\robotjs\src\keycode.h(134): error C2143: syntax error : missing ';' before '}'
c:\documents and settings\administrator\desktop\robotjs\robotjs\src\keycode.h(134): error C2059: syntax error : '}'
c:\documents and settings\administrator\desktop\robotjs\robotjs\src\keypress.h(15): error C2143: syntax error : missing ';' before '{'
c:\documents and settings\administrator\desktop\robotjs\robotjs\src\keypress.h(15): error C2447: '{' : missing function header (old-style formal list?)
c:\documents and settings\administrator\desktop\robotjs\robotjs\src\rgb.h(87): error C2668: 'sqrt' : ambiguous call to overloaded function
          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\math.h(589): could be 'long double sqrt(long double)'
          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\math.h(541): or       'float sqrt(float)'
          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\math.h(127): or       'double sqrt(double)'
          while trying to match the argument list '(int)'
c:\documents and settings\administrator\desktop\robotjs\robotjs\src\rgb.h(103): error C2668: 'sqrt' : ambiguous call to overloaded function
          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\math.h(589): could be 'long double sqrt(long double)'
          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\math.h(541): or       'float sqrt(float)'
          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\math.h(127): or       'double sqrt(double)'
          while trying to match the argument list '(int)'
..\src\robotjs.cc(175): error C2065: 'MMKeyFlags' : undeclared identifier
..\src\robotjs.cc(175): error C2146: syntax error : missing ';' before identifier 'flags'
..\src\robotjs.cc(175): error C2065: 'flags' : undeclared identifier
..\src\robotjs.cc(175): error C2065: 'MOD_NONE' : undeclared identifier
..\src\robotjs.cc(179): error C2065: 'flags' : undeclared identifier
..\src\robotjs.cc(179): error C3861: 'tapKey': identifier not found
..\src\robotjs.cc(193): error C2664: 'typeString' : cannot convert parameter 1 from 'char *' to 'const v8::Arguments &'
          Reason: cannot convert from 'char *' to 'const v8::Arguments'
          No constructor could take the source type, or constructor overload resolution was ambiguous

This isn't too terrible, and at least it's a start!

@plasmashadow was working on this today, hopefully he had better luck.

commented

@octalmage Getting the same error when I tried to build robotjs in windows

..\robotjs\src\os.h(26): warning C4005: 'STRICT' : macro redefinition [..\robotjs\build\robotjs.vcxproj]
      C:\Program Files (x86)\Windows Kits\8.0\Include\shared\minwindef.h(23) : see previous definition of 'STRICT'
..\robotjs\src\ms_stdint.h(102): error C2371: 'int_fast16_t' : redefinition; different basic types [..t\robotjs\build\robotjs.vcxproj]
      C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdint.h(27) : see declaration of 'int_fast16_t'
..\robotjs\src\ms_stdint.h(106): error C2371: 'uint_fast16_t' : redefinition; different basic types [..\robotjs\build\robotjs.vcxproj]
      C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdint.h(31) : see declaration of 'uint_fast16_t'

Still having issues here. I fixed a bunch of the errors in 581cbdc, but now there's more. I'm probably going to reach out to someone more familiar with gyp for help.

commented

+1

I really need to get this working. As more projects start to rely on RobotJS, I'm letting them and their users down by not supporting Windows.

I've been doing a lot of research and I have some new ideas, I'm going to hit this hard tomorrow. At the end of Thursday if I can't get it building I'll post to the gyp mailing list.

The code is cross platform, I just need to set the right flags for MSVC. My goal is to publish a Windows compatible build by the end of the month.

Wish me luck!

commented

+1

I'm praying to the C/C++ gods.

+1

Going to need another week, it's going to happen this month!

So I'm getting close with this as my bindings.gyp:

{
  'targets': [{
    'target_name': 'robotjs',
    'include_dirs': [
        '<!(node -e \'require("nan")\')'
    ],
    'cflags': [
      '-Wall',
      '-Wparentheses',
      '-Winline',
      '-Wbad-function-cast',
      '-Wdisabled-optimization'
    ],
    'conditions': [
      ['OS == "mac"', {
        'include_dirs': [
          'System/Library/Frameworks/CoreFoundation.Framework/Headers',
          'System/Library/Frameworks/Carbon.Framework/Headers',
          'System/Library/Frameworks/ApplicationServices.framework/Headers',
          'System/Library/Frameworks/OpenGL.framework/Headers',
        ],
        'link_settings': {
          'libraries': [
            '-framework Carbon',
            '-framework CoreFoundation',
            '-framework ApplicationServices',
            '-framework OpenGL'
          ]
        }
      }],
        ["OS=='win'", {
        'defines': [
        'IS_WINDOWS'],
        'libraries': [
          'gdi32',
          'user32',
          'advapi32',
          'gdiplus',
        ],
        'include_dirs': [
            'node_modules/nan/'
        ],
          "configurations": {
            "Release": {
              "msvs_settings": {
                "VCCLCompilerTool": {
                  "RuntimeLibrary": "3"
                }
              },
            },
            "Debug": {
              "msvs_settings": {
                "VCCLCompilerTool": {
                  "RuntimeLibrary": "3"
                }
              },
            }
          },
          }],
      ['OS == "linux"', {
        'link_settings': {
          'libraries': [
            '-lpng',
            '-lz',
            '-lX11',
            '-lXtst'
          ]
        },

        'sources': [
          'src/xdisplay.c'
        ]
      }]
    ],

    'sources': [
      'src/robotjs.cc',
      'src/deadbeef_rand.c',
      'src/mouse.c',
      'src/keypress.c',
      'src/keycode.c',
      'src/screen.c',
      'src/screengrab.c',
      'src/MMBitmap.c'
    ]
  }]
}

I know it's a mess, but it's getting me close.

The errors I'm getting seem to be related to using C:

c:\documents and settings\administrator\desktop\robotjs\robotjs\src\rgb.h(37):
error C2061: syntax error : identifier 'MMRGBHex' [C:\Documents and Settings\Ad
ministrator\Desktop\robotjs\robotjs\build\robotjs.vcxproj]
c:\documents and settings\administrator\desktop\robotjs\robotjs\src\rgb.h(37):
error C2059: syntax error : ';' [C:\Documents and Settings\Administrator\Deskto
p\robotjs\robotjs\build\robotjs.vcxproj]
c:\documents and settings\administrator\desktop\robotjs\robotjs\src\rgb.h(48):
error C2061: syntax error : identifier 'hexFromMMRGB' [C:\Documents and Setting
s\Administrator\Desktop\robotjs\robotjs\build\robotjs.vcxproj]
c:\documents and settings\administrator\desktop\robotjs\robotjs\src\rgb.h(48):
error C2059: syntax error : ';' [C:\Documents and Settings\Administrator\Deskto
p\robotjs\robotjs\build\robotjs.vcxproj]
c:\documents and settings\administrator\desktop\robotjs\robotjs\src\rgb.h(48):
error C2059: syntax error : 'type' [C:\Documents and Settings\Administrator\Des
ktop\robotjs\robotjs\build\robotjs.vcxproj]
c:\documents and settings\administrator\desktop\robotjs\robotjs\src\rgb.h(58):
error C2146: syntax error : missing ')' before identifier 'hex' [C:\Documents a
nd Settings\Administrator\Desktop\robotjs\robotjs\build\robotjs.vcxproj]
c:\documents and settings\administrator\desktop\robotjs\robotjs\src\rgb.h(58):
error C2061: syntax error : identifier 'hex' [C:\Documents and Settings\Adminis
trator\Desktop\robotjs\robotjs\build\robotjs.vcxproj]
c:\documents and settings\administrator\desktop\robotjs\robotjs\src\rgb.h(58):
error C2059: syntax error : ';' [C:\Documents and Settings\Administrator\Deskto
p\robotjs\robotjs\build\robotjs.vcxproj]

Unfortunately I wasn't able to get the project to build. This is very disheartening but I posted to the Node.js mailing list. Hopefully I'll get some help there.

I just want a Windows build so bad, If anyone is familiar with Visual Studio, we could use your help!

I've tried to run it on Windows, some stuff I found while trying to get it working.

The file https://github.com/octalmage/robotjs/blob/master/src/ms_stdint.h is already included by libuv, which results in duplicated definition errors.

https://github.com/octalmage/robotjs/blob/master/src/robotjs.cc#L286 There is no nanosleep or timespec types on Windows, so this function is doomed.

The nan include in the binding.gyp file is not working because it's using single quotes.

I'm using Visual Studio 12, and I can include stdint.h just fine, idk about other versions.

After fixing those errors I was able to get it compiled.

Also, the only thing I've modified in the binding file was what I said above, about the nan include.

No way!!! You are my hero @JCMais.

The ms_stdint.h/libuv issue probably caused a ton of the errors I was seeing, great find! I guess we should just remove this completely right?

The nanosleep stuff is new, we'll need to make a cross platform equivalent, or remove it. Still not sure if I want to have the delay built in or make everything chainable. #14 #27

Anyway, thanks a ton!

I played with this today and was able to get RobotJS building on Windows in 10 minutes thanks to the comment from @JCMais. I'll get it cleaned up and released this week!

Does this mean there's official Windows support now? Sick!

@RangerMauve there will be soon! I'm so excited.

Could someone help me test the Windows build?

https://github.com/octalmage/robotjs/tree/windows

There might be some issues with this branch, if it doesn't build try robotjs.zip.

Known issues:

  • getPixelColor is broken because of the snprintf, I'm probably going to write my own padding function.
  • The mssleep function needs to be cross platform.
  • moveMouse and moveMouseSmooth wouldn't work in my virtual machine. I'm guessing this is because it's a VM, but it would be cool if someone could confirm.

Thanks!

cc: @anand-seeenivasagam @plasmashadow.

Looks like the version in the zip file works, windows branch does not. Using the windows branch:

$ node-gyp build
gyp info it worked if it ends with ok
gyp info using node-gyp@2.0.1
gyp info using node@0.10.26 | win32 | x64
gyp info spawn C:\Program Files (x86)\MSBuild\12.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
..\src\robotjs.cc(2): fatal error C1083: Cannot open include file: 'nan.h': No such file or directory [C:\Users\{username}\workspace\temp\ro botjs\build\robotjs.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\12.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\{username}\AppData\Roaming\npm\node_modules\node-gyp\lib\build.js:269:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:797:12)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\{username}\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "build"
gyp ERR! cwd C:\Users\{username}\workspace\temp\robotjs
gyp ERR! node -v v0.10.26
gyp ERR! node-gyp -v v2.0.1
gyp ERR! not ok

Using the zip file:

$ node-gyp build
gyp info it worked if it ends with ok
gyp info using node-gyp@2.0.1
gyp info using node@0.10.26 | win32 | x64
gyp info spawn C:\Program Files (x86)\MSBuild\12.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.
[snip....]
  build\Release\robotjs.exp
  Generating code
  Finished generating code
  robotjs.vcxproj -> C:\Users\{username}\workspace\temp\robotjs2\build\Release\\robotjs.node
gyp info ok

$ npm test

> robotjs@0.1.2 test C:\Users\{username}\workspace\temp\robotjs2
> node test/all.js

TAP version 13
# get the initial mouse position
ok 1 successfully retrieved mouse position
ok 2 mousepos.x is a valid value
ok 3 mousepos.y is a valid value

1..3
# tests 3
# pass  3

# ok

P.S. looking forward to using this!

Thanks @Hypercubed!

Could you try this code?

var robot = require("robotjs");

//Get the mouse position, returns an object with x and y. 
var mouse=robot.getMousePos();
console.log("Mouse is at x:" + mouse.x + " y:" + mouse.y);

//Move the mouse down by 100 pixels.
robot.moveMouse(mouse.x,mouse.y+100);

//Left click!
robot.mouseClick();

I'm mostly interested in the moveMouse and mouseClick.

Also with the windows branch, it looks like you need to do npm install first to install nan.

Thanks again!

I tried the windows branch again (now on a win 8, was on win 7 before) after running npm install nan. Still no luck.

The zipped build does work on windows 8. I ran the following:

var robot = require("./index");

//Get the mouse position, returns an object with x and y.
var mouse=robot.getMousePos();
console.log("Mouse is at x:" + mouse.x + " y:" + mouse.y);

//Move the mouse down by 100 pixels.
robot.moveMouse(mouse.x,mouse.y+100);
mouse=robot.getMousePos();
console.log("Mouse is at x:" + mouse.x + " y:" + mouse.y);

//Left click!
robot.mouseClick();

and got:

$ node test.js
Mouse is at x:296 y:390
Mouse is at x:289 y:484

@Hypercubed I had a feeling a messed up the windows branch.

It looks like moveMouse works! Woohoo! That's super good news. I'll work on the other non cross platform code now.

commented

@octalmage probably doing something wrong, but the zipped build you linked in #2 (comment) throws an %1 is not a valid win32 application error for me on win8 64bit

@nikersify hmm I haven't seen that before. What steps did you follow?

commented

@octalmage simply thrown the zip's contents into node_modules/robotjs then tried to require it

commented

@octalmage also just now I've tried npm installing directly from github which fails at node-gyp rebuild

edit: the .log file https://gist.github.com/Nikersify/fad2d3d0c6296a65b8c6

Try this:

  • Download and unpack zip.
  • Run npm install.
  • Run node-gyp rebuild.
  • Place entire contents in node_modules/robotjs.

Then try using the library.

I looked at your log and I honestly I'm not sure what's going on there.

commented

@octalmage fails at npm install again https://gist.github.com/Nikersify/6217e6c2220daff046e0
ps: thanks for the help! really looking forward to this package!

commented

@octalmage also some stuff after running node-gyp rebuild directly https://gist.github.com/Nikersify/b149bcfa49c8a878487e - sorry for throwing so many long .log files at you by the way, I'm quite new to node :p

No worries, I super appreciate the help testing!

Unfortunately I don't know what the issue is. Since this has worked for me and a few others my first idea is the environment? Could be the node.js version, or maybe the python version? I'm not even sure which line is the error.

I'm currently away from my computer, could another Windows user take a look?

@nikersify after looking at your logs some more it looks like you are building the RobotJS version hosted on GitHub? A lot of those errors have been fixed in my Windows zip posted above.

commented

@octalmage yea I was building it from the windows branch, now that I've switched it fails aswell unfortunately. I've tried a lot of different things to make it work aswell - no luck so far. I'll keep poking it and let you know if I figure something out.

Sorry got octalmage branch, ran node-gyp configure, works, but build has the issues pointed out earlier: (I am building with VS12 on Windows 8)
(https://cloud.githubusercontent.com/assets/3604869/8829636/a5f49a60-308f-11e5-85f1-43065561863a.png)

Just published the windows-2 branch, which includes a bunch of bug fixes:

https://github.com/octalmage/robotjs/tree/windows-2

Currently only getPixelColor might be broken, it returns 000000 in my VM. I'm not sure if it's really broken, so if someone could test and confirm that would be cool.

The getPixelColor is broken. Im only getting #000000. The script mentioned above (mouseclick) works good.

@Deltatiger thanks a ton for confirming! I'll dig into getPixelColor when I have time. After that we're pretty much ready to merge!

@octalmage Np. I will also look into it and see if I can fix it. I am pretty new to node.js (started yesterday) so let me give see what I can do.

@Deltatiger Awesome have at it! Just a heads up, RobotJS is actually written in C/C++.

If I had to guess, id say the issue is the snprintf call in src/robotjs.cc. I don't trust the portable version of that function.

I also wrote this code the other day just in case we needed to replace that snprintf call:

https://gist.github.com/octalmage/2b873e2b50695cda56d8

Seems I may have found the problem. The BitBlt function in the screengrab.c seems to have the arguments mixed up.

BOOL BitBlt(
  _In_  HDC   hdcDest,
  _In_  int   nXDest,
  _In_  int   nYDest,
  _In_  int   nWidth,
  _In_  int   nHeight,
  _In_  HDC   hdcSrc,
  _In_  int   nXSrc,
  _In_  int   nYSrc,
  _In_  DWORD dwRop
);

The code now is

BitBlt(screenMem, 
                (int)rect.origin.x, 
                (int)rect.origin.y, 
                (int)rect.size.width,
                (int)rect.size.height, screen, 0, 0, SRCCOPY)

The code should be

BitBlt(screenMem, 
                (int)0, 
                (int)0, 
                (int)rect.size.width,
                (int)rect.size.height, screen, rect.origin.x, rect.origin.y, SRCCOPY)

I cant test right now. But I can check it out in around 10 Hours from now.

Yup that fixed the issue. getPixelColor is now working.

Thanks to pr #43 from @Deltatiger and 8730e94 we now have full Windows support. I'll get ready to merge into the master branch.

If anyone wants to test the windows-2 branch before I merge, that would be cool!

We did it!

Thanks to everyone who helped!

RobotJS v0.2.0 has been published to npm with Windows support.

Awesome work @octalmage!

commented

The link for the Windows build, at the top of this page, goes to a 404.

Sorry that branch was merged. Just install from npm!

You rocks, thanks guys!

still get error when install npm install --save robotjs

image

commented

@achenwei-chwy its exactly what is says.. you don't have ANY python in your PATH
As far as I can recall node-gyp required python2