Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.1K
Visualizações
How to press a key using nodejs?

I would like to know how to get a certain key on the keyboard to be pressed via code on nodejs.

For instance, I want the f3 button to pressed once the following page is rendered:

var express = require('express');
var router = express.Router();


/* GET home page. */
router.get('/', function(req, res, next) {
   // press key
});

module.exports = router;
about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Take a look at robotjs, which can be used to generate keyboard events.

For instance, to "send" an F3 key press:

const robot = require('robotjs');
...
router.get('/', function(req, res, next) {
  robot.keyTap('f3');
  res.end();
});

Although it depends on which OS you're using if this is going to work as expected.

about 4 years ago · Santiago Trujillo Relatório

0

Not possible from server side. You can include a javascript script in your page which can trigger the event. If you are using jQuery.

var ev = jQuery.Event("keypress");
ev.ctrlKey = false;
ev.which = 37;
$("container").trigger(ev);

Is it possible to trigger a keyboard button with JavaScript?

about 4 years ago · Santiago Trujillo Relatório

0

You can simply use applescript in nodejs, and node-key-sender on other platform.

const os = require('os')
const childProcess = require('child_process')
const { promisify } = require('util')
const ks = require('node-key-sender')  

function hitHotkey (key, modifier) {
    if (os.type() === 'Darwin') {
      if (modifier) {
        return exec(`Script="tell app \\"System Events\\" to keystroke ${key} using ${modifier} down"
        osascript -e "$Script"`)
      } else {
        return exec(`Script="tell app \\"System Events\\" to keystroke ${key}"
        osascript -e "$Script"`)
      }
    } else {
      if (modifier) {
        return ks.sendCombination([modifier, key])
      } else {
        return ks.sendKey(key)
      }
    }
  }
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda