RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    Mouse emulation using keyboard (arrow keys) for scummvm

    Scheduled Pinned Locked Moved Help and Support
    scummvmmouseemulationkeyboard
    5 Posts 1 Posters 2.5k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      joyrider3774
      last edited by

      Hi,

      Does there exist such a thing as a keyboard mouse emulator ? basically i have a picade and it would be nice if i could control the mouse pointer in scummvm using the arrow keys of the keyboard (my joystick is attached to a keyboard controller so it acts as a keyboard). Something like pressing a button + arrow keys would move the pointer and 2 keys for left an right click.

      I'm not sure if any such software exists, i've seen mouse emulators for keyboards but i was wondering if it ever has been done using keynoard ? I tried the forum search but did not see anything directly nor did my google search

      1 Reply Last reply Reply Quote 0
      • J
        joyrider3774
        last edited by

        just found this http://tjjr.fi/sw/python-uinput/

        Looks pretty easy using that library to create a uinput mouse device, i 'm goana experiment with it tonight and see if i can whip up a little python script.

        Basically what i'll try to do is create a python script that listens for a specific keypress (a modifier key) while this key is pressed and i move the joystick on my picade i'll move the mouse using that library and when 2 (or 3) other keys are pressed they act as a left / middle / right mouse click. I think if the scummvm picks up the mouse input deivce using that library i should be able to create something like this.

        Will let you guys know if it worked out or not

        1 Reply Last reply Reply Quote 0
        • J
          joyrider3774
          last edited by joyrider3774

          Hey guys,

          i got something working in python using python-evdev :)

          the mouse movement and button presses work and i added a mapped key for accessing the menu from scummvm. Here you can choose quite or change options about the game or save / load etc. In some games it loads a menu ingame but in most i tested it loads the scummvm menu.

          the python scripts needed are available here on github.

          here's how to use it when using ssh for testing (at the end of the post there's an explanation on how to use with a script so that it runs when scummvm runs and quits when scummvm quits)

          you basically start by running
          sudo python listdevices.py

          it will list all /dev/input/evenX devices with their name location etc. you need to run this to figure out your keyboard that is used for the picade or any other keyboard. On my picade the one i need is ('/dev/input/event0', 'Arduino LLC Arduino Leonardo', 'usb-3f980000.usb-1.3/input2') make memory of device location (/dev/input/event0) that's what you need later on.

          then you have to edit the "keyboardinputdevice" variable in both findoutkeycodes.py and keyboardmouseemulator.py
          so in my case i had to write keyboardinputdevice = '/dev/input/event0'

          next step you run your edited findoutkeycodes.py file like so
          sudo python findoutkeycodes.py and you press your joystick up / down / left / right as well as pressing 4 buttons 3 for left / middle / right mouse button and one for the menu. Note down the numbers it writes on a piece of paper also make sure not to use ESC for the button you want to display the menu because some games actually use the esc key.

          Once you have found out and writen all the codes on a paper press CTRL-C to quite the python script.

          Now you have to edit the button mappings for the mouse in keyboardmouseemulator.py you either write down the codes you wrote on the piece of paper or use the keycode names like i did (listdevices.py prints them out).

          Once you have done that start the python script by running
          sudo python keyboardmouseemulator.py then start scummvm using your picade the normal way (so while this script is running over ssh). If you have done everything right using the joystick on picade (or the corresponding button presses on the keyboard) you'll see the mouse moving and pressing the buttons you assinged for left / right / middle button should also work as well as the button for accessing the menu in scummvm.

          Do note the buttons you press on your picade still get registered by scummvm for example if you had mapped the menu to the esc key, scummvm will still register esc as being pressed as well as the F5 key (= menu key normally in scummvm) and games using the esc key will register it as well some of them quiting.

          By default i have mapped the picade like this:
          joystick = mouse movement:
          bottom left button = mouse left
          bottom middle button = mouse middle
          bottom right button = right button
          top left button = menu key.

          to run the script when you start a game in your emulationstation or attract menu and quit when emulation station quits, create an sh script more or less like this (adopt paths if needed). Bascially it starts the python mouse emulator script which does an endless loop (so that's why i specify &) then i run scummvm passing the parameters passed to the script and lastly when scummvm quits the python script gets killed. So this way the keyboard mouse emulator is only running when scummvm is running

          #!/bin/bash
          sudo python /home/pi/scripts/keyboardmouseemulator.py &
          /opt/retropie/emulators/scummvm/bin/scummvm $@
          sudo ps aux | grep -i keyboardmouseemulator.py | awk '{print $2}' | xargs sudo kill -9

          then change your configs for your frontend(attract mode / emulation station) so it starts this script instead of the scummvm binary directly

          i tried blocking input from other keys which works but if you kill the script the lock remains and the joysticks / picade controls don't seem usuable anymore so am not going to try that anymore. not sure how i can go around that yet (this is not included in the script atm only in my local test version)

          i must say i'm quit surprised at how good it works with my picade & scummvm although not all games work i'm quite happy with it already.

          Anway goana try some more games now in scummvm using my picade

          edit: been testing some games, a few of them need you to press f5 in game, the trick is to press the menu button move the mouse with the joystick to resume then press and hold the menu key and the press the key for left mouse button (on resume) and releasing the menu button when the menu has gone ... the games start then, goblins is such an example and i had a few others as well

          another edit: some games can use both keyboard and mouse. Those don't work that good because when you press up or down or whatever on your joystick on the picade. The up / down etc arrow keys that it registers using the keyboard encoder in the picade are not blocked and your basically using the mouse (emulation) and keyboard (up / down) etc at the same time which makes it impossible to use it in those games.
          I'll try looking again on grabbing the input completely by pressing another toggle button that grabs / ungrabs (= blocks /unblocks the keyboard keys that normally get used when using the joystick) the only thing you have to watch out for is that you don't forget to release the grab before quiting scummvm or the keyboard encoder is blocked completly until a reboot. Will see how that goes tommorow, it should at least make the games that both use a keyboard and mouse (for movement / selections) playable because you'll be able to block the keyboard completely.

          some games seem to use double right mouse click, or at least i think so to show the inventory, but don't register well i had to press the button for right mouse click quickly after each other before i could the iventory, it's a hit & miss.

          1 Reply Last reply Reply Quote 2
          • J
            joyrider3774
            last edited by

            guys, the emulator currently does not work correctly getting the menu to show up was luck because one of the keys i used is ctrl but in my current version (not uploaded to github yet) i got it working now.

            I also modified the code / working quite a bit and the keys from your keyboard / encoder are not registered anymore. Basically i added a switch between either your keyboard encoder / keyboard input or mouse input with the keyboard / encoder disabled you can (de)activate the mouse mode using 2 buttons you have to choose if they are pressed at the same time mouse mode becomes active and when you press them again your encoder / keyboard gets activated again. and the controls don't stay locked anymore.

            This also means you can now run this emulator at startup of retropie and activate it whenever you like. I havent tested this but i wonder if it will work in the drastic emulator now.

            I still have to change a few things and then i'll upload the new version.

            Games that had problems before (the ones that could use keyboard / mouse simultaniosly) now work.

            I'll keep you guys posted

            1 Reply Last reply Reply Quote 0
            • J
              joyrider3774
              last edited by

              ok i finally uploaded everything and made a readme on github. Everything works now, when mouse mode is active the keys from your buttons are not registered anymore and you can switch between mouse mode and your normal input method. you specify and remap existing keys of your encoder specifically for use in mouse mode (you tell it if i press this button which is key CTRL for example then send key F5 instead). You can specify 6 keys like this.

              i did not find a game yet that did not work with this version, my readme needs work though but it's a rather long readme for something simple to setup

              1 Reply Last reply Reply Quote 0
              • First post
                Last post

              Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

              Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.