I'd like to do a program that takes input from HIDs attached to a linux system and generates MIDI from those. I'm ok on the MIDI side, but I'm struggling on the HID side of things. While this approach works ok (taken from here):
#!/usr/bin/python2
import struct
inputDevice = "/dev/input/event0" #keyboard on my system
inputEventFormat = 'iihhi'
inputEventSize = 16
file = open(inputDevice, "rb") # standard binary file input
event = file.read(inputEventSize)
while event:
(time1, time2, type, code, value) = struct.unpack(inputEventFormat, event)
print type,code,value
event = file.read(inputEventSize)
file.close()
it gets high on CPU usage when there are lots of events; especially if tracking the mouse, large movements take almost 50