USB Mouse/Keyboard Data Monitoring Using Raspberry Pi
I am working on getting the raw USB mouse or keyboard data using raspberry pi.
To start with, I just decided to grab the data from the Logitech K400R wireless keyboard that I use for my raspberry pi.
This keyboard has the touchpad and size is good, not too small, not too large, and price is very reasonable.
Setup
Install pip:$ sudo apt-get install python-pip python-dev build-essentialInstall evdev module:
$ sudo pip install --upgrade pip
$ sudo pip install --upgrade virtualenv
$ sudo pip install evdevCheck input events:
$ ls /dev/inputIf you do not know which event is mouse or keyboard, follow this.
Install input-utils:
$ sudo apt-get install input-utils
$ lsinput
Python Code
This is the python example code.
Example 1:from evdev import InputDevice, categorize, ecodesExample 2:
dev = InputDevice('/dev/input/event0')
print(dev)
for event in dev.read_loop():
print(event)
from evdev import InputDevice, categorize, ecodesCrate a python script file as below and copy&paste the above code.
dev = InputDevice('/dev/input/event0')
print(dev)
for event in dev.read_loop():
if event.type == ecodes.EV_KEY:
print(event)
nano test.pyRun the python script.
python test.pyPress any buttons on the keyboard or mouse and you will see the outputs in the terminal.
Done!