'use strict';

// Move the mouse across the screen as a sine wave.
const robot = require("robotjs");

// Speed up the mouse.

const twoPI = Math.PI * 2.0;
const screenSize = robot.getScreenSize();
const height = (screenSize.height / 2) - 10;
const width = screenSize.width;

for (let x = 0; x < width; x++){
    const y = height * Math.sin((twoPI * x) / width) + height;
    robot.moveMouse(x, y);

Raspberry Piへのインストールでエラーでました

$ npm i --save robotjs

> robotjs@0.4.7 install /home/pi/n0bisuke/splatoon_audio/robottest/node_modules/robotjs
> prebuild-install || node-gyp rebuild

prebuild-install info begin Prebuild-install version 2.4.1
prebuild-install info looking for local prebuild @ prebuilds/robotjs-v0.4.7-node-v59-linux-arm.tar.gz
prebuild-install info looking for cached prebuild @ /home/pi/.npm/_prebuilds/
prebuild-install http request GET
prebuild-install http 404
prebuild-install WARN install No prebuilt binaries found (target=9.2.0 runtime=node arch=arm platform=linux)
make: Entering directory '/home/pi/n0bisuke/splatoon_audio/robottest/node_modules/robotjs/build'
  CXX(target) Release/
cc1plus: warning: command line option '-Wbad-function-cast' is valid for C/ObjC but not for C++
In file included from ../src/keypress.h:6:0,
                 from ../src/
../src/keycode.h:103:23: fatal error: X11/Xutil.h: No such file or directory
 #include <X11/Xutil.h>
compilation terminated. recipe for target 'Release/' failed
make: *** [Release/] Error 1
make: Leaving directory '/home/pi/n0bisuke/splatoon_audio/robottest/node_modules/robotjs/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/home/pi/.nodebrew/node/v9.2.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack     at ChildProcess.emit (events.js:159:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:12)
gyp ERR! System Linux 4.4.21-v7+
gyp ERR! command "/home/pi/.nodebrew/node/v9.2.0/bin/node" "/home/pi/.nodebrew/node/v9.2.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/pi/n0bisuke/splatoon_audio/robottest/node_modules/robotjs
gyp ERR! node -v v9.2.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN robottest@1.0.0 No description
npm WARN robottest@1.0.0 No repository field.

npm ERR! errno 1
npm ERR! robotjs@0.4.7 install: `prebuild-install || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the robotjs@0.4.7 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/pi/.npm/_logs/2017-12-13T08_00_26_277Z-debug.log

たぶんX11/Xutil.h: No such file or directoryのところが怪しい

X11/Xutil.h: No such file or directory


$ sudo apt-get install libx11-dev



../src/mouse.c:12:35: fatal error: X11/extensions/XTest.h: No such file or directory
  #include <X11/extensions/XTest.h>

X11/extensions/XTest.h: No such file or directory


$ sudo apt-get install apt-file
$ sudo apt-file update
$ apt-file search "X11/extensions/XTest.h"
$ sudo apt-get install libxtst-dev


Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.