Keyboard shortcut to switch monitors?

I have a laptop running Lubuntu 23.04 connected by HDMI to a TV. I can use Preferences > LXQT Settings > Monitor Settings to switch between the laptop screen and the TV but so far I can’t find a keyboard shortcut that works.

(Super + P does nothing. Same with F4 and F5 on external keyboard, and Fn+F4 and Fn+F5 on laptop keyboard.)

I’ve looked in the manual and online but without luck so far.

hi there, with both connected and making sure it switches manually first to make sure it’s working, copy and paste this lot into a terminal, press enter then let me know if it switches for you, repeat to see if it switches back too:

#Toggles between two screens. Assuming only one external screen is connected

monitors=`xrandr | grep -P ' connected' | grep -o '^[^ ]*'`
set -- "$monitors"
#monArr contains an array of the id's of the connected screens
declare -a monArr=($*)

#onMon holds the id of the *first* on screen found
onMon=`xrandr --listmonitors | head -2 | grep -oP "[a-zA-Z]*-[0-9]$"`

#offMon holds the id of the other monitor, which is not on
if [ "$onMon" = "${monArr[0]}" ]


#Switches the on screen off and vice versa
xrandr --output $offMon --auto --output $onMon --off
1 Like

Thanks for the suggestion But before I try these commands maybe I should mention a problem I have re “switching manually” (if that means using the Monitor Settings app), in case it’s relevant.

When I have Lubuntu outputting to just one screen (either laptop or TV) and I try to use Monitor Settings > Fast options to switch to the other screen, it doesn’t do anything. I first have to change to one of the two-screen options (either Unified or Extended) and only then can I change to just one screen.

E.g. it’s just on the TV (Only second) and I want to change to the laptop screen (Only first). Selecting Only First does nothing, even if I click Apply after. So I click on Unified, get the image on both screens, and then I click on Only first and it changes to just the laptop screen.

thats a bit odd, never tried it but i’ll give it a go when i get time. Back to the original question, keyboard shortcut to switch 2 displays. Well, nothing easy really, there’s quite a few posts around asking the same over the years for lxqt, and it appears a bash script would be needed, then a shortcut assigned for a keyboard combination referencing the script (and if it was me, i’d assign a gesture as well just for the sake of it!)., the bit i posted was a bash script content from a lubuntu thread on a Ubuntu forum.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.