captureScreen = function () { [native code] }...
}
module.exports.screen.capture = function(x, y, width, height)
{
//If coords have been passed, use them.
if (typeof x !== "undefined" && typeof y !== "undefined" && typeof width !== "undefined
" && typeof height !== "undefined")
{
b = robotjs.captureScreen(x, y, width, height);
}
else
{
b = robotjs.captureScreen();
}
return new bitmap(b.width, b.height, b.byteWidth, b.bitsPerPixel, b.bytesPerPixel, b.image);
...dragMouse = function () { [native code] }...
});
test('Drag the mouse.', function(t)
{
t.plan(4);
t.ok(robot.dragMouse(5, 5) === 1, 'successfully dragged the mouse.');
t.throws(function()
{
robot.dragMouse(0);
}, /Invalid number/, 'drag mouse to (0).');
t.throws(function()
...getColor = function () { [native code] }...
this.byteWidth = byteWidth;
this.bitsPerPixel = bitsPerPixel;
this.bytesPerPixel = bytesPerPixel;
this.image = image;
this.colorAt = function(x, y)
{
return robotjs.getColor(this, x, y);
};
}
module.exports.screen.capture = function(x, y, width, height)
{
//If coords have been passed, use them.
...getMousePos = function () { [native code] }...
##### [Screen](https://github.com/octalmage/robotjs/wiki/Syntax#screen)
```JavaScript
// Get pixel color under the mouse.
var robot = require("robotjs");
// Get mouse position.
var mouse = robot.getMousePos();
// Get pixel color in hex format.
var hex = robot.getPixelColor(mouse.x, mouse.y);
console.log("#" + hex + " at x:" + mouse.x + " y:" + mouse.y);
```
Read the [Wiki](https://github.com/octalmage/robotjs/wiki) for more information!
...getPixelColor = function () { [native code] }...
// Get pixel color under the mouse.
var robot = require("robotjs");
// Get mouse position.
var mouse = robot.getMousePos();
// Get pixel color in hex format.
var hex = robot.getPixelColor(mouse.x, mouse.y);
console.log("#" + hex + " at x:" + mouse.x + " y:" + mouse.y);
```
Read the [Wiki](https://github.com/octalmage/robotjs/wiki) for more information!
## [API](https://github.com/octalmage/robotjs/wiki/Syntax)
The [RobotJS API](https://github.com/octalmage/robotjs/wiki/Syntax) is contained in the [Wiki](https://github.com/octalmage/robotjs
/wiki).
...getScreenSize = function () { [native code] }...
// Move the mouse across the screen as a sine wave.
var robot = require("robotjs");
// 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 (var x = 0; x < width; x++)
{
y = height * Math.sin((twoPI * x) / width) + height;
robot.moveMouse(x, y);
...getXDisplayName = function () { [native code] }n/a
keyTap = function () { [native code] }...
// Type "Hello World" then press enter.
var robot = require("robotjs");
// Type "Hello World".
robot.typeString("Hello World");
// Press enter.
robot.keyTap("enter");
```
##### [Screen](https://github.com/octalmage/robotjs/wiki/Syntax#screen)
```JavaScript
// Get pixel color under the mouse.
var robot = require("robotjs");
...keyToggle = function () { [native code] }n/a
mouseClick = function () { [native code] }...
t.ok(robot.moveMouseSmooth("0", "0") === 1, 'move mouse to ("0", "0").');
});
test('Click the mouse.', function(t)
{
t.plan(8);
t.ok(robot.mouseClick(), 'click the mouse (no button specified).');
t.ok(robot.mouseClick("left") === 1, 'click the left mouse button.');
t.ok(robot.mouseClick("middle") === 1, 'click the middle mouse button.');
t.ok(robot.mouseClick("right") === 1, 'click the right mouse button.');
t.ok(robot.mouseClick("left", 1), 'double click the left mouse button.');
t.throws(function()
...mouseToggle = function () { [native code] }n/a
moveMouse = function () { [native code] }...
var screenSize = robot.getScreenSize();
var height = (screenSize.height / 2) - 10;
var width = screenSize.width;
for (var x = 0; x < width; x++)
{
y = height * Math.sin((twoPI * x) / width) + height;
robot.moveMouse(x, y);
}
```
##### [Keyboard](https://github.com/octalmage/robotjs/wiki/Syntax#keyboard)
```JavaScript
// Type "Hello World" then press enter.
...moveMouseSmooth = function () { [native code] }...
t.ok(robot.moveMouse("0", "0") === 1, 'move mouse to ("0", "0").');
});
test('Move the mouse smoothly.', function(t)
{
t.plan(6);
lastKnownPos = robot.moveMouseSmooth(0, 0);
t.ok(robot.moveMouseSmooth(100, 100) === 1, 'successfully moved the mouse.');
currentPos = robot.getMousePos();
t.ok(currentPos.x === 100, 'mousepos.x is correct.');
t.ok(currentPos.y === 100, 'mousepos.y is correct.');
t.throws(function()
{
...scrollMouse = function () { [native code] }n/a
setKeyboardDelay = function () { [native code] }n/a
setMouseDelay = function () { [native code] }...
<p align="center"><img src="https://cldup.com/lugVjjAkEi.gif"></p>
```JavaScript
// Move the mouse across the screen as a sine wave.
var robot = require("robotjs");
// 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 (var x = 0; x < width; x++)
...setXDisplayName = function () { [native code] }n/a
typeString = function () { [native code] }...
##### [Keyboard](https://github.com/octalmage/robotjs/wiki/Syntax#keyboard)
```JavaScript
// Type "Hello World" then press enter.
var robot = require("robotjs");
// Type "Hello World".
robot.typeString("Hello World");
// Press enter.
robot.keyTap("enter");
```
##### [Screen](https://github.com/octalmage/robotjs/wiki/Syntax#screen)
...typeStringDelayed = function () { [native code] }n/a
capture = function (x, y, width, height)
{
//If coords have been passed, use them.
if (typeof x !== "undefined" && typeof y !== "undefined" && typeof width !== "undefined" && typeof height !== "undefined")
{
b = robotjs.captureScreen(x, y, width, height);
}
else
{
b = robotjs.captureScreen();
}
return new bitmap(b.width, b.height, b.byteWidth, b.bitsPerPixel, b.bytesPerPixel, b.image);
}...
'bytesPerPixel': 'number',
'image': 'object'
};
test('Get a bitmap.', function(t)
{
t.plan(1);
t.ok(robot.screen.capture(), 'got a bitmap.');
});
test('Get a bitmap and check the parameters.', function(t)
{
t.plan(6);
var img = robot.screen.capture();
...