Skip to content

Get 'keydown' and 'keyup' events in nodejs on X11 by parsing the output of `xev`.

Notifications You must be signed in to change notification settings

twitchard/nodejs-xev-emitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Get keyup and keydown on Linux

Natively, node.js only gives you the 'keypress' event. It doesn't give you 'keyup' and 'keydown' events.

An alternative, if you are running a Linux desktop, is to parse the output of the xev command, which opens up a window and outputs all the X events that happen inside.

That's what this does.

Usage

Installation

npm install xev-emitter
// example.js
const xevEmitter = require('xev-emitter')(process.stdin)
xevEmitter.on('KeyPress', (key) => {
    console.log(key, 'was pressed')
})

xevEmitter.on('KeyRelease', (key) => {
    console.log(key, 'was released')
})
$ xev | node example.js
h was pressed
h was released
e was pressed
e was released
l was pressed
l was released
l was pressed
l was released
o was pressed
o was released

About

Get 'keydown' and 'keyup' events in nodejs on X11 by parsing the output of `xev`.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published