├── .gitignore ├── .gitmodules ├── .editorconfig ├── LICENSE ├── lib ├── clipboard.js ├── keyboard.js ├── process.js ├── image.js ├── mouse.js ├── window.js ├── size.js ├── point.js ├── color.js ├── range.js ├── screen.js ├── hash.js ├── timer.js ├── module.js └── robot.js ├── package.json ├── src ├── NodeScreen.h ├── NodeKeyboard.h ├── NodeClipboard.h ├── NodeMouse.h ├── NodeRobot.rc ├── NodeImage.h ├── NodeMemory.h ├── NodeProcess.h ├── NodeWindow.h ├── NodeScreen.cc ├── NodeClipboard.cc ├── NodeKeyboard.cc ├── NodeMouse.cc ├── NodeImage.cc ├── NodeCommon.h ├── NodeRobot.cc └── NodeProcess.cc ├── scripts ├── getabi.js └── install.js ├── README.md ├── binding.gyp └── test ├── test.js ├── mouse.js ├── timer.js └── process.js /.gitignore: -------------------------------------------------------------------------------- 1 | *.node 2 | *.pdb 3 | build/ 4 | node_modules/ 5 | .DS_STORE 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/robot"] 2 | path = src/robot 3 | url = https://github.com/robot/robot 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome 2 | # http://EditorConfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | indent_style = tab 8 | indent_size = 4 9 | end_of_line = crlf 10 | trim_trailing_whitespace = true 11 | insert_final_newline = true 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2010-2018 Robot Developers 2 | 3 | This software is provided 'as-is', without any express or implied 4 | warranty. In no event will the authors be held liable for any damages 5 | arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any purpose, 8 | including commercial applications, and to alter it and redistribute it 9 | freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you must not 12 | claim that you wrote the original software. If you use this software 13 | in a product, an acknowledgment in the product documentation would be 14 | appreciated but is not required. 15 | 2. Altered source versions must be plainly marked as such, and must not be 16 | misrepresented as being the original software. 17 | 3. This notice may not be removed or altered from any source distribution. 18 | -------------------------------------------------------------------------------- /lib/clipboard.js: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | "use strict"; 11 | 12 | //----------------------------------------------------------------------------// 13 | // Exports // 14 | //----------------------------------------------------------------------------// 15 | 16 | module.exports = function (robot, native) { return native.Clipboard; }; 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "robot-js", 3 | "version" : "2.0.0", 4 | "robot" : "2.0.0", 5 | "license" : "Zlib", 6 | "main" : "lib/robot.js", 7 | "gypfile" : true, 8 | 9 | "description" : "Native system automation for node.js", 10 | "homepage" : "http://getrobot.net", 11 | 12 | "author": 13 | { 14 | "name" : "David Krutsko", 15 | "email" : "dave@krutsko.net", 16 | "url" : "http://krutsko.net" 17 | }, 18 | 19 | "repository": 20 | { 21 | "type" : "git", 22 | "url" : "https://github.com/robot/robot-js.git" 23 | }, 24 | 25 | "bugs": 26 | { 27 | "url" : "https://github.com/robot/robot-js/issues" 28 | }, 29 | 30 | "scripts": 31 | { 32 | "install" : "node scripts/install.js || node-gyp rebuild", 33 | "test" : "node test/test.js types timer" 34 | }, 35 | 36 | "config": 37 | { 38 | "verify" : true 39 | }, 40 | 41 | "engines": 42 | { 43 | "node" : "0.12 - 9" 44 | }, 45 | 46 | "os": 47 | [ 48 | "linux", 49 | "darwin", 50 | "win32" 51 | ], 52 | 53 | "cpu": 54 | [ 55 | "arm", 56 | "x64", 57 | "ia32" 58 | ], 59 | 60 | "keywords": 61 | [ 62 | "autoit", 63 | "native", 64 | "system", 65 | "automation", 66 | "hash", 67 | "keyboard", 68 | "mouse", 69 | "process", 70 | "memory", 71 | "window", 72 | "screen", 73 | "monitor", 74 | "display", 75 | "timer", 76 | "clock", 77 | "clipboard", 78 | "keylogging" 79 | ], 80 | 81 | "dependencies": 82 | { 83 | "colors" : "~1.1", 84 | "node-gyp" : "~3.6" 85 | }, 86 | 87 | "devDependencies": 88 | { 89 | "sprintf-js" : "~1.1", 90 | "node-png" : "~0.4", 91 | "readline-sync" : "~1.4" 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/NodeScreen.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | //----------------------------------------------------------------------------// 11 | // Prefaces // 12 | //----------------------------------------------------------------------------// 13 | 14 | #pragma once 15 | #include "NodeCommon.h" 16 | 17 | 18 | 19 | //----------------------------------------------------------------------------// 20 | // Classes // 21 | //----------------------------------------------------------------------------// 22 | 23 | //////////////////////////////////////////////////////////////////////////////// 24 | 25 | class ScreenWrap : public ObjectWrap 26 | { 27 | private: 28 | static void Synchronize (const FunctionCallbackInfo& args); 29 | static void GrabScreen (const FunctionCallbackInfo& args); 30 | 31 | static void IsCompositing (const FunctionCallbackInfo& args); 32 | static void SetCompositing (const FunctionCallbackInfo& args); 33 | 34 | public: 35 | static void Initialize (Handle exports); 36 | }; 37 | -------------------------------------------------------------------------------- /src/NodeKeyboard.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | //----------------------------------------------------------------------------// 11 | // Prefaces // 12 | //----------------------------------------------------------------------------// 13 | 14 | #pragma once 15 | #include "NodeCommon.h" 16 | 17 | 18 | 19 | //----------------------------------------------------------------------------// 20 | // Classes // 21 | //----------------------------------------------------------------------------// 22 | 23 | //////////////////////////////////////////////////////////////////////////////// 24 | 25 | class KeyboardWrap : public ObjectWrap 26 | { 27 | DECLARE_ROBOT_TYPE (Keyboard); 28 | 29 | private: 30 | static void Click (const FunctionCallbackInfo& args); 31 | static void Press (const FunctionCallbackInfo& args); 32 | static void Release (const FunctionCallbackInfo& args); 33 | 34 | static void Compile (const FunctionCallbackInfo& args); 35 | static void GetState (const FunctionCallbackInfo& args); 36 | 37 | static void New (const FunctionCallbackInfo& args); 38 | 39 | public: 40 | static void Initialize (Handle exports); 41 | 42 | public: 43 | Keyboard mKeyboard; 44 | }; 45 | -------------------------------------------------------------------------------- /src/NodeClipboard.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | //----------------------------------------------------------------------------// 11 | // Prefaces // 12 | //----------------------------------------------------------------------------// 13 | 14 | #pragma once 15 | #include "NodeCommon.h" 16 | 17 | 18 | 19 | //----------------------------------------------------------------------------// 20 | // Classes // 21 | //----------------------------------------------------------------------------// 22 | 23 | //////////////////////////////////////////////////////////////////////////////// 24 | 25 | class ClipboardWrap : public ObjectWrap 26 | { 27 | private: 28 | static void Clear (const FunctionCallbackInfo& args); 29 | 30 | static void HasText (const FunctionCallbackInfo& args); 31 | static void GetText (const FunctionCallbackInfo& args); 32 | static void SetText (const FunctionCallbackInfo& args); 33 | 34 | static void HasImage (const FunctionCallbackInfo& args); 35 | static void GetImage (const FunctionCallbackInfo& args); 36 | static void SetImage (const FunctionCallbackInfo& args); 37 | 38 | static void GetSequence (const FunctionCallbackInfo& args); 39 | 40 | public: 41 | static void Initialize (Handle exports); 42 | }; 43 | -------------------------------------------------------------------------------- /src/NodeMouse.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | //----------------------------------------------------------------------------// 11 | // Prefaces // 12 | //----------------------------------------------------------------------------// 13 | 14 | #pragma once 15 | #include "NodeCommon.h" 16 | 17 | 18 | 19 | //----------------------------------------------------------------------------// 20 | // Classes // 21 | //----------------------------------------------------------------------------// 22 | 23 | //////////////////////////////////////////////////////////////////////////////// 24 | 25 | class MouseWrap : public ObjectWrap 26 | { 27 | DECLARE_ROBOT_TYPE (Mouse); 28 | 29 | private: 30 | static void Click (const FunctionCallbackInfo& args); 31 | static void Press (const FunctionCallbackInfo& args); 32 | static void Release (const FunctionCallbackInfo& args); 33 | static void ScrollH (const FunctionCallbackInfo& args); 34 | static void ScrollV (const FunctionCallbackInfo& args); 35 | 36 | static void GetPos (const FunctionCallbackInfo& args); 37 | static void SetPos (const FunctionCallbackInfo& args); 38 | static void GetState (const FunctionCallbackInfo& args); 39 | 40 | static void New (const FunctionCallbackInfo& args); 41 | 42 | public: 43 | static void Initialize (Handle exports); 44 | 45 | public: 46 | Mouse mMouse; 47 | }; 48 | -------------------------------------------------------------------------------- /scripts/getabi.js: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | "use strict"; 11 | 12 | //----------------------------------------------------------------------------// 13 | // Requires // 14 | //----------------------------------------------------------------------------// 15 | 16 | var mFS = require ("fs" ); 17 | var mPath = require ("path"); 18 | 19 | 20 | 21 | //----------------------------------------------------------------------------// 22 | // Main // 23 | //----------------------------------------------------------------------------// 24 | 25 | //////////////////////////////////////////////////////////////////////////////// 26 | /// Discovers the Node ABI version by peeking into the node_version header file 27 | /// Expects the header include path as an argument and works with Node and IOjs 28 | 29 | var paths = 30 | [ 31 | mPath.join (process.argv[2], "include", "node", "node_version.h"), 32 | mPath.join (process.argv[2], "src", "node_version.h") 33 | ]; 34 | 35 | var contents = null; 36 | // Iterate through all possible paths 37 | for (var i = 0; i < paths.length; ++i) 38 | { 39 | try 40 | { 41 | // Read the contents of the header file 42 | contents = mFS.readFileSync (paths[i]); 43 | break; 44 | 45 | } catch (e) { } 46 | } 47 | 48 | // Verify read 49 | if (!contents) 50 | { 51 | console.error ("Unable to find node_version.h"); 52 | process.exitCode = 1; 53 | } 54 | 55 | else 56 | { 57 | console.info (contents.toString().match 58 | (/\s+NODE_MODULE_VERSION\s+(\d+)/)[1]); 59 | } 60 | -------------------------------------------------------------------------------- /src/NodeRobot.rc: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | //----------------------------------------------------------------------------// 11 | // Prefaces // 12 | //----------------------------------------------------------------------------// 13 | 14 | #include 15 | #define STRINGIFY( s ) _STRINGIFY( s ) 16 | #define _STRINGIFY( s ) #s 17 | 18 | 19 | 20 | //----------------------------------------------------------------------------// 21 | // Version // 22 | //----------------------------------------------------------------------------// 23 | 24 | VS_VERSION_INFO VERSIONINFO 25 | 26 | PRODUCTVERSION 2, 0, 0, TARGET_MODULE_VERSION 27 | FILEVERSION 2, 0, 0, TARGET_MODULE_VERSION 28 | 29 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 30 | #ifdef DEBUG 31 | FILEFLAGS VS_FF_DEBUG 32 | #else 33 | FILEFLAGS 0 34 | #endif 35 | 36 | FILEOS VOS_NT_WINDOWS32 37 | FILETYPE VFT_STATIC_LIB 38 | 39 | BEGIN 40 | BLOCK "StringFileInfo" 41 | BEGIN 42 | BLOCK "000004B0" 43 | BEGIN 44 | 45 | VALUE "ProductName", "robot-js" 46 | VALUE "FileDescription", "robot-js" 47 | 48 | VALUE "ProductVersion", "2.0.0." STRINGIFY (TARGET_MODULE_VERSION) 49 | VALUE "FileVersion", "2.0.0." STRINGIFY (TARGET_MODULE_VERSION) 50 | VALUE "RobotVersion", "2.0.0." "0" 51 | 52 | VALUE "CompanyName", "Robot Developers" 53 | VALUE "OriginalFilename", STRINGIFY (NODE_GYP_MODULE_NAME) ".node" 54 | 55 | END 56 | END 57 | 58 | BLOCK "VarFileInfo" 59 | BEGIN 60 | VALUE "Translation", 0x0000, 0x04B0 61 | END 62 | END 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | ROBOT 4 | 5 |

6 | 7 |

Native System Automation for Node

8 | 9 |

10 | 11 | Built with Robot 12 | 13 | 14 | Robot 2.0.0 15 | 16 | 17 | NPM 2.0.0 18 | 19 | Node 0.12 - 9 20 | 21 | Docs API 22 | 23 | 24 | ZLIB License 25 | 26 |

27 | 28 |
29 | 30 | GET STARTED 31 | 32 |  |  33 | 34 | DOCUMENTATION 35 | 36 |  |  37 | 38 | API 39 | 40 |  |  41 | 42 | COMMUNITY 43 | 44 |
45 | 46 |

47 | Introducing Robot for Node, a library aimed at facilitating the development of system automation software for the purposes of test automation, self-running demos, and other applications. The library works by abstracting away all platform-specific differences into a single, robust API compatible with most desktop operating systems. Functionality ranges from basic keyboard and mouse automation to advanced process manipulation capabilities. It has everything you need to take full control of your system. Visit the Homepage for more information. 48 |

49 | 50 |
npm install robot-js
51 | -------------------------------------------------------------------------------- /src/NodeImage.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | //----------------------------------------------------------------------------// 11 | // Prefaces // 12 | //----------------------------------------------------------------------------// 13 | 14 | #pragma once 15 | #include "NodeCommon.h" 16 | 17 | 18 | 19 | //----------------------------------------------------------------------------// 20 | // Classes // 21 | //----------------------------------------------------------------------------// 22 | 23 | //////////////////////////////////////////////////////////////////////////////// 24 | 25 | class ImageWrap : public ObjectWrap 26 | { 27 | DECLARE_ROBOT_TYPE (Image); 28 | 29 | private: 30 | static void IsValid (const FunctionCallbackInfo& args); 31 | 32 | static void Create (const FunctionCallbackInfo& args); 33 | static void Destroy (const FunctionCallbackInfo& args); 34 | 35 | static void GetWidth (const FunctionCallbackInfo& args); 36 | static void GetHeight (const FunctionCallbackInfo& args); 37 | static void GetLength (const FunctionCallbackInfo& args); 38 | static void GetData (const FunctionCallbackInfo& args); 39 | static void GetLimit (const FunctionCallbackInfo& args); 40 | 41 | static void GetPixel (const FunctionCallbackInfo& args); 42 | static void SetPixel (const FunctionCallbackInfo& args); 43 | 44 | static void Fill (const FunctionCallbackInfo& args); 45 | static void Swap (const FunctionCallbackInfo& args); 46 | static void Flip (const FunctionCallbackInfo& args); 47 | static void Equals (const FunctionCallbackInfo& args); 48 | 49 | static void New (const FunctionCallbackInfo& args); 50 | 51 | public: 52 | static void Initialize (Handle exports); 53 | 54 | public: 55 | Image mImage; 56 | }; 57 | -------------------------------------------------------------------------------- /lib/keyboard.js: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | "use strict"; 11 | 12 | //----------------------------------------------------------------------------// 13 | // Exports // 14 | //----------------------------------------------------------------------------// 15 | 16 | module.exports = function (robot, native) 17 | { 18 | //----------------------------------------------------------------------------// 19 | // Functions Keyboard // 20 | //----------------------------------------------------------------------------// 21 | 22 | //////////////////////////////////////////////////////////////////////////////// 23 | 24 | native.Keyboard.prototype.click = function (keycode) 25 | { 26 | // AutoDelay should always be a range object 27 | if (!(this.autoDelay instanceof robot.Range)) 28 | throw new TypeError ("Invalid properties"); 29 | 30 | return this._click (keycode, 31 | this.autoDelay.min, 32 | this.autoDelay.max); 33 | }; 34 | 35 | //////////////////////////////////////////////////////////////////////////////// 36 | 37 | native.Keyboard.prototype.press = function (keycode) 38 | { 39 | // AutoDelay should always be a range object 40 | if (!(this.autoDelay instanceof robot.Range)) 41 | throw new TypeError ("Invalid properties"); 42 | 43 | this._press (keycode, 44 | this.autoDelay.min, 45 | this.autoDelay.max); 46 | }; 47 | 48 | //////////////////////////////////////////////////////////////////////////////// 49 | 50 | native.Keyboard.prototype.release = function (keycode) 51 | { 52 | // AutoDelay should always be a range object 53 | if (!(this.autoDelay instanceof robot.Range)) 54 | throw new TypeError ("Invalid properties"); 55 | 56 | this._release (keycode, 57 | this.autoDelay.min, 58 | this.autoDelay.max); 59 | }; 60 | 61 | //////////////////////////////////////////////////////////////////////////////// 62 | 63 | return native.Keyboard; 64 | }; 65 | -------------------------------------------------------------------------------- /lib/process.js: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | "use strict"; 11 | 12 | //----------------------------------------------------------------------------// 13 | // Exports // 14 | //----------------------------------------------------------------------------// 15 | 16 | module.exports = function (robot, native) 17 | { 18 | //----------------------------------------------------------------------------// 19 | // Static Process // 20 | //----------------------------------------------------------------------------// 21 | 22 | //////////////////////////////////////////////////////////////////////////////// 23 | 24 | native.Process.isSys64Bit = function() 25 | { 26 | // Perform native call only once 27 | if (this._isSys64 === undefined) 28 | this._isSys64 = this._isSys64Bit(); 29 | 30 | return this._isSys64; 31 | }; 32 | 33 | 34 | 35 | //----------------------------------------------------------------------------// 36 | // Operators Process // 37 | //----------------------------------------------------------------------------// 38 | 39 | //////////////////////////////////////////////////////////////////////////////// 40 | 41 | native.Process.prototype.eq = function (value) 42 | { 43 | // Check if arg is of valid type 44 | if (typeof value === "number" || 45 | value instanceof native.Process) 46 | return this._equals (value); 47 | 48 | throw new TypeError ("Invalid arguments"); 49 | }; 50 | 51 | //////////////////////////////////////////////////////////////////////////////// 52 | 53 | native.Process.prototype.ne = function (value) 54 | { 55 | // Check if arg is of valid type 56 | if (typeof value === "number" || 57 | value instanceof native.Process) 58 | return !this._equals (value); 59 | 60 | throw new TypeError ("Invalid arguments"); 61 | }; 62 | 63 | //////////////////////////////////////////////////////////////////////////////// 64 | 65 | return native.Process; 66 | }; 67 | -------------------------------------------------------------------------------- /src/NodeMemory.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | //----------------------------------------------------------------------------// 11 | // Prefaces // 12 | //----------------------------------------------------------------------------// 13 | 14 | #pragma once 15 | #include "NodeCommon.h" 16 | 17 | 18 | 19 | //----------------------------------------------------------------------------// 20 | // Classes // 21 | //----------------------------------------------------------------------------// 22 | 23 | //////////////////////////////////////////////////////////////////////////////// 24 | 25 | class MemoryWrap : public ObjectWrap 26 | { 27 | DECLARE_ROBOT_TYPE (Memory); 28 | 29 | private: 30 | static void IsValid (const FunctionCallbackInfo& args); 31 | static void GetProcess (const FunctionCallbackInfo& args); 32 | static void GetStats (const FunctionCallbackInfo& args); 33 | 34 | static void GetRegion (const FunctionCallbackInfo& args); 35 | static void GetRegions (const FunctionCallbackInfo& args); 36 | static void SetAccess (const FunctionCallbackInfo& args); 37 | 38 | static void Find (const FunctionCallbackInfo& args); 39 | 40 | static void CreateCache (const FunctionCallbackInfo& args); 41 | static void ClearCache (const FunctionCallbackInfo& args); 42 | static void DeleteCache (const FunctionCallbackInfo& args); 43 | static void IsCaching (const FunctionCallbackInfo& args); 44 | static void GetCacheSize (const FunctionCallbackInfo& args); 45 | 46 | static void ReadData (const FunctionCallbackInfo& args); 47 | static void WriteData (const FunctionCallbackInfo& args); 48 | static void ReadType (const FunctionCallbackInfo& args); 49 | static void WriteType (const FunctionCallbackInfo& args); 50 | 51 | static void New (const FunctionCallbackInfo& args); 52 | 53 | public: 54 | static void Initialize (Handle exports); 55 | 56 | public: 57 | Memory mMemory; 58 | }; 59 | -------------------------------------------------------------------------------- /src/NodeProcess.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | //----------------------------------------------------------------------------// 11 | // Prefaces // 12 | //----------------------------------------------------------------------------// 13 | 14 | #pragma once 15 | #include "NodeCommon.h" 16 | 17 | 18 | 19 | //----------------------------------------------------------------------------// 20 | // Classes // 21 | //----------------------------------------------------------------------------// 22 | 23 | //////////////////////////////////////////////////////////////////////////////// 24 | 25 | class ProcessWrap : public ObjectWrap 26 | { 27 | DECLARE_ROBOT_TYPE (Process); 28 | 29 | private: 30 | static void Open (const FunctionCallbackInfo& args); 31 | static void Close (const FunctionCallbackInfo& args); 32 | 33 | static void IsValid (const FunctionCallbackInfo& args); 34 | static void Is64Bit (const FunctionCallbackInfo& args); 35 | static void IsDebugged (const FunctionCallbackInfo& args); 36 | 37 | static void GetPID (const FunctionCallbackInfo& args); 38 | static void GetName (const FunctionCallbackInfo& args); 39 | static void GetPath (const FunctionCallbackInfo& args); 40 | 41 | static void Exit (const FunctionCallbackInfo& args); 42 | static void Kill (const FunctionCallbackInfo& args); 43 | static void HasExited (const FunctionCallbackInfo& args); 44 | 45 | static void GetModules (const FunctionCallbackInfo& args); 46 | static void GetWindows (const FunctionCallbackInfo& args); 47 | static void Equals (const FunctionCallbackInfo& args); 48 | 49 | static void GetList (const FunctionCallbackInfo& args); 50 | static void GetCurrent (const FunctionCallbackInfo& args); 51 | static void IsSys64Bit (const FunctionCallbackInfo& args); 52 | static void GetSegments (const FunctionCallbackInfo& args); 53 | 54 | static void New (const FunctionCallbackInfo& args); 55 | 56 | public: 57 | static void Initialize (Handle exports); 58 | 59 | public: 60 | Process mProcess; 61 | }; 62 | -------------------------------------------------------------------------------- /src/NodeWindow.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | //----------------------------------------------------------------------------// 11 | // Prefaces // 12 | //----------------------------------------------------------------------------// 13 | 14 | #pragma once 15 | #include "NodeCommon.h" 16 | 17 | 18 | 19 | //----------------------------------------------------------------------------// 20 | // Classes // 21 | //----------------------------------------------------------------------------// 22 | 23 | //////////////////////////////////////////////////////////////////////////////// 24 | 25 | class WindowWrap : public ObjectWrap 26 | { 27 | DECLARE_ROBOT_TYPE (Window); 28 | 29 | private: 30 | static void IsValid (const FunctionCallbackInfo& args); 31 | static void Close (const FunctionCallbackInfo& args); 32 | 33 | static void IsTopMost (const FunctionCallbackInfo& args); 34 | static void IsBorderless (const FunctionCallbackInfo& args); 35 | static void IsMinimized (const FunctionCallbackInfo& args); 36 | static void IsMaximized (const FunctionCallbackInfo& args); 37 | 38 | static void SetTopMost (const FunctionCallbackInfo& args); 39 | static void SetBorderless (const FunctionCallbackInfo& args); 40 | static void SetMinimized (const FunctionCallbackInfo& args); 41 | static void SetMaximized (const FunctionCallbackInfo& args); 42 | 43 | static void GetProcess (const FunctionCallbackInfo& args); 44 | static void GetPID (const FunctionCallbackInfo& args); 45 | static void GetHandle (const FunctionCallbackInfo& args); 46 | static void SetHandle (const FunctionCallbackInfo& args); 47 | 48 | static void GetTitle (const FunctionCallbackInfo& args); 49 | static void SetTitle (const FunctionCallbackInfo& args); 50 | 51 | static void GetBounds (const FunctionCallbackInfo& args); 52 | static void SetBounds (const FunctionCallbackInfo& args); 53 | static void GetClient (const FunctionCallbackInfo& args); 54 | static void SetClient (const FunctionCallbackInfo& args); 55 | static void MapToClient (const FunctionCallbackInfo& args); 56 | static void MapToScreen (const FunctionCallbackInfo& args); 57 | static void Equals (const FunctionCallbackInfo& args); 58 | 59 | static void GetList (const FunctionCallbackInfo& args); 60 | static void GetActive (const FunctionCallbackInfo& args); 61 | static void SetActive (const FunctionCallbackInfo& args); 62 | static void IsAxEnabled (const FunctionCallbackInfo& args); 63 | 64 | static void New (const FunctionCallbackInfo& args); 65 | 66 | public: 67 | static void Initialize (Handle exports); 68 | 69 | public: 70 | Window mWindow; 71 | }; 72 | -------------------------------------------------------------------------------- /lib/image.js: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | "use strict"; 11 | 12 | //----------------------------------------------------------------------------// 13 | // Exports // 14 | //----------------------------------------------------------------------------// 15 | 16 | module.exports = function (robot, native) 17 | { 18 | //----------------------------------------------------------------------------// 19 | // Functions Image // 20 | //----------------------------------------------------------------------------// 21 | 22 | //////////////////////////////////////////////////////////////////////////////// 23 | 24 | native.Image.prototype.create = function (aw, ah) 25 | { 26 | var s = robot 27 | .Size.normalize ( aw, ah); 28 | return this._create (s.w, s.h); 29 | }; 30 | 31 | //////////////////////////////////////////////////////////////////////////////// 32 | 33 | native.Image.prototype.getPixel = function (ax, ay) 34 | { 35 | var p = robot 36 | .Point.normalize ( ax, ay); 37 | return this._getPixel (p.x, p.y); 38 | }; 39 | 40 | //////////////////////////////////////////////////////////////////////////////// 41 | 42 | native.Image.prototype.setPixel = function (ax, ay, color) 43 | { 44 | var c = arguments[arguments.length - 1]; 45 | 46 | // Check if argument is a color 47 | if (!(c instanceof robot.Color)) 48 | throw new TypeError ("Invalid arguments"); 49 | 50 | var p = robot.Point.normalize (ax, ay); 51 | this._setPixel (p.x, p.y, c.r, c.g, c.b, c.a); 52 | }; 53 | 54 | //////////////////////////////////////////////////////////////////////////////// 55 | 56 | native.Image.prototype.fill = function (ar, ag, ab, aa) 57 | { 58 | var c = robot. 59 | Color.normalize ( ar, ag, ab, aa); 60 | return this._fill (c.r, c.g, c.b, c.a); 61 | }; 62 | 63 | 64 | 65 | //----------------------------------------------------------------------------// 66 | // Operators Image // 67 | //----------------------------------------------------------------------------// 68 | 69 | //////////////////////////////////////////////////////////////////////////////// 70 | 71 | native.Image.prototype.eq = function (image) 72 | { 73 | // Check if image is a native image 74 | if (!(image instanceof native.Image)) 75 | throw new TypeError ("Invalid arguments"); 76 | 77 | return this._equals (image); 78 | }; 79 | 80 | //////////////////////////////////////////////////////////////////////////////// 81 | 82 | native.Image.prototype.ne = function (image) 83 | { 84 | // Check if image is a native image 85 | if (!(image instanceof native.Image)) 86 | throw new TypeError ("Invalid arguments"); 87 | 88 | return !this._equals (image); 89 | }; 90 | 91 | //////////////////////////////////////////////////////////////////////////////// 92 | 93 | return native.Image; 94 | }; 95 | -------------------------------------------------------------------------------- /lib/mouse.js: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | "use strict"; 11 | 12 | //----------------------------------------------------------------------------// 13 | // Exports // 14 | //----------------------------------------------------------------------------// 15 | 16 | module.exports = function (robot, native) 17 | { 18 | //----------------------------------------------------------------------------// 19 | // Functions Mouse // 20 | //----------------------------------------------------------------------------// 21 | 22 | //////////////////////////////////////////////////////////////////////////////// 23 | 24 | native.Mouse.prototype.click = function (button) 25 | { 26 | // AutoDelay should always be a range object 27 | if (!(this.autoDelay instanceof robot.Range)) 28 | throw new TypeError ("Invalid properties"); 29 | 30 | this._click (button, 31 | this.autoDelay.min, 32 | this.autoDelay.max); 33 | }; 34 | 35 | //////////////////////////////////////////////////////////////////////////////// 36 | 37 | native.Mouse.prototype.press = function (button) 38 | { 39 | // AutoDelay should always be a range object 40 | if (!(this.autoDelay instanceof robot.Range)) 41 | throw new TypeError ("Invalid properties"); 42 | 43 | this._press (button, 44 | this.autoDelay.min, 45 | this.autoDelay.max); 46 | }; 47 | 48 | //////////////////////////////////////////////////////////////////////////////// 49 | 50 | native.Mouse.prototype.release = function (button) 51 | { 52 | // AutoDelay should always be a range object 53 | if (!(this.autoDelay instanceof robot.Range)) 54 | throw new TypeError ("Invalid properties"); 55 | 56 | this._release (button, 57 | this.autoDelay.min, 58 | this.autoDelay.max); 59 | }; 60 | 61 | //////////////////////////////////////////////////////////////////////////////// 62 | 63 | native.Mouse.prototype.scrollH = function (amount) 64 | { 65 | // AutoDelay should always be a range object 66 | if (!(this.autoDelay instanceof robot.Range)) 67 | throw new TypeError ("Invalid properties"); 68 | 69 | this._scrollH (amount, 70 | this.autoDelay.min, 71 | this.autoDelay.max); 72 | }; 73 | 74 | //////////////////////////////////////////////////////////////////////////////// 75 | 76 | native.Mouse.prototype.scrollV = function (amount) 77 | { 78 | // AutoDelay should always be a range object 79 | if (!(this.autoDelay instanceof robot.Range)) 80 | throw new TypeError ("Invalid properties"); 81 | 82 | this._scrollV (amount, 83 | this.autoDelay.min, 84 | this.autoDelay.max); 85 | }; 86 | 87 | 88 | 89 | //----------------------------------------------------------------------------// 90 | // Static Mouse // 91 | //----------------------------------------------------------------------------// 92 | 93 | //////////////////////////////////////////////////////////////////////////////// 94 | 95 | native.Mouse.setPos = function (ax, ay) 96 | { 97 | var p = robot.Point. 98 | normalize( ax, ay); 99 | this._setPos (p.x, p.y); 100 | }; 101 | 102 | //////////////////////////////////////////////////////////////////////////////// 103 | 104 | return native.Mouse; 105 | }; 106 | -------------------------------------------------------------------------------- /lib/window.js: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | "use strict"; 11 | 12 | //----------------------------------------------------------------------------// 13 | // Exports // 14 | //----------------------------------------------------------------------------// 15 | 16 | module.exports = function (robot, native) 17 | { 18 | //----------------------------------------------------------------------------// 19 | // Functions Window // 20 | //----------------------------------------------------------------------------// 21 | 22 | //////////////////////////////////////////////////////////////////////////////// 23 | 24 | native.Window.prototype.setBounds = function (ax, ay, aw, ah) 25 | { 26 | var b = robot.Bounds 27 | .normalize ( ax, ay, aw, ah); 28 | this._setBounds (b.x, b.y, b.w, b.h); 29 | }; 30 | 31 | //////////////////////////////////////////////////////////////////////////////// 32 | 33 | native.Window.prototype.setClient = function (ax, ay, aw, ah) 34 | { 35 | var b = robot.Bounds 36 | .normalize ( ax, ay, aw, ah); 37 | this._setClient (b.x, b.y, b.w, b.h); 38 | }; 39 | 40 | //////////////////////////////////////////////////////////////////////////////// 41 | 42 | native.Window.prototype.mapToClient = function (ax, ay) 43 | { 44 | var p = 45 | robot.Point.normalize( ax, ay); 46 | return this._mapToClient (p.x, p.y); 47 | }; 48 | 49 | //////////////////////////////////////////////////////////////////////////////// 50 | 51 | native.Window.prototype.mapToScreen = function (ax, ay) 52 | { 53 | var p = 54 | robot.Point.normalize( ax, ay); 55 | return this._mapToScreen (p.x, p.y); 56 | }; 57 | 58 | 59 | 60 | //----------------------------------------------------------------------------// 61 | // Static Window // 62 | //----------------------------------------------------------------------------// 63 | 64 | //////////////////////////////////////////////////////////////////////////////// 65 | 66 | native.Window.setActive = function (window) 67 | { 68 | // Check if window is a native window 69 | if (!(window instanceof native.Window)) 70 | throw new TypeError ("Invalid arguments"); 71 | 72 | this._setActive (window); 73 | }; 74 | 75 | 76 | 77 | //----------------------------------------------------------------------------// 78 | // Operators Window // 79 | //----------------------------------------------------------------------------// 80 | 81 | //////////////////////////////////////////////////////////////////////////////// 82 | 83 | native.Window.prototype.eq = function (value) 84 | { 85 | // Check if arg is of valid type 86 | if (typeof value === "number" || 87 | value instanceof native.Window) 88 | return this._equals (value); 89 | 90 | throw new TypeError ("Invalid arguments"); 91 | }; 92 | 93 | //////////////////////////////////////////////////////////////////////////////// 94 | 95 | native.Window.prototype.ne = function (value) 96 | { 97 | // Check if arg is of valid type 98 | if (typeof value === "number" || 99 | value instanceof native.Window) 100 | return !this._equals (value); 101 | 102 | throw new TypeError ("Invalid arguments"); 103 | }; 104 | 105 | //////////////////////////////////////////////////////////////////////////////// 106 | 107 | return native.Window; 108 | }; 109 | -------------------------------------------------------------------------------- /src/NodeScreen.cc: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | //----------------------------------------------------------------------------// 11 | // Prefaces // 12 | //----------------------------------------------------------------------------// 13 | 14 | #include "NodeScreen.h" 15 | #include "NodeWindow.h" 16 | #include "NodeImage.h" 17 | 18 | extern Persistent JsBounds; 19 | 20 | 21 | 22 | //----------------------------------------------------------------------------// 23 | // Functions ScreenWrap // 24 | //----------------------------------------------------------------------------// 25 | 26 | //////////////////////////////////////////////////////////////////////////////// 27 | 28 | void ScreenWrap::Synchronize (const FunctionCallbackInfo& args) 29 | { 30 | ISOLATE; 31 | // Synchronize screens 32 | auto status = NEW_BOOL 33 | (Screen::Synchronize()); 34 | 35 | // Retrieve a list of screens 36 | auto list = Screen::GetList(); 37 | 38 | int length = (int) list.size(); 39 | auto screens = NEW_ARR (length); 40 | // Loop array and add to result 41 | for (int i = 0; i < length; ++i) 42 | { 43 | auto obj = NEW_OBJ; 44 | Bounds b = list[i]->GetBounds(); 45 | Bounds u = list[i]->GetUsable(); 46 | obj->Set (NEW_STR ("bounds"), NEW_BOUNDS (b.X, b.Y, b.W, b.H)); 47 | obj->Set (NEW_STR ("usable"), NEW_BOUNDS (u.X, u.Y, u.W, u.H)); 48 | screens->Set (i, obj); 49 | } 50 | 51 | auto res = NEW_OBJ; 52 | Bounds b = Screen::GetTotalBounds(); 53 | Bounds u = Screen::GetTotalUsable(); 54 | res->Set (NEW_STR ("screens"), screens); 55 | res->Set (NEW_STR ("status" ), status ); 56 | res->Set (NEW_STR ("totalBounds"), NEW_BOUNDS (b.X, b.Y, b.W, b.H)); 57 | res->Set (NEW_STR ("totalUsable"), NEW_BOUNDS (u.X, u.Y, u.W, u.H)); 58 | RETURN (res); 59 | } 60 | 61 | //////////////////////////////////////////////////////////////////////////////// 62 | 63 | void ScreenWrap::GrabScreen (const FunctionCallbackInfo& args) 64 | { 65 | ISOLATE; 66 | auto img = UnwrapRobot< ImageWrap> (args[0]); 67 | auto win = UnwrapRobot (args[5]); 68 | 69 | RETURN_BOOL (Screen::GrabScreen (img->mImage, 70 | args[1]->Int32Value(), args[2]->Int32Value(), 71 | args[3]->Int32Value(), args[4]->Int32Value(), 72 | win ? win->mWindow : Window())); 73 | } 74 | 75 | //////////////////////////////////////////////////////////////////////////////// 76 | 77 | void ScreenWrap::IsCompositing (const FunctionCallbackInfo& args) 78 | { 79 | ISOLATE; 80 | RETURN_BOOL (Screen::IsCompositing()); 81 | } 82 | 83 | //////////////////////////////////////////////////////////////////////////////// 84 | 85 | void ScreenWrap::SetCompositing (const FunctionCallbackInfo& args) 86 | { 87 | ISOLATE; 88 | // Check for valid args 89 | if (!args[0]->IsBoolean()) 90 | THROW (Type, "Invalid arguments"); 91 | 92 | bool ec = 93 | args[0]->BooleanValue(); 94 | Screen::SetCompositing (ec); 95 | } 96 | 97 | //////////////////////////////////////////////////////////////////////////////// 98 | 99 | void ScreenWrap::Initialize (Handle exports) 100 | { 101 | // Get the current isolated V8 instance 102 | Isolate* isolate = Isolate::GetCurrent(); 103 | 104 | // Create the resulting object 105 | Local result = NEW_OBJ; 106 | 107 | NODE_SET_METHOD (result, "synchronize", Synchronize ); 108 | NODE_SET_METHOD (result, "grabScreen", GrabScreen ); 109 | 110 | NODE_SET_METHOD (result, "isCompositing", IsCompositing); 111 | NODE_SET_METHOD (result, "setCompositing", SetCompositing); 112 | 113 | // Export screen functions inside object 114 | exports->Set (NEW_STR ("Screen"), result); 115 | } 116 | -------------------------------------------------------------------------------- /src/NodeClipboard.cc: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | //----------------------------------------------------------------------------// 11 | // Prefaces // 12 | //----------------------------------------------------------------------------// 13 | 14 | #include "NodeClipboard.h" 15 | #include "NodeImage.h" 16 | 17 | 18 | 19 | //----------------------------------------------------------------------------// 20 | // Functions ClipboardWrap // 21 | //----------------------------------------------------------------------------// 22 | 23 | //////////////////////////////////////////////////////////////////////////////// 24 | 25 | void ClipboardWrap::Clear (const FunctionCallbackInfo& args) 26 | { 27 | ISOLATE; 28 | RETURN_BOOL (Clipboard::Clear()); 29 | } 30 | 31 | //////////////////////////////////////////////////////////////////////////////// 32 | 33 | void ClipboardWrap::HasText (const FunctionCallbackInfo& args) 34 | { 35 | ISOLATE; 36 | RETURN_BOOL (Clipboard::HasText()); 37 | } 38 | 39 | //////////////////////////////////////////////////////////////////////////////// 40 | 41 | void ClipboardWrap::GetText (const FunctionCallbackInfo& args) 42 | { 43 | ISOLATE; 44 | RETURN_STR (Clipboard::GetText().data()); 45 | } 46 | 47 | //////////////////////////////////////////////////////////////////////////////// 48 | 49 | void ClipboardWrap::SetText (const FunctionCallbackInfo& args) 50 | { 51 | ISOLATE; 52 | // Check for valid args 53 | if (!args[0]->IsString()) 54 | THROW (Type, "Invalid arguments"); 55 | 56 | String::Utf8Value value (args[0]); 57 | auto text = *value ? *value : ""; 58 | RETURN_BOOL (Clipboard::SetText (text)); 59 | } 60 | 61 | //////////////////////////////////////////////////////////////////////////////// 62 | 63 | void ClipboardWrap::HasImage (const FunctionCallbackInfo& args) 64 | { 65 | ISOLATE; 66 | RETURN_BOOL (Clipboard::HasImage()); 67 | } 68 | 69 | //////////////////////////////////////////////////////////////////////////////// 70 | 71 | void ClipboardWrap::GetImage (const FunctionCallbackInfo& args) 72 | { 73 | ISOLATE; 74 | // Attempt to unwrap into native image type 75 | auto wrap = UnwrapRobot (args[0]); 76 | if (!wrap) THROW (Type, "Invalid arguments"); 77 | 78 | RETURN_BOOL (Clipboard::GetImage (wrap->mImage)); 79 | } 80 | 81 | //////////////////////////////////////////////////////////////////////////////// 82 | 83 | void ClipboardWrap::SetImage (const FunctionCallbackInfo& args) 84 | { 85 | ISOLATE; 86 | // Attempt to unwrap into native image type 87 | auto wrap = UnwrapRobot (args[0]); 88 | if (!wrap) THROW (Type, "Invalid arguments"); 89 | 90 | RETURN_BOOL (Clipboard::SetImage (wrap->mImage)); 91 | } 92 | 93 | //////////////////////////////////////////////////////////////////////////////// 94 | 95 | void ClipboardWrap::GetSequence (const FunctionCallbackInfo& args) 96 | { 97 | ISOLATE; 98 | RETURN_NUM ((double) Clipboard::GetSequence()); 99 | } 100 | 101 | //////////////////////////////////////////////////////////////////////////////// 102 | 103 | void ClipboardWrap::Initialize (Handle exports) 104 | { 105 | // Get the current isolated V8 instance 106 | Isolate* isolate = Isolate::GetCurrent(); 107 | 108 | // Create the resulting object 109 | Local result = NEW_OBJ; 110 | 111 | NODE_SET_METHOD (result, "clear", Clear ); 112 | 113 | NODE_SET_METHOD (result, "hasText", HasText ); 114 | NODE_SET_METHOD (result, "getText", GetText ); 115 | NODE_SET_METHOD (result, "setText", SetText ); 116 | 117 | NODE_SET_METHOD (result, "hasImage", HasImage ); 118 | NODE_SET_METHOD (result, "getImage", GetImage ); 119 | NODE_SET_METHOD (result, "setImage", SetImage ); 120 | 121 | NODE_SET_METHOD (result, "getSequence", GetSequence); 122 | 123 | // Export clipboard functions inside object 124 | exports->Set (NEW_STR ("Clipboard"), result); 125 | } 126 | -------------------------------------------------------------------------------- /lib/size.js: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | "use strict"; 11 | 12 | //----------------------------------------------------------------------------// 13 | // Exports // 14 | //----------------------------------------------------------------------------// 15 | 16 | module.exports = function (robot) 17 | { 18 | //----------------------------------------------------------------------------// 19 | // Constructor Size // 20 | //----------------------------------------------------------------------------// 21 | 22 | //////////////////////////////////////////////////////////////////////////////// 23 | 24 | function Size (aw, ah) 25 | { 26 | // Auto instantiate the Size 27 | if (!(this instanceof Size)) 28 | return new Size (aw, ah); 29 | 30 | var s = Size.normalize (aw, ah); 31 | this.w = s.w; 32 | this.h = s.h; 33 | } 34 | 35 | 36 | 37 | //----------------------------------------------------------------------------// 38 | // Functions Size // 39 | //----------------------------------------------------------------------------// 40 | 41 | //////////////////////////////////////////////////////////////////////////////// 42 | 43 | Size.prototype.isZero = function() 44 | { 45 | return this.w === 0 46 | && this.h === 0; 47 | }; 48 | 49 | //////////////////////////////////////////////////////////////////////////////// 50 | 51 | Size.prototype.isEmpty = function() 52 | { 53 | return this.w === 0 54 | || this.h === 0; 55 | }; 56 | 57 | //////////////////////////////////////////////////////////////////////////////// 58 | 59 | Size.prototype.toPoint = function() 60 | { 61 | return robot.Point 62 | (this.w, this.h); 63 | }; 64 | 65 | 66 | 67 | //----------------------------------------------------------------------------// 68 | // Static Size // 69 | //----------------------------------------------------------------------------// 70 | 71 | //////////////////////////////////////////////////////////////////////////////// 72 | 73 | Size.normalize = function (aw, ah) 74 | { 75 | if (aw instanceof Size) 76 | return aw; 77 | 78 | if (aw === undefined) 79 | return { w: 0, h: 0 }; 80 | 81 | if (typeof aw === "object" && 82 | typeof aw.w === "number" && 83 | typeof aw.h === "number") 84 | return aw; 85 | 86 | if (typeof aw === "number") 87 | { 88 | if (typeof ah === "number") 89 | return { w: aw, h: ah }; 90 | return { w: aw, h: aw }; 91 | } 92 | 93 | throw new TypeError 94 | ("Invalid arguments"); 95 | }; 96 | 97 | 98 | 99 | //----------------------------------------------------------------------------// 100 | // Operators Size // 101 | //----------------------------------------------------------------------------// 102 | 103 | //////////////////////////////////////////////////////////////////////////////// 104 | 105 | Size.prototype.add = function (aw, ah) 106 | { 107 | var s = Size.normalize (aw, ah); 108 | return Size 109 | (this.w + s.w, this.h + s.h); 110 | }; 111 | 112 | //////////////////////////////////////////////////////////////////////////////// 113 | 114 | Size.prototype.sub = function (aw, ah) 115 | { 116 | var s = Size.normalize (aw, ah); 117 | return Size 118 | (this.w - s.w, this.h - s.h); 119 | }; 120 | 121 | //////////////////////////////////////////////////////////////////////////////// 122 | 123 | Size.prototype.eq = function (aw, ah) 124 | { 125 | var s = Size.normalize (aw, ah); 126 | return this.w === s.w 127 | && this.h === s.h; 128 | }; 129 | 130 | //////////////////////////////////////////////////////////////////////////////// 131 | 132 | Size.prototype.ne = function (aw, ah) 133 | { 134 | var s = Size.normalize (aw, ah); 135 | return this.w !== s.w 136 | || this.h !== s.h; 137 | }; 138 | 139 | //////////////////////////////////////////////////////////////////////////////// 140 | 141 | return Size; 142 | }; 143 | -------------------------------------------------------------------------------- /lib/point.js: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | "use strict"; 11 | 12 | //----------------------------------------------------------------------------// 13 | // Exports // 14 | //----------------------------------------------------------------------------// 15 | 16 | module.exports = function (robot) 17 | { 18 | //----------------------------------------------------------------------------// 19 | // Constructor Point // 20 | //----------------------------------------------------------------------------// 21 | 22 | //////////////////////////////////////////////////////////////////////////////// 23 | 24 | function Point (ax, ay) 25 | { 26 | // Auto instantiate the Point 27 | if (!(this instanceof Point)) 28 | return new Point (ax, ay); 29 | 30 | var p = Point.normalize (ax, ay); 31 | this.x = p.x; 32 | this.y = p.y; 33 | } 34 | 35 | 36 | 37 | //----------------------------------------------------------------------------// 38 | // Functions Point // 39 | //----------------------------------------------------------------------------// 40 | 41 | //////////////////////////////////////////////////////////////////////////////// 42 | 43 | Point.prototype.isZero = function() 44 | { 45 | return this.x === 0 46 | && this.y === 0; 47 | }; 48 | 49 | //////////////////////////////////////////////////////////////////////////////// 50 | 51 | Point.prototype.toSize = function() 52 | { 53 | return robot.Size 54 | (this.x, this.y); 55 | }; 56 | 57 | 58 | 59 | //----------------------------------------------------------------------------// 60 | // Static Point // 61 | //----------------------------------------------------------------------------// 62 | 63 | //////////////////////////////////////////////////////////////////////////////// 64 | 65 | Point.normalize = function (ax, ay) 66 | { 67 | if (ax instanceof Point) 68 | return ax; 69 | 70 | if (ax === undefined) 71 | return { x: 0, y: 0 }; 72 | 73 | if (typeof ax === "object" && 74 | typeof ax.x === "number" && 75 | typeof ax.y === "number") 76 | return ax; 77 | 78 | if (typeof ax === "number") 79 | { 80 | if (typeof ay === "number") 81 | return { x: ax, y: ay }; 82 | return { x: ax, y: ax }; 83 | } 84 | 85 | throw new TypeError 86 | ("Invalid arguments"); 87 | }; 88 | 89 | 90 | 91 | //----------------------------------------------------------------------------// 92 | // Operators Point // 93 | //----------------------------------------------------------------------------// 94 | 95 | //////////////////////////////////////////////////////////////////////////////// 96 | 97 | Point.prototype.add = function (ax, ay) 98 | { 99 | var p = Point.normalize (ax, ay); 100 | return Point 101 | (this.x + p.x, this.y + p.y); 102 | }; 103 | 104 | //////////////////////////////////////////////////////////////////////////////// 105 | 106 | Point.prototype.sub = function (ax, ay) 107 | { 108 | var p = Point.normalize (ax, ay); 109 | return Point 110 | (this.x - p.x, this.y - p.y); 111 | }; 112 | 113 | //////////////////////////////////////////////////////////////////////////////// 114 | 115 | Point.prototype.eq = function (ax, ay) 116 | { 117 | var p = Point.normalize (ax, ay); 118 | return this.x === p.x 119 | && this.y === p.y; 120 | }; 121 | 122 | //////////////////////////////////////////////////////////////////////////////// 123 | 124 | Point.prototype.ne = function (ax, ay) 125 | { 126 | var p = Point.normalize (ax, ay); 127 | return this.x !== p.x 128 | || this.y !== p.y; 129 | }; 130 | 131 | //////////////////////////////////////////////////////////////////////////////// 132 | 133 | Point.prototype.neg = function() 134 | { 135 | return Point (-this.x, -this.y); 136 | }; 137 | 138 | //////////////////////////////////////////////////////////////////////////////// 139 | 140 | return Point; 141 | }; 142 | -------------------------------------------------------------------------------- /lib/color.js: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | "use strict"; 11 | 12 | //----------------------------------------------------------------------------// 13 | // Exports // 14 | //----------------------------------------------------------------------------// 15 | 16 | module.exports = function (robot) 17 | { 18 | //----------------------------------------------------------------------------// 19 | // Constructor Color // 20 | //----------------------------------------------------------------------------// 21 | 22 | //////////////////////////////////////////////////////////////////////////////// 23 | 24 | function Color (ar, ag, ab, aa) 25 | { 26 | // Auto instantiate the Color 27 | if (!(this instanceof Color)) 28 | return new Color (ar, ag, ab, aa); 29 | 30 | var c = Color.normalize (ar, ag, ab, aa); 31 | this.r = c.r; 32 | this.g = c.g; 33 | this.b = c.b; 34 | this.a = c.a; 35 | } 36 | 37 | 38 | 39 | //----------------------------------------------------------------------------// 40 | // Functions Color // 41 | //----------------------------------------------------------------------------// 42 | 43 | //////////////////////////////////////////////////////////////////////////////// 44 | 45 | Color.prototype.getARGB = function() 46 | { 47 | return ((this.a << 24) | (this.r << 16) | 48 | (this.g << 8) | (this.b << 0)) 49 | >>> 0; 50 | }; 51 | 52 | //////////////////////////////////////////////////////////////////////////////// 53 | 54 | Color.prototype.setARGB = function (argb) 55 | { 56 | // Verify that argb is valid 57 | if (typeof argb !== "number") 58 | throw new TypeError ("Invalid arguments"); 59 | 60 | this.a = (argb & 0xFF000000) >>> 24; 61 | this.r = (argb & 0x00FF0000) >>> 16; 62 | this.g = (argb & 0x0000FF00) >>> 8; 63 | this.b = (argb & 0x000000FF) >>> 0; 64 | }; 65 | 66 | 67 | 68 | //----------------------------------------------------------------------------// 69 | // Static Color // 70 | //----------------------------------------------------------------------------// 71 | 72 | //////////////////////////////////////////////////////////////////////////////// 73 | 74 | Color.normalize = function (ar, ag, ab, aa) 75 | { 76 | if (ar instanceof Color) 77 | return ar; 78 | 79 | if (ar === undefined) 80 | return { r: 0, g: 0, b: 0, a: 0 }; 81 | 82 | if (typeof ar === "object" && 83 | typeof ar.r === "number" && 84 | typeof ar.g === "number" && 85 | typeof ar.b === "number") 86 | { 87 | if (typeof ar.a === "number") 88 | return ar; 89 | 90 | return { r: ar.r, g: ar.g, 91 | b: ar.b, a: 255 }; 92 | } 93 | 94 | if (typeof ar === "number") 95 | { 96 | if (typeof ag === "number" && 97 | typeof ab === "number") 98 | { 99 | if (typeof aa === "number") 100 | return { r: ar, g: ag, b: ab, a: aa }; 101 | return { r: ar, g: ag, b: ab, a: 255 }; 102 | } 103 | 104 | return { 105 | a: (ar & 0xFF000000) >>> 24, 106 | r: (ar & 0x00FF0000) >>> 16, 107 | g: (ar & 0x0000FF00) >>> 8, 108 | b: (ar & 0x000000FF) >>> 0 109 | }; 110 | } 111 | 112 | throw new TypeError ("Invalid arguments"); 113 | }; 114 | 115 | 116 | 117 | //----------------------------------------------------------------------------// 118 | // Operators Color // 119 | //----------------------------------------------------------------------------// 120 | 121 | //////////////////////////////////////////////////////////////////////////////// 122 | 123 | Color.prototype.eq = function (ar, ag, ab, aa) 124 | { 125 | var c = Color.normalize (ar, ag, ab, aa); 126 | return this.a === c.a 127 | && this.r === c.r 128 | && this.g === c.g 129 | && this.b === c.b; 130 | }; 131 | 132 | //////////////////////////////////////////////////////////////////////////////// 133 | 134 | Color.prototype.ne = function (ar, ag, ab, aa) 135 | { 136 | var c = Color.normalize (ar, ag, ab, aa); 137 | return this.a !== c.a 138 | || this.r !== c.r 139 | || this.g !== c.g 140 | || this.b !== c.b; 141 | }; 142 | 143 | //////////////////////////////////////////////////////////////////////////////// 144 | 145 | return Color; 146 | }; 147 | -------------------------------------------------------------------------------- /lib/range.js: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | "use strict"; 11 | 12 | //----------------------------------------------------------------------------// 13 | // Exports // 14 | //----------------------------------------------------------------------------// 15 | 16 | module.exports = function (robot) 17 | { 18 | //----------------------------------------------------------------------------// 19 | // Constructor Range // 20 | //----------------------------------------------------------------------------// 21 | 22 | //////////////////////////////////////////////////////////////////////////////// 23 | 24 | function Range (aMin, aMax) 25 | { 26 | // Auto instantiate the Range 27 | if (!(this instanceof Range)) 28 | return new Range (aMin, aMax); 29 | 30 | var r = Range.normalize (aMin, aMax); 31 | this.min = r.min; 32 | this.max = r.max; 33 | } 34 | 35 | 36 | 37 | //----------------------------------------------------------------------------// 38 | // Functions Range // 39 | //----------------------------------------------------------------------------// 40 | 41 | //////////////////////////////////////////////////////////////////////////////// 42 | 43 | Range.prototype.getRange = function() 44 | { 45 | return this.max - this.min; 46 | }; 47 | 48 | //////////////////////////////////////////////////////////////////////////////// 49 | 50 | Range.prototype.setRange = function (aMin, aMax) 51 | { 52 | var r = Range.normalize (aMin, aMax); 53 | this.min = r.min; 54 | this.max = r.max; 55 | }; 56 | 57 | //////////////////////////////////////////////////////////////////////////////// 58 | 59 | Range.prototype.getRandom = function() 60 | { 61 | // Check if this range is currently valid 62 | if (this.min >= this.max) return this.min; 63 | 64 | // Generate value between a range 65 | return (Math.random() * (this.max - 66 | this.min) | 0) + this.min; 67 | }; 68 | 69 | //////////////////////////////////////////////////////////////////////////////// 70 | 71 | Range.prototype.contains = function (value, inclusive) 72 | { 73 | // Inclusive true by default 74 | if (inclusive === undefined) 75 | inclusive = true; 76 | 77 | // Verify that parameters are valid 78 | if (typeof value !== "number" || 79 | typeof inclusive !== "boolean") 80 | throw new TypeError ("Invalid arguments"); 81 | 82 | return inclusive ? 83 | this.min <= value && value <= this.max : 84 | this.min < value && value < this.max; 85 | }; 86 | 87 | 88 | 89 | //----------------------------------------------------------------------------// 90 | // Static Range // 91 | //----------------------------------------------------------------------------// 92 | 93 | //////////////////////////////////////////////////////////////////////////////// 94 | 95 | Range.normalize = function (aMin, aMax) 96 | { 97 | if (aMin instanceof Range) 98 | return aMin; 99 | 100 | if (aMin === undefined) 101 | return { min: 0, max: 0 }; 102 | 103 | if (typeof aMin === "object" && 104 | typeof aMin.min === "number" && 105 | typeof aMin.max === "number") 106 | return aMin; 107 | 108 | if (typeof aMin === "number") 109 | { 110 | if (typeof aMax === "number") 111 | return { min: aMin, max: aMax }; 112 | return { min: aMin, max: aMin }; 113 | } 114 | 115 | throw new TypeError 116 | ("Invalid arguments"); 117 | }; 118 | 119 | 120 | 121 | //----------------------------------------------------------------------------// 122 | // Operators Range // 123 | //----------------------------------------------------------------------------// 124 | 125 | //////////////////////////////////////////////////////////////////////////////// 126 | 127 | Range.prototype.eq = function (aMin, aMax) 128 | { 129 | var r = Range.normalize (aMin, aMax); 130 | return this.min === r.min 131 | && this.max === r.max; 132 | }; 133 | 134 | //////////////////////////////////////////////////////////////////////////////// 135 | 136 | Range.prototype.ne = function (aMin, aMax) 137 | { 138 | var r = Range.normalize (aMin, aMax); 139 | return this.min !== r.min 140 | || this.max !== r.max; 141 | }; 142 | 143 | //////////////////////////////////////////////////////////////////////////////// 144 | 145 | return Range; 146 | }; 147 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "conditions": 3 | [ 4 | [ "OS == 'linux'", { "variables": { "target_platform": "linux" }}], 5 | [ "OS == 'mac'", { "variables": { "target_platform": "darwin" }}], 6 | [ "OS == 'win'", { "variables": { "target_platform": "win32" }}] 7 | ], 8 | 9 | "variables": 10 | { 11 | "target_module_version": "= this._bounds.h; }; 63 | 64 | 65 | 66 | //----------------------------------------------------------------------------// 67 | // Static Screen // 68 | //----------------------------------------------------------------------------// 69 | 70 | //////////////////////////////////////////////////////////////////////////////// 71 | 72 | Screen._screens = [ ]; 73 | Screen._totalBounds = robot.Bounds(); 74 | Screen._totalUsable = robot.Bounds(); 75 | 76 | //////////////////////////////////////////////////////////////////////////////// 77 | 78 | Screen.synchronize = function() 79 | { 80 | // Perform native screen synchronization 81 | var result = native.Screen.synchronize(); 82 | 83 | this._screens = result.screens; 84 | this._totalBounds = result.totalBounds; 85 | this._totalUsable = result.totalUsable; 86 | 87 | // Convert screen objects into screen classes 88 | for (var i = 0; i < this._screens.length; ++i) 89 | { 90 | this._screens[i] = Screen 91 | (this._screens[i].bounds, 92 | this._screens[i].usable); 93 | } 94 | 95 | return result.status; 96 | }; 97 | 98 | //////////////////////////////////////////////////////////////////////////////// 99 | 100 | Screen.getMain = function() 101 | { 102 | // The primary screen is always the first screen object 103 | return this._screens.length ? this._screens[0] : null; 104 | }; 105 | 106 | //////////////////////////////////////////////////////////////////////////////// 107 | 108 | Screen.getList = function() { return this._screens; }; 109 | 110 | //////////////////////////////////////////////////////////////////////////////// 111 | 112 | Screen.getScreen = function (ax, ay) 113 | { 114 | var p; 115 | // Check if instance of window 116 | if (ax instanceof robot.Window) 117 | { 118 | if (!ax.isValid()) return null; 119 | p = ax.getBounds().getCenter(); 120 | } 121 | 122 | // Attempt to parse as a regular point 123 | else p = robot.Point.normalize (ax, ay); 124 | 125 | // Loop through every available screen object 126 | for (var i = 0; i < this._screens.length; ++i) 127 | { 128 | if (this._screens[i]._bounds.containsP 129 | (p.x, p.y)) return this._screens[i]; 130 | } 131 | 132 | // The primary screen is always the first screen object 133 | return this._screens.length ? this._screens[0] : null; 134 | }; 135 | 136 | //////////////////////////////////////////////////////////////////////////////// 137 | 138 | Screen.grabScreen = function (image, ax, ay, aw, ah, window) 139 | { 140 | // Check if argument is native image 141 | if (!(image instanceof robot.Image)) 142 | throw new TypeError ("Invalid arguments"); 143 | 144 | var b = robot.Bounds. 145 | normalize (ax, ay, aw, ah); 146 | 147 | // Perform native image capture 148 | return native.Screen.grabScreen 149 | (image, b.x, b.y, b.w, b.h, 150 | arguments[arguments.length - 1]); 151 | }; 152 | 153 | //////////////////////////////////////////////////////////////////////////////// 154 | 155 | Screen.getTotalBounds = function() { return this._totalBounds; }; 156 | Screen.getTotalUsable = function() { return this._totalUsable; }; 157 | 158 | //////////////////////////////////////////////////////////////////////////////// 159 | 160 | Screen. isCompositing = native.Screen. isCompositing; 161 | Screen.setCompositing = native.Screen.setCompositing; 162 | 163 | //////////////////////////////////////////////////////////////////////////////// 164 | 165 | return Screen; 166 | }; 167 | -------------------------------------------------------------------------------- /src/NodeKeyboard.cc: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // -------------------------------------------------------------------------- // 3 | // // 4 | // (C) 2010-2018 Robot Developers // 5 | // See LICENSE for licensing info // 6 | // // 7 | // -------------------------------------------------------------------------- // 8 | //////////////////////////////////////////////////////////////////////////////// 9 | 10 | //----------------------------------------------------------------------------// 11 | // Prefaces // 12 | //----------------------------------------------------------------------------// 13 | 14 | #include "NodeKeyboard.h" 15 | DEFINE_ROBOT_TYPE (Keyboard); 16 | 17 | 18 | 19 | //----------------------------------------------------------------------------// 20 | // Functions KeyboardWrap // 21 | //----------------------------------------------------------------------------// 22 | 23 | //////////////////////////////////////////////////////////////////////////////// 24 | 25 | void KeyboardWrap::Click (const FunctionCallbackInfo& args) 26 | { 27 | ISOWRAP (Keyboard, args.Holder()); 28 | 29 | mKeyboard->AutoDelay.Min = args[1]->Int32Value(); 30 | mKeyboard->AutoDelay.Max = args[2]->Int32Value(); 31 | if (args[0]->IsInt32()) 32 | mKeyboard->Click ((Key) args[0]->Int32Value()); 33 | 34 | else 35 | { 36 | // Args should be string 37 | if (!args[0]->IsString()) 38 | THROW (Type, "Invalid arguments"); 39 | 40 | String::Utf8Value value (args[0]); 41 | auto keys = *value ? *value : ""; 42 | // Perform a series of keycode actions 43 | RETURN_BOOL (mKeyboard->Click (keys)); 44 | } 45 | } 46 | 47 | //////////////////////////////////////////////////////////////////////////////// 48 | 49 | void KeyboardWrap::Press (const FunctionCallbackInfo& args) 50 | { 51 | ISOWRAP (Keyboard, args.Holder()); 52 | 53 | // Check for valid args 54 | if (!args[0]->IsInt32()) 55 | THROW (Type, "Invalid arguments"); 56 | 57 | mKeyboard->AutoDelay.Min = args[1]->Int32Value(); 58 | mKeyboard->AutoDelay.Max = args[2]->Int32Value(); 59 | mKeyboard->Press ((Key) args[0]->Int32Value()); 60 | } 61 | 62 | //////////////////////////////////////////////////////////////////////////////// 63 | 64 | void KeyboardWrap::Release (const FunctionCallbackInfo& args) 65 | { 66 | ISOWRAP (Keyboard, args.Holder()); 67 | 68 | // Check for valid args 69 | if (!args[0]->IsInt32()) 70 | THROW (Type, "Invalid arguments"); 71 | 72 | mKeyboard->AutoDelay.Min = args[1]->Int32Value(); 73 | mKeyboard->AutoDelay.Max = args[2]->Int32Value(); 74 | mKeyboard->Release ((Key) args[0]->Int32Value()); 75 | } 76 | 77 | //////////////////////////////////////////////////////////////////////////////// 78 | 79 | void KeyboardWrap::Compile (const FunctionCallbackInfo& args) 80 | { 81 | ISOLATE; 82 | 83 | // Check for valid args 84 | if (!args[0]->IsString()) 85 | THROW (Type, "Invalid arguments"); 86 | 87 | String::Utf8Value value (args[0]); 88 | auto keys = *value ? *value : ""; 89 | 90 | KeyList list; 91 | // Attempt to compile the key list 92 | if (Keyboard::Compile (keys, list)) 93 | { 94 | int length = (int) list.size(); 95 | auto res = NEW_ARR (length); 96 | // Loop array and add to result 97 | for (int i = 0; i < length; ++i) 98 | { 99 | auto obj = NEW_OBJ; 100 | obj->Set (NEW_STR ("down"), NEW_BOOL (list[i].first )); 101 | obj->Set (NEW_STR ("key" ), NEW_INT (list[i].second)); 102 | res->Set (i, obj); 103 | } 104 | 105 | RETURN (res); 106 | } 107 | 108 | RETURN_ARR; 109 | } 110 | 111 | //////////////////////////////////////////////////////////////////////////////// 112 | 113 | void KeyboardWrap::GetState (const FunctionCallbackInfo& args) 114 | { 115 | ISOLATE; 116 | // No arguments were given 117 | if (args[0]->IsUndefined()) 118 | { 119 | auto res = NEW_OBJ; 120 | KeyState state; 121 | // Retrieve all keycode states 122 | if (Keyboard::GetState (state)) 123 | { 124 | // Loop every state and add it to resulting object 125 | for (auto i = state.begin(); i != state.end(); ++i) 126 | res->Set (NEW_INT (i->first), NEW_BOOL (i->second)); 127 | } 128 | 129 | RETURN (res); 130 | } 131 | 132 | // A keycode was given 133 | if (args[0]->IsInt32()) 134 | { 135 | RETURN_BOOL (Keyboard::GetState 136 | // Get info about a single key 137 | ((Key) args[0]->Int32Value())); 138 | } 139 | 140 | THROW (Type, "Invalid arguments"); 141 | } 142 | 143 | //////////////////////////////////////////////////////////////////////////////// 144 | 145 | void KeyboardWrap::New (const FunctionCallbackInfo& args) 146 | { 147 | ISOLATE; 148 | // Whether called using new 149 | if (args.IsConstructCall()) 150 | { 151 | (new KeyboardWrap())->Wrap (args.This()); 152 | args.This()->Set (NEW_STR ("autoDelay"), 153 | NEW_RANGE ( 40, 90)); 154 | 155 | REGISTER_ROBOT_TYPE; 156 | RETURN (args.This()); 157 | } 158 | 159 | else 160 | { 161 | auto ctor = NEW_CTOR (Keyboard); 162 | // Return as a new instance 163 | RETURN (ctor->NewInstance()); 164 | } 165 | } 166 | 167 | //////////////////////////////////////////////////////////////////////////////// 168 | 169 | void KeyboardWrap::Initialize (Handle exports) 170 | { 171 | // Get the current isolated V8 instance 172 | Isolate* isolate = Isolate::GetCurrent(); 173 | 174 | // Associate the new function with new template 175 | auto tpl = FunctionTemplate::New (isolate, New); 176 | tpl->InstanceTemplate()->SetInternalFieldCount (1); 177 | tpl->SetClassName (NEW_STR ("Keyboard")); 178 | 179 | NODE_SET_PROTOTYPE_METHOD (tpl, "_click", Click ); 180 | NODE_SET_PROTOTYPE_METHOD (tpl, "_press", Press ); 181 | NODE_SET_PROTOTYPE_METHOD (tpl, "_release", Release); 182 | 183 | NODE_SET_METHOD ((Local