Skip to content

Instantly share code, notes, and snippets.

@CodeBrauer
Created July 31, 2015 22:46
Show Gist options
  • Save CodeBrauer/6e6624d8234a5642c2d3 to your computer and use it in GitHub Desktop.
Save CodeBrauer/6e6624d8234a5642c2d3 to your computer and use it in GitHub Desktop.
just a simple demo for a ajax-usage of robotjs - allows to set the mouse position on a simple request like this: http://localhost:4000/movemouse/200/50
var sys = require('sys');
var http = require('http');
var robot = require('robotjs');
console.log('Starting...');
http.createServer(function(request, response) {
result = 0;
if (request.method === 'GET') {
requestEndpoint = request.url.split('/');
if (
requestEndpoint[1] === 'movemouse'
&& typeof requestEndpoint[2] !== 'undefined'
&& typeof requestEndpoint[3] !== 'undefined'
) {
result = robot.moveMouse(parseInt(requestEndpoint[2]), parseInt(requestEndpoint[3]));
console.log('moved mouse to: x: ' + requestEndpoint[2] + ', y:' + requestEndpoint[3]);
}
}
response.writeHeader(200, {'Content-Type:' : 'application/javascript'})
response.write(JSON.stringify({'success' : (parseInt(result) != 0 ? true : false) }));
response.end();
}).listen(4000);
console.log('Server running on port 4000');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment