thurse93
Posts: 13
Joined: Sat Mar 23, 2013 4:43 pm

Implementing a single button menu

Sat Jul 27, 2013 11:01 am

Hi Forum!

For my recent project I need to implement a single button selection menu to switch between different states, like a lot of mp3 players used to have. It should work as follows:

-Pressing button -> menu appears which displays current item (= state)
-Pressing button again [multiple times] -> switch to the next [n'th] menu item
-Waiting for a fix amount of time (~ 1 sec)
-Executing a special shell script connected with the menu item
-Menu closes

My trigger is the button of an old gamepad connected via usb and supervised by joyd.

How could this be implemented? Is there even a chance to build a menu like this completely in shellscript (because this is the "language" im used to, i dont know python or C at all....)?

Regards,

thurse

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Implementing a single button menu

Sat Jul 27, 2013 11:13 am

What would BASH scripting be without external programs ?
zenity , dialog and whiptail come to mind.
You could have a look inot raspi-configs source code.


ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

thurse93
Posts: 13
Joined: Sat Mar 23, 2013 4:43 pm

Re: Implementing a single button menu

Sat Jul 27, 2013 11:40 am

Sure, a zenity or xdialog menu would be a nice and simple thing, but how can i control them with just one button?

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Implementing a single button menu

Sat Jul 27, 2013 7:21 pm

Hmm ..
xdotool seems to be what you need.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

thurse93
Posts: 13
Joined: Sat Mar 23, 2013 4:43 pm

Re: Implementing a single button menu

Sat Aug 03, 2013 1:11 pm

Thanks, xdotool was just the right thing. It's kind of a mess, because it involves 4 scripts an 3 temp-files but it works now...

Greetings,

thurse

Return to “General programming discussion”