Skip to content

Instantly share code, notes, and snippets.

@riston
Created June 22, 2012 15:43
Show Gist options
  • Save riston/2973580 to your computer and use it in GitHub Desktop.
Save riston/2973580 to your computer and use it in GitHub Desktop.
Reading /dev/psaux stream with nodejs
var fs = require('fs');
var readStream = fs.ReadStream('/dev/psaux');
var mouseMovements = [];
readStream.on('data', function(packet) {
var buf = packet.readInt8(0);
var mouse = {
leftBtn: !!(buf & 1)
, rightBtn: !!(buf & 2)
, middleBtn: !!(buf & 4)
, always: !!(buf & 8)
, xSign: !!(buf & 16)
, ySign: !!(buf & 32)
, xOver: !!(buf & 64)
, yOver: !!(buf & 128)
, xDelta: packet.readInt8(1)
, yDelta: packet.readInt8(2)
};
console.log(mouse);
});
readStream.on('close', function() {
console.log('Closed readstream');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment