Viewing 1 post (of 1 total)
  • Author
  • lorigio
    Post count: 1

    Hi i’m trying to control emulationstation using python as keyboard. I have this code

    import time
    from evdev import uinput, ecodes as e
    def buttonEventHandler ():
       print "keypress"
       with uinput.UInput() as ui:
          ui.write(e.EV_KEY, e.KEY_UP, 1)   
          ui.write(e.EV_KEY, e.KEY_SPACE, 0)
    def main():
         while True:
    if __name__=="__main__":

    It works only if i first plug a real keyboard then i can disconnect the keyboard and the script starts working and i can see emulationstation reacting when i send the keys from the script. How can i make it working without plug a keyboard first?

    I also tried with a modified version of retrogame but nothing

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <unistd.h>
    #include <fcntl.h>
    #include <poll.h>
    #include <signal.h>
    #include <sys/mman.h>
    #include <linux/input.h>
    #include <linux/uinput.h>
    int main(int argc, char *argv[]) {
    // Retrogame normally uses /dev/uinput for generating key events.
    	// Cupcade requires this and it's the default.  SDL2 (used by
    	// some newer emulators) doesn't like it, wants /dev/input/event0
    	// instead.  Enable that code by changing to "#if 0" above.
        int fd;
        struct input_event     keyEv, synEv; // uinput events
    	if((fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK)) < 0)
    		err("Can't open /dev/uinput");
    	struct uinput_user_dev uidev;
    	memset(&uidev, 0, sizeof(uidev));
    	snprintf(, UINPUT_MAX_NAME_SIZE, "retrogame"); = BUS_USB;  = 0x1; = 0x1; = 1;
    	if(write(fd, &uidev, sizeof(uidev)) < 0)
    		err("write failed");
    	if(ioctl(fd, UI_DEV_CREATE) < 0)
    		err("DEV_CREATE failed");
    	// Initialize input event structures
    	memset(&keyEv, 0, sizeof(keyEv));
    	keyEv.type  = EV_KEY;
    	memset(&synEv, 0, sizeof(synEv));
    	synEv.type  = EV_SYN;
    	synEv.code  = SYN_REPORT;
    	synEv.value = 0;
        keyEv.code = 97;
        for(int i=1; i>= 0; i--) { // Press, release
            keyEv.value = i;
            write(fd, &keyEv, sizeof(keyEv));
            usleep(10000); // Be slow, else MAME flakes
            write(fd, &synEv, sizeof(synEv));
        while (1 == 1)
        ioctl(fd, UI_DEV_DESTROY); // Destroy and
        close(fd);                 // close uinput    

    I used 97 on keyEv.code because i have
    <input name=”a” type=”key” id=”97″ value=”1″ />
    on es_input.cfg is it right?

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.