Haxe externs for RobotJS. RobotJS is a desktop automation library for Node.js.
Inject keystrokes and mouse moves into a Node.js application. Also capture mouse position and screen pixels.
A simple test app for Node.js is here.
A sample app for VSCode/Electron is here.
Install robot-externs
lib for Haxe:
haxelib git robotjs-externs https://github.com/wiggin77/robotjs-externs.git
Install RobotJS module. From the directory of the project for which you want to add RobotJS support (i.e. directory containing package.json
):
npm install robotjs
This will create a node_modules
directory within your project directory.
npm
will install prebuilt binaries for Windows, Mac, and Linux. If you need to build it yourself, see here.
To build for Electron see here.
Examples modified for Haxe from http://robotjs.io/docs/examples.
import js.robotjs.Robot;
class Test {
public static function test() {
// Speed up the mouse.
Robot.setMouseDelay(2);
var twoPI = Math.PI * 2.0;
var screenSize = Robot.getScreenSize();
var height = (screenSize.height / 2) - 10;
var width = screenSize.width;
for (x in 0...width)
{
var y = Std.int(height * Math.sin((twoPI * x) / width) + height);
Robot.moveMouse(x, y);
}
}
}
import js.robotjs.Robot;
import js.robotjs.RobotHelper;
class Test {
public static function test() {
// Type "Hello World".
Robot.typeString("Hello World");
// Press enter.
Robot.keyTap("enter");
// Use helper for auto-shift modifier.
RobotHelper.typeString("_Mixed shift and non-shift!");
}
}
import js.robotjs.Robot;
class Test {
public static function test() {
// Get mouse position.
var mouse = Robot.getMousePos();
// Get pixel color in hex format.
var hex = Robot.getPixelColor(mouse.x, mouse.y);
trace("#" + hex + " at x:" + mouse.x + " y:" + mouse.y);
}
}