dasstrum
Posts: 5
Joined: Thu Mar 08, 2018 3:10 pm

Push a button to switch between programs (Like Alt+Tab in windows)

Thu Mar 08, 2018 3:19 pm

I am currently planning a project for a picture frame with a 9 inch LCD screen. I want to install a couple buttons at the top of the picture frame to do certain task. I want to run Chromium browser in kiosk mode pointing to an IP address for my camera system running Blue Iris (I have this already figured out and is running on another Pi) I want a button on the top of the picture frame for when pressed, it switches between Chromium in Kiosk mode to a picture slideshow program (Similar to pressing Alt+Tab in windows)

Button 1: When pressed switches between Chromium and picture slideshow

Button 2: Power toggle for the picture frame- shutdown and or boots up raspberry Pi (I have this one figured out already)


I've done a lot of research and found that you can program a button to launch a certain program however I haven't found anything to toggle between programs (like a windows Alt+tab keystroke) Any pointers would be great!

klricks
Posts: 7172
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Push a button to switch between programs (Like Alt+Tab in windows)

Fri Mar 09, 2018 5:27 am

Try installing xdotool. This program will allow you to send keystrokes or mouse move/ clicks etc. by command line or bash files.

Code: Select all

sudo apt update
sudo apt install xdotool
Add the following code to your button press code:

Code: Select all

xdotool key alt+Tab

You probably want to open your 2 (or more) applications and your button code automatically on boot using autostart.

Another option would be to install obconfig and make multiple desktops. Then open one application in each desktop.... then use xdotool -OR- wmctrl to switch between desktops.

Code: Select all

sudo apt install wmctrl
Last edited by klricks on Fri Mar 09, 2018 2:17 pm, edited 2 times in total.
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: Push a button to switch between programs (Like Alt+Tab in windows)

Fri Mar 09, 2018 8:57 am

klricks wrote:
Fri Mar 09, 2018 5:27 am
to install obconfig and make multiple desktops
sudo apt-get install -y obconf
Menu / Preferences / Openbox Configuration Manager / [Number of Desktops] 2 ( and give some name )
i not find any working key combination to use it??
but mouse wheel turn / while mouse over desktop background /
works, even via realVNC
menu and application bar and desktop settings are same for ALL desktops,
but if you have 2 programs running they can be in different displays/workspace as open window.
window header line allow right mouse click new menu option "send to desktop ..."
as the mouse wheel thing only works on desktop background, the program window can NOT be in fullscreeen.

PiGraham
Posts: 3971
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Push a button to switch between programs (Like Alt+Tab in windows)

Fri Mar 09, 2018 10:25 am

Maybe xdotool will be useful.
http://www.semicomplete.com/projects/xdotool/
It's in the official repository but experimenting with it briefly the windowraise and other control functions didn't seem to work
It you can solve that riddle it should allow you to move, set focus, minimise etc any window from a bash script. It looks like it can also send keyboard and mouse events to windows.

klricks
Posts: 7172
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Push a button to switch between programs (Like Alt+Tab in windows)

Fri Mar 09, 2018 2:01 pm

KLL wrote:
Fri Mar 09, 2018 8:57 am
...
i not find any working key combination to use it??
....
Sorry I said wrong tool.
To switch between desktops install wmctrl

Code: Select all

sudo apt install wmctrl
to switch to first desktop use

Code: Select all

wmctrl -s 0
to switch to 2nd desktop etc......

Code: Select all

wmctrl -s 1
See this for more details: viewtopic.php?f=29&t=206538
-------------------------------
Edit: Actually xdotool does have commands to switch desktops.

Code: Select all

xdotool set_desktop 2
Also I think xdotools can send mouse roller and clicks.
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

dasstrum
Posts: 5
Joined: Thu Mar 08, 2018 3:10 pm

Re: Push a button to switch between programs (Like Alt+Tab in windows)

Sun Mar 11, 2018 3:10 pm

Perfect! Thanks for the suggestions... I'll have to give them a try!

dasstrum
Posts: 5
Joined: Thu Mar 08, 2018 3:10 pm

Re: Push a button to switch between programs (Like Alt+Tab in windows)

Mon Mar 12, 2018 10:11 pm

So I was able to get it working using python and pynput to simulate the key presses! Woohoo

CarlosRoberts
Posts: 2
Joined: Sat Apr 09, 2016 7:12 am

Re: Push a button to switch between programs (Like Alt+Tab in windows)

Sat Sep 22, 2018 9:19 pm

Congratulations dasstrum!!!
I was inspired by your project and had to start my own. Came up with my scripts, but sharing yours would be a good idea.
For everyone else, checkout his work at:
https://ipcamtalk.com/threads/blue-iris ... ion.26894/
Keep up with your great ideas!!!
CR
dasstrum wrote:
Mon Mar 12, 2018 10:11 pm
So I was able to get it working using python and pynput to simulate the key presses! Woohoo

Return to “Beginners”