Search code examples
javascriptnode.jskeypresstwitch

How to send keypresses through nodejs


I am coding a twitch bot and I want it so when users type a command (something like !space [time] ) it will randomly press space for the ammount of time they gave. I know how to receive the command but i dont know how to send the key input. Thanks in advance

EDIT : When i say send keypresses i mean from the nodejs console on my end not in on twitch

EDIT 2 : I want this so viewers on my stream can spend points to troll me when i am playing games


Solution

  • I know this thread is old, but you can use Nut.js.

    Minimal Example:

    const { keyboard } = require('@nut-tree/nut-js');
    keyboard.config.autoDelayMs = 0;
    
       keyboard.type("Hello World!");
    

    I personally think that RobotJS uses too many dependencies. Nut.js is much easier to use and much faster to set up.