Created
June 22, 2012 15:43
-
-
Save riston/2973580 to your computer and use it in GitHub Desktop.
Reading /dev/psaux stream with nodejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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