Last active
August 4, 2018 22:19
-
-
Save brianpeiris/b9117eceec4d4e1597ec807637951b46 to your computer and use it in GitHub Desktop.
robot-websocket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
robot-websocket is a websocket server that runs robotjs commands when it receives messages. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules | |
cert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "robot-websocket", | |
"private": true, | |
"dependencies": { | |
"robotjs": "0.5.1", | |
"ws": "6.0.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const https = require('https'); | |
const WebSocket = require('ws'); | |
const robot = require('robotjs'); | |
const server = new https.createServer({ | |
cert: fs.readFileSync('cert/cert.pem'), | |
key: fs.readFileSync('cert/key.pem') | |
}); | |
const wss = new WebSocket.Server({ server }); | |
wss.on('connection', function connection(ws) { | |
console.log('connected'); | |
ws.on('message', function incoming(message) { | |
console.log('message', message); | |
switch(message) { | |
case 'scrolldown': | |
robot.scrollMouse(0, -3000); | |
break; | |
case 'scrollup': | |
robot.scrollMouse(0, 3000); | |
break; | |
} | |
}); | |
}); | |
server.listen(443); | |
console.log('listening'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment