--Using the USB mouse
As explained in stackoverflow, the mouse information is in /dev/input/mice
. Reading and parsing the three bytes of information is straighforward. The test program just prints whatever the mouse sensors read. The x,y information returned is a delta_x and delta_y. In a real application, the mouse should be read at a known rate and the speed scaled, then (usually) numerically integrated to give position on the screen. In this test program, the mouse-read blocks. You may need to add code to make the device non-blocking.
//needed for nonblocking read() int flags = fcntl(fd, F_GETFL, 0); fcntl(fd, F_SETFL, flags | O_NONBLOCK);
--Reading keyboard keycodes
As explained in The Linux Daily, keyboard keycodes can be read from /dev/input/eventx
. Where 'x' is some digit. The program
keyboard.c requires you to input the device location as a parameter, then
prints keycodes.
Copyright Cornell University February 2, 2017