-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
64 lines (49 loc) · 1.36 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var express = require('express');
var bodyParser = require('body-parser');
var robot = require("robotjs");
var app = express();
app.use(express.static('public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.post('/send/string', function(req, res){
res.end();
console.log(decodeURI(req.body.string));
robot.typeString(decodeURI(req.body.string));
});
app.get('/send/key/:key', function(req, res){
res.end();
robot.keyTap(req.params.key);
});
app.get('/send/clear', function(req, res){
res.end();
robot.keyTap('a', 'control');
robot.keyTap('delete');
});
app.get('/send/ctrla', function(req, res){
res.end();
robot.keyTap('a', 'control');
});
app.post('/send/mouse/move', function(req, res){
res.end();
var mousePosition = robot.getMousePos();
var newX = mousePosition.x + req.body.x;
var newY = mousePosition.y + req.body.y;
robot.moveMouse(newX, newY);
});
app.get('/send/mouse/scroll/:direction', function(req, res){
res.end();
if(req.params.direction === "up"){
robot.scrollMouse(1, "up");
}else if(req.params.direction === "down"){
robot.scrollMouse(1, "down");
}
});
app.get('/send/mouse/click', function(req, res){
res.end();
robot.mouseClick();
});
var server = app.listen(80, function(){
var host = server.address().address;
var port = server.address().port;
console.log("listening %s:%s", host, port);
});