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;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With