Out of curiosity I was trying to figure out what format mouse data comes into a linux system as. I found from a little reading that the data comes in on the character device /dev/input/mice. Examining this device with xxd (a command line hex dump program) I can see the patterns for X and Y movement and the 3 button clicks in a string of three bytes. I was under the impression, from research around the good old internet, that there was supposed to be a 4th byte used to represent data about the 4th and 5th buttons (aka scroll wheel). Moving the wheel causes more 3 byte sets to come out of /dev/input/mice, but causes no change in the bytes themselves. A regular pattern of '0800 00' is observed as I move the wheel back and forth. Judging from the fact that I can actually use the wheel in my system, I assume the data must be going somewhere. Is it parsed into a separate device, am I trying to get at the data in the wrong way, or is my system just broken somehow? Any insight would be greatly appreciated.
same here
I experienced the same here... and I am now curious enough to investigate on that, too. Perhaps the gpm sources may help? Iirc the /dev/input/mice outputs ImPS/2 protocol data, converted from your mouse 's protocol if needed. The part of gpm source that handles the ImPS/2 protocol may be interesting... even if I doubt that the implementation of ImPS/2 in gpm is complete or its even aware of scrolling.
Happy Hacking ;)
gibbon_
Scroll wheel info is in /dev/input/event1
You can get more detailed mouse info by reading "struct input_event"s from /dev/input/event#. My mouse is /dev/input/event1, and while scrolling the mouse wheel it returns e->type==REL_WHEEL and e->code==signed movement distance. You can read all the other event types, and find struct input_event, in <linux/input.h>.
Hmm... I somehow don't get
Hmm...
I somehow don't get any events from my mouse even though i got read access and i can open the device just fine.
read() blocks forever.
The same code works just fine with my Keyboard, i don't know what's going on.
Can anyone give me a hint?
Here's the code:
#include <stdio.h>
#include <linux/input.h>
#include <fcntl.h>
int main(int argc, char **argv)
{
int fd;
if ((fd = open("/dev/input/event1", O_RDONLY)) < 0) {
perror("evdev open");
exit(1);
}
struct input_event ev;
while(1) {
read(fd, &ev, sizeof(struct input_event));
printf("value %d, type %d, code %d\n",ev.value,ev.type,ev.code);
}
return 0;
}
write magic sequence to /dev/input/mice
You need to set mouse protocol as ImPS/2 first. By default it is wheelless PS/2. Then packet size becomes equal to 4 and new byte contains "dz" - wheel scroll.
This is done by writing magic sequence to "/dev/input/mice"
See kernel source file drivers/input/mousedev.c for more info.
This is done by writing magic sequence to "/dev/input/mice"
Could you kindly tell us what is the magic sequence ?
Thank you very much.
Sincerely,
Joseph
reading inputs from mouse/keyboard in linux kernel space
Good day! I want to ask if anyone can help me with this problem:
Create a loadable kernel module pcmouse.c that spawns 3 kernel threads upon initialization. Thread 1 is the producer kthread that reads mouse (usb or ps/2) x and y movements and store on 2 separate buffers (bufferx and buffery). Thread 2 is a consumer thread that reads x movements while Thread 3 is another consumer thread that reads y movements. Please decide on the size of the buffer that you will use.
-- we need a code in kernel space that can read inputs from the mouse or keyboard but do not use the open() and read() since this might cause problems in compiling. Thanks