song940 / input-event

:musical_keyboard: Read and parse input device(like mouse, keyboard, joystick and IR-Remote)'s event data.

Home Page:https://npmjs.org/input-event

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mouse doesnt seem to work

teuteuguy opened this issue · comments

Normal ?

mouse.on fails

commented

no implement yet 😄

commented

try again 😄

Hi there,

yes thanks for the update.

I've managed to get it to work, however I've discovered the following problems with this approach.
The event object { tssec, tsusec, type, code, value } is not sufficient to capture mousedown / mouseup events.

By hacking the code manually, in the parse function, if you add:
value: buf.readUInt32LE(12),
btn: buf.readUInt16LE(26),
up: buf.readUInt16LE(28)

This gives you indication as to which button was pressed on the mouse, also with the fact that it is pressend then released.

Do you confirm this ?

commented

pull-request are welcome 😉

I can make a pull-request suggestion, however, I can't seem to find documentation anywhere for my findings ...

How have you found the documentation behind the structure of the /dev/input/event1 ?

Yep, that's the same documentation I've found.

As you can see, if you console.log(buf) in your parse function, there is more data after the number of bytes that you are reading as per the spec.

From another gist, I found hex codes that refer to mouse buttons, 0x110 (left), 0x111 (right), 0x112 (middle)
When console logging the buffer, you can see these appear further down in the buffer in the 26 region.
A 1 or 0 appears in 28 when button is pressed.

Observing this, shows that it works, but I can't find concrete documentation on this.

Do you see what I mean ?

commented

yes, i'll try .

Just tried that. Does not work for me. It actually crashes.

(Note, I don't have keyboard plugged in, only a USB mouse)

code:
var InputEvent = require("input-event");
// var input = new InputEvent('/dev/input/event1');
var input = new InputEvent('/dev/input/mice');

var mouse = new InputEvent.Mouse(input);

// mouse.on('wheel', console.log);
mouse.on('keypress', console.log);
// mouse.on('data', console.log);

Failure:

test-mouse/node_modules/input-event/lib/keyboard.js:18
if(InputEvent.EVENT_TYPES.EV_KEY == ev.type){
^

TypeError: Cannot read property 'type' of undefined
at Mouse. (/root/tmp/test-mouse/node_modules/input-event/lib/keyboard.js:18:43)
at emitOne (events.js:82:20)
at Mouse.emit (events.js:169:7)
at ReadStream. (/root/tmp/test-mouse/node_modules/input-event/lib/index.js:36:10)
at emitOne (events.js:77:13)
at ReadStream.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at ReadStream.Readable.push (_stream_readable.js:110:10)
at onread (fs.js:1743:12)
at FSReqWrap.wrapper as oncomplete

When reverting to /dev/input/even1, it works for data, move but not keypress.
And on movement, only moving the mouse vertically gets detected, not horizontally...