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

    Shutdown RetroPie/Pi using OSMC Remote Control Button

    Scheduled Pinned Locked Moved Help and Support
    osmc remotedetect keystrok
    5 Posts 1 Posters 859 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.
    • S
      serenity
      last edited by

      Hello,

      This is my first post.

      I am trying to restart Retropie using an OSMC remote home button to calls a bash script (not using the emulation station menu option). I think the home button issues a standard keyboard ”Escape” keystroke if I am not mistaken. I have been trying to do this for the past 3 days but to no avail.

      I managed to do a similar thing easily in Raspbian by editing “Openbox” keyboard shortcut file but retropie doesn’t seem to have Openbox. I even tried to install openbox but it didn’t work. I know retropie is built on raspbian lite but I don’t want to go through the process of installing pixel desktop, openbox and such.

      I tried several solution listed below and I know one of them should work but I couldn’t manage to do it and need help.

      1. Bash & Python
        I managed to read keystrokes but only in Terminal and not in Retropie GUI
      2. Xbindkeys
        Seems to need X windows or such
      3. Tkinter
        Like Bash & Python Worked in Terminal
      4. PyGame
        Worked on raspbian but required a window to be drawn and this will cause issues in retropie
      5. Finally tried /dev/input/by-path approach it seemed crude and should work but it didn’t for some reason
        I think one of the above hold the solution but I couldn’t nail it. I would appreciate a working code samples that will let me accomplish this task.

      Thanks in advance

      1 Reply Last reply Reply Quote 0
      • S
        serenity
        last edited by

        Touch question I reckon.
        I managed to solve the issue using the /dev/input/by-path approach.
        I have found a script online and adapted it.I will post it shortly.

        1 Reply Last reply Reply Quote 0
        • S
          serenity
          last edited by

          Here is the script I came up with. I used a base script for the internet and adapted it to my needs. I also added ability to find keyboards rather than having to input them manually into script and also added threading so you can monitor all keyboards in background.

          1 Reply Last reply Reply Quote 0
          • S
            serenity
            last edited by serenity

            # code block
            
            #!/usr/bin/env python
            
            import string
            import os
            import sys
            import time
            import threading
            
            # pip install evdev
            from evdev import InputDevice
            from select import select
            
            # Set function to be called for each keyboard
            def keyDetectFunc( fullpath ):   
                # look for a /dev/input/by-id/usb...kbd or something similar
                #DEVICE = "/dev/input/by-id/usb-USB_USB_Keyboard-event-kbd"
                DEVICE = fullpath
            
                dev = InputDevice(DEVICE)
            
                while True:
            
                    # wait for keypad command
                    r, w, x = select([dev], [], [])
            
                    # read keypad        
                    for event in dev.read():
                        if event.type==1 and event.value==1:
                            # do something with this key press
                            print ("KEY CODE: ", event.code)
                            if event.code == 1:
                               print ("KEY CODE: ", event.code)
                               os.system('sudo shutdown -r now')
                return;
            
            
            # Return list of all connected input devices
            path = "/dev/input/by-id/"
            dirs = os.listdir(path) # returns list
            
            # This would get all files in dir and filter out Keyboards only
            for file in dirs:
               if ("Keyboard" in file) or ("kbd" in file):
                print file
                keyfile = file
                fullpath = path + file
                
                #Call detection funtion in background
                keydetect_thread = threading.Thread(target=keyDetectFunc, args=(fullpath,))
                keydetect_thread.start()
            
            1 Reply Last reply Reply Quote 0
            • S
              serenity
              last edited by serenity

              Also you need to install the following for code to work:
              sudo apt-get install python-dev python-pip gcc
              sudo apt-get install linux-headers-$(uname -r)
              sudo pip install evdev

              Note it worked without installing the header i.e 2nd satement

              Then you can call it on start up via a cron such as:
              @reboot python /home/pi/scripts/keyreboot.py &

              Remember to give the file execution permisions

              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.