layout | title | categories | lead_text |
---|---|---|---|
docs |
Syntax |
docs |
keyToggle
and keyTap
support for following keys.
Note: The names of the letter and number keys are the same as that single letter or digit. For example: b is the "b" key and 5 is the "5" key.
Key | Description | Notes |
---|---|---|
backspace | ||
delete | ||
enter | ||
tab | ||
escape | ||
up | Up arrow key | |
down | Down arrow key | |
right | Right arrow key | |
left | Left arrow key | |
home | ||
end | ||
pageup | ||
pagedown | ||
f1 | ||
f2 | ||
f3 | ||
f4 | ||
f5 | ||
f6 | ||
f7 | ||
f8 | ||
f9 | ||
f10 | ||
f11 | ||
f12 | ||
command | ||
alt | ||
control | ||
shift | ||
right_shift | ||
space | ||
printscreen | No Mac support | |
insert | No Mac support | |
audio_mute | Mute the volume | |
audio_vol_down | Lower the volume | |
audio_vol_up | Increase the volume | |
audio_play | Play | |
audio_stop | Stop | |
audio_pause | Pause | |
audio_prev | Previous Track | |
audio_next | Next Track | |
audio_rewind | Linux only | |
audio_forward | Linux only | |
audio_repeat | Linux only | |
audio_random | Linux only | |
numpad_0 | No Linux support | |
numpad_1 | No Linux support | |
numpad_2 | No Linux support | |
numpad_3 | No Linux support | |
numpad_4 | No Linux support | |
numpad_5 | No Linux support | |
numpad_6 | No Linux support | |
numpad_7 | No Linux support | |
numpad_8 | No Linux support | |
numpad_9 | No Linux support | |
lights_mon_up | Turn up monitor brightness | No Windows support |
lights_mon_down | Turn down monitor brightness | No Windows support |
lights_kbd_toggle | Toggle keyboard backlight on/off | No Windows support |
lights_kbd_up | Turn up keyboard backlight brightness | No Windows support |
lights_kbd_down | Turn down keyboard backlight brightness | No Windows support |
Up to date as of v0.4.4.
Sets the delay in milliseconds to sleep after a keyboard event. This is 10ms by default.
Arguments
Argument | Description | Default |
---|---|---|
ms |
Time to sleep in milliseconds. | None |
Press a single key.
Arguments
Argument | Description | Default |
---|---|---|
key |
See keys. | None |
modified |
String or an array. Accepts alt, command (win), control, and shift. | None |
Hold down or release a key.
Arguments
Argument | Description | Default |
---|---|---|
key |
See keys. | None |
down |
Accepts down or up. | None |
modifier |
String or an array. Accepts alt, command (mac), control, and shift. | None |
Arguments
Argument | Description | Default |
---|---|---|
string |
The string to send. | None |
Arguments
Argument | Description | Default |
---|---|---|
string |
The string to send. | None |
cpm |
Characters per minute. | None |
Sets the delay in milliseconds to sleep after a mouse event. This is 10ms by default.
Arguments
Argument | Description | Default |
---|---|---|
ms |
Time to sleep in milliseconds. | None |
Moves mouse to x, y instantly, with the mouse button up.
Arguments
Argument | Description | Default |
---|---|---|
x |
None | |
y |
None |
Examples
{% highlight javascript %} var robot = require("robotjs");
//Move the mouse to 100, 100 on the screen. robot.moveMouse(100, 100); {% endhighlight %}
Moves mouse to x, y human like, with the mouse button up.
Arguments
Argument | Description | Default |
---|---|---|
x |
None | |
y |
None |
Clicks the mouse.
Arguments
Argument | Description | Default |
---|---|---|
button |
Accepts left, right, or middle. | left |
double |
Set to true to perform a double click. | false |
Examples
{% highlight javascript %} var robot = require("robotjs");
robot.mouseClick(); {% endhighlight %}
Toggles mouse button.
Arguments
Argument | Description | Default |
---|---|---|
down |
Accepts down or up. | down |
button |
Accepts left, right, or middle. | left |
Examples
{% highlight javascript %} var robot = require("robotjs");
robot.mouseToggle("down");
setTimeout(function() { robot.mouseToggle("up");
}, 2000); {% endhighlight %}
Moves mouse to x, y instantly, with the mouse button held down.
Arguments
Argument | Description | Default |
---|---|---|
x |
None | |
y |
None |
Examples
{% highlight javascript %} var robot = require("robotjs");
//Mouse down at 0, 0 and then drag to 100, 100 and release. robot.moveMouse(0, 0); robot.mouseToggle("down"); robot.dragMouse(100, 100); robot.mouseToggle("up"); {% endhighlight %}
Gets the mouse coordinates.
Return
Returns an object with keys x and y.
Examples
{% highlight javascript %} var robot = require("robotjs");
var mouse = robot.getMousePos(); console.log("Mouse is at x:" + mouse.x + " y:" + mouse.y); {% endhighlight %}
Scrolls the mouse either up or down.
Arguments
Argument | Description | Default |
---|---|---|
magnitude |
The amount to scroll. | None |
direction |
Accepts down or up. | None |
Examples
{% highlight javascript %} var robot = require("robotjs");
robot.scrollMouse(50, "up");
setTimeout(function() { robot.scrollMouse(50, "down"); }, 2000); {% endhighlight %}
Gets the pixel color at x, y. This function is perfect for getting a pixel or two, but if you'll be reading large portions of the screen use screen.capture.
Arguments
Argument | Description | Default |
---|---|---|
x |
None | |
y |
None |
Return
Returns the hex color code of the pixel at x, y.
Gets the screen width and height.
Return
Returns an object with .width
and .height
.
Gets part or all of the screen.
Arguments
Argument | Description | Default |
---|---|---|
x |
0 | |
y |
0 | |
width |
Screen width | |
height |
Screen height |
If no arguments are provided, screen.capture will get the full screen.
Return
Returns a bitmap object.
Examples
For higher density screens (Macs) the resulting screen capture could be larger than the area requested. You can work around this by dividing the image size by the requested size. For example:
{% highlight javascript %} var size = 10; var img = robot.screen.capture(0, 0, size, size); // Support for higher density screens. var multi = img.width / size; // Get color at 2, 3. var color = img.colorAt(2 * multi, 3 * multi); {% endhighlight %}
This is an object returned by screen.capture.
Property | Description
--------|-----------------|-------------
width
| The width of the bitmap.
height
| The height of the bitmap.
image
| The raw image (buffer).
byteWidth
| |
bitsPerPixel
| |
bytesPerPixel
| |
Gets the pixel color at x, y of a bitmap.
Arguments
Argument | Description | Default |
---|---|---|
x |
None | |
y |
None |
Return
Returns the hex color code of the pixel at x, y.
Examples
{% highlight javascript %} var robot = require("robotjs");
//Get a 100x100 screen capture starting at 0, 0. var img = robot.screen.capture(0, 0, 100, 100);
console.log(img.width)
//Get pixel color at 50, 50. var hex = img.colorAt(50, 50); console.log(hex); {% endhighlight %}