Node.js JavaScript: simulating keystrokes on a server (like a macro)

I am trying to get a node.js script to simulate a keystroke, like an up arrow or a button. In particular, I am trying to make a clone of Twitch Plays Pokemon . In principle, whenever a command (up, down, left, right, a, b, select, start) is sent via IRC, the server simulates a keystroke, which, in turn, controls the game emulator itself. So far I have written this with the IRC module for node.js:

var config = {
    channels: ["#tron"],
    server: "irc.freenode.net",
    botName: "wyatt"
};

var irc = require("irc");

var bot = new irc.Client(config.server, config.botName, {
    channels: config.channels
});

var commandHandler = function(from, text) {
    if(text.toLowerCase() === "up"||text.toLowerCase() === "down"||text.toLowerCase() === "left"||text.toLowerCase() === "right"||text.toLowerCase() === "a"||text.toLowerCase() === "b"||text.toLowerCase() === "select"||text.toLowerCase() === "start") {
        bot.say(config.channels[0], from.toUpperCase() + " sent the " + text.toUpperCase() + " command!");
    } else {
        bot.say(config.channels[0], from.toUpperCase() + ", that wasn't a valid command!");
    }
};

bot.addListener("message", function(from, to, text, message) {
    commandHandler(from, text);
});

To run my script, I will enter node scriptName.js in the command line. I am using Windows 7.

This connects to the #tron freenode channel, which I use for testing purposes, since it seems to be mostly inactive.

, "NIMAID LEFT!", "NIMAID, !". , . , , , script - switch.

, , , node.js JQuery - . .

TL;DR: node.js script , Windows 7.

?

+4
5

- exec node python script, pywin32. linux xdotool.

, . node .

+3

node, : https://github.com/kylepaulsen/kbm-robot

var robot = require("kbm-robot");

robot.startJar();

robot.press("alt")
    .press("tab")
    .sleep(100)
    .release("tab")
    .release("alt")
    .sleep(100)
    .typeString("Hello World!")
    .go()
    .then(robot.stopJar);
+3

-, win_keyboard npm, - Windows. npm install win_keyboard ; , , , .

+2
source

You can try the alternative to RobotJS. This is a very small and still cross-platform library for sending keys to your operating system called node-key-sender. I developed after being disappointed in RobotJS and kbm-robot.

Install it with npm install --save-dev node-key-sender.

And send the text to the keyboard using:

var ks = require('node-key-sender');
ks.sendText('This is my text');

Check out the documentation page: https://www.npmjs.com/package/node-key-sender .

+1
source

Source: https://habr.com/ru/post/1527457/


All Articles