#!/usr/bin/env python from evdev import uinput, ecodes as ec import pygame import pygame.midi from pygame.locals import * import time pygame.init() pygame.fastevent.init() event_get = pygame.fastevent.get event_post = pygame.fastevent.post pygame.midi.init() input_id = 2 print ("using input_id :%s:" % input_id) i = pygame.midi.Input( input_id ) keymap = { 84:ec.KEY_ENTER, 83:ec.KEY_F1, 81:ec.KEY_F2, 79:ec.KEY_F3, 77:ec.KEY_F4, 76:ec.KEY_F5, 75:ec.KEY_ESCAPE, } with uinput.UInput() as ui: going = True while going: events = event_get() for e in events: if e.type in [QUIT]: going = False if e.type in [pygame.midi.MIDIIN]: if e.data2>0: status = 1 else: status = 0 if keymap.has_key(e.data1): ui.write(ec.EV_KEY, code, status) ui.syn() else: print "unknown key",e if i.poll(): midi_events = i.read(10) midi_evs = pygame.midi.midis2events(midi_events, i.device_id) for m_e in midi_evs: event_post( m_e ) del i pygame.midi.quit()