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

Windows Support. #2

Closed
scottmas opened this issue Nov 26, 2014 · 61 comments
Closed

Windows Support. #2

scottmas opened this issue Nov 26, 2014 · 61 comments
Assignees
Milestone

Comments

@scottmas
Copy link

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 getPixelColor bug fix. #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?

@scottmas
Copy link
Author

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.

@scottmas scottmas changed the title Get's stuck building on window Package doesn't build Dec 1, 2014
@octalmage octalmage self-assigned this Dec 3, 2014
@octalmage
Copy link
Owner

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!

@scottmas
Copy link
Author

scottmas commented Dec 4, 2014

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 :(

@octalmage
Copy link
Owner

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

@octalmage octalmage modified the milestone: First Stable Release. Jan 29, 2015
@octalmage octalmage changed the title Package doesn't build Package doesn't build on Windows. Feb 4, 2015
@octalmage
Copy link
Owner

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!

@octalmage
Copy link
Owner

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

@anand-io
Copy link

anand-io commented Feb 6, 2015

@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'

@octalmage
Copy link
Owner

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.

@syzer
Copy link

syzer commented Mar 30, 2015

+1

@octalmage
Copy link
Owner

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!

@syzer
Copy link

syzer commented May 20, 2015

+1

@octalmage
Copy link
Owner

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

@jack-guy
Copy link

+1

@octalmage
Copy link
Owner

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

@octalmage
Copy link
Owner

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.

@octalmage
Copy link
Owner

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]

@octalmage
Copy link
Owner

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!

@JCMais
Copy link

JCMais commented Jun 12, 2015

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.

@octalmage
Copy link
Owner

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

@jczimm
Copy link

jczimm commented Jul 17, 2015

+1

@octalmage octalmage changed the title Package doesn't build on Windows. Windows Support. Jul 18, 2015
@cataquil
Copy link

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)

@octalmage
Copy link
Owner

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.

@Deltatiger
Copy link
Collaborator

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

@octalmage
Copy link
Owner

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

@Deltatiger
Copy link
Collaborator

@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.

@octalmage
Copy link
Owner

@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.

@octalmage
Copy link
Owner

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

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

@Deltatiger
Copy link
Collaborator

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.

@Deltatiger
Copy link
Collaborator

Yup that fixed the issue. getPixelColor is now working.

@octalmage
Copy link
Owner

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!

@octalmage
Copy link
Owner

We did it!

Thanks to everyone who helped!

@octalmage
Copy link
Owner

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

@JCMais
Copy link

JCMais commented Jul 27, 2015

Awesome work @octalmage!

@magicdawn
Copy link

@cparker4486
Copy link

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

@octalmage
Copy link
Owner

Sorry that branch was merged. Just install from npm!

@Venryx Venryx mentioned this issue Jul 28, 2016
@roccomuso
Copy link

You rocks, thanks guys!

octalmage pushed a commit that referenced this issue Jan 24, 2019
@adamchenwei
Copy link

still get error when install npm install --save robotjs

image

@syzer
Copy link

syzer commented Apr 28, 2020

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests