How to add volume control in stand alone emulators

In the main menu and Retroarch, you can use shift + select/start to control the volume but in the stand alone emulators or other apps you can’t. So is there a way to add this feature ? I have no knowledge about coding so i don’t know what to do. Sorry for my poor English.

I’m no expert, but I assume it’s not an easy change. When you use the buttons in RetroArch, it’s a RA setting that changes. So you’d need the same for every standalone emulator.

Someone wrote a script to do this for Pico-8. It sets up hooks for the volume buttons and then launches Pico-8, all within the same script. It’s essentially a wrapper for Pico-8.

The same thing could be adapted to launch anything else, and assuming you didn’t need those buttons for the thing you were launching (like Retroarch), it should work.

Might be nice if someone tweaked this script a bit to be more generic and maybe take a single parameter for the target application to launch. Then it could be used in scripts and could take over the volume keys for anything.

It would be even nicer if this was done properly, as a system service (and maybe more efficiently). Just a guess, but I imagine most of us would want the volume buttons to work most of the time. If there was a way to override them (disable the service via a command when launching the target application), that would probably make more sense. Then if you wanted to use the volume buttons for something else, you could, but by default they would actually control the volume.

Anyhow, this might be useful if someone wants to tinker:

1 Like

There’s no big change !

Look there :

The script enables you to control volume via select + left/right and brightness via select + up/down everywhere.

I personnally changed the values of amount volume modification to 4 because 20 is too much.

And I also inverted the brightnessTool.Further() and brightnessTool.StepBack() , so select+up increase and select+down decrease brightness.

2 Likes

i tried it, but it doesn’t work out for me

What have you done exactly ?

i use command promt to ssh to the device and do the following lines just like the guide said

sudo pip install evdev

git clone https://github.com/zfteam/gameshell_backlight_hotkey.git

cd gameshell_backlight_hotkey

cp backlight_hotkey.py ~/launcher/sys.py/

cp -r tools ~/launcher/sys.py/

sudo nano /etc/rc.local

a new window pop up and i input this to the last line

nohup python /home/cpi/launcher/sys.py/backlight_hotkey.py &

and before it exits, it asks me the file type that i want to save, so i choose DOC format

and reboot the system

i tried to repeat all of these steps, trying to find out what i did wrong but it still didn’t work out for me

this is what the rc.local file looks like after editting

It seems to be fine.

Do you keep select pressed, then press a direction ?

i keep pressing the select button and then pressing the arrow key in any direction but nothing change

If you’re saving as a doc format, ie MS word I’m guessing, it probably isn’t going to work.

Try using notepad++

Or better yet, use nano to edit the file from within a terminal session.

If you’re still having problems, I’ll just upload my files so you can just upload them to your Gameshell.

1 Like

Tried with notepad ++, nothing changed, i didn’t know why but thank you

1 Like

Did you upload your amended file back to the correct place?
By nothing changed, are you saying that when you download the file again, it doesn’t have the change?
Hmm. Try and use nano to edit the file from within a command line/ssh/terminal window. This is what I use whenever adding lines of code.
I couldn’t find any simple nano tutorials on these forums, so I just looked one up for you:

1 Like

IMPORTANT!! BACK UP BEFORE COPYING ANY SYSTEM FILES!! If you don’t do this correctly, your device may not start up, and you will need to reflash your system!!

I’ve just uploaded my rc.local file, pre edited.

Copy it to the etc directory.

This is basically Step 2 of the readme file. I would however strongly recommend you use nano or another editor to edit the file yourself.

2.add reboot command shell

"sudo nano /etc/rc.local" open rc.local file and input this to the last line

nohup python /home/cpi/launcher/sys.py/backlight_hotkey.py &

IMPORTANT!
You WILL need permission attributes set to this:
-rwxr-xr-x
Change it using the command,

chmod 755 /etc/rc.local

Just for your information:
rwx,r-x,r-x = 755
rwx = 7, read, write, and execute
r-x = 5, read and execute
r-x = 5, read and execute

2.add reboot command shell

"sudo nano /etc/rc.local" open rc.local file and input this to the last line

nohup python /home/cpi/launcher/sys.py/backlight_hotkey.py &

The only other changes I’ve made are to backlight_hotkey.py, changing the direction of the brightness adjustment hotkey, and the incremental step size for volume. It was mentioned by another user, @Dowdheur, but not directly printed out.

import time
from evdev import InputDevice
from select import select
from tools.brightness_tool import BrightnessTool
import alsaaudio

m = alsaaudio.Mixer()
sound_volume=m.getvolume()[0]
# print("cur aound volume:%d",sound_volume)

dev = InputDevice('/dev/input/event1')

select_press=False
while True:
    select([dev], [], [])
    for event in dev.read():
        # print "code:%s value:%s" % (event.code, event.value)
        if (event.code==57 and event.value==1):
            select_press=True
            # print("sel press")
        elif(event.code==57 and event.value==0):
            select_press=False
        
        if(select_press==True and event.code==103 and event.value==1):
            brightnessTool = BrightnessTool()
            brightnessTool.Further()
            del brightnessTool
        elif(select_press==True and event.code==108 and event.value==1):
            brightnessTool = BrightnessTool()
            brightnessTool.StepBack()
            del brightnessTool
        elif(select_press==True and event.code==105 and event.value==1):
            sound_volume=sound_volume - 4
            if(sound_volume<0):
                sound_volume=0
            try:
                m = alsaaudio.Mixer()
                m.setvolume(sound_volume)
            except Exception,e:
                print(str(e))
        elif(select_press==True and event.code==106 and event.value==1):
            sound_volume=sound_volume + 4
            if(sound_volume>100):
                sound_volume=98

            try:
                m = alsaaudio.Mixer()
                m.setvolume(sound_volume)
            except Exception,e:
                print(str(e))

        
            


1 Like

Wow, cool, I was annoyed by the jumps in volume, so I’ll try that out when I get the chance.

2 Likes

Mh, tried doing that just now, but it just wouldn’t work. :confused:
Guess that feature will have to wait for my custom OS image.

1 Like

Oh? Which part? It sounds like you got the script to initially work. Are you talking about inverting the brightness hotkey and reducing the volume increments? (From 20 to 4 for the record)
You might need to reinitialise it. The file I uploaded includes some modified lines compared to the one you git pulled initially.
Just follow the steps again, after having modified the file.
And don’t forget to reboot.

I accidentally put your rc.local on my device as I didn’t realize that I need the part after that to modify the increments. I don’t know if that caused it, but after rebooting nothing happened.

2 Likes

Ah dang it!!
By nothing happened, do you mean your device didn’t start up?? Or hopefully, nothing changed.
I’ve put a big disclaimer to back up in case any users in future end up doing this, and forget to change permissions etc.
I’ll put in the command to change the attributes too, to make it easier. I’m so sorry! Hopefully you had a backup.

Meantime, can you still SSH into your Gameshell? If you can, try this:

chmod 755 /etc/rc.local

Also another thought. If you got to the stage where you could adjust the volume using this alternative hook, you shouldn’t need go copy the rc.local file, as you’ve already got it working.

1 Like

finally, i got it. The part that did wrong was save it in DOC format. When saving the rc.local file, you just need to hit enter to save it, not in DOC nor MAC format. I’m a dummy dumb, thank you for all of your helps

1 Like