L
L
levenokk2020-06-07 17:45:26
JavaScript
levenokk, 2020-06-07 17:45:26

Is it possible to monitor keypresses in a system in nodeJs?

I want to create a program in nodeJs, and I want it to run a certain action when a key is pressed, but so that the program is in the background, is there any way to monitor this in nodeJs on windows ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dubolom Unicellular, 2020-06-07
@levenokk

ElectronJS , you can create a desktop application using HTML CSS and JS with it, and it works just fine with node, just in the parameters of the electron window, write:

transparent: true, // прозрачность окна
show: false // скрытие ярлыка программы с панели задач

If you use nodejs directly in the main js file (script.js, app.js, main.js, index.js), don't forget to tell electron about it:
webPreferences: {
  nodeIntegration: true
}

And then grab the key (the name of the key the user pressed):
document.addEventListener("keydown", e => { 
  if(e.key == "C"){
    console.log("нажал на C");
  }
}); // также есть еще keypress и keyup

V
Vladimir Korotenko, 2020-06-07
@firedragon

It is possible, write on with binding

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question