User avatar
liudr
Posts: 687
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Shut down rpi with a keyboard key combo

Wed Sep 19, 2018 7:29 pm

I've seen plenty of projects describing how to shut down rpi with a push button connected to a GPIO pin and running a python script to catch the button push. I thought why not setting up a keyboard combo for shutdown or other stuff? If I can do that under GUI, I can replace the real keyboard with an arduino leonardo or micro that can emulate keyboard. I still want a push button on the enclosure but I want this to be emulating keyboard combos. It just sounds clean and I can set up more key combos with the same arduino for other tasks. I know that windows has this feature to link key combos to certain tasks. What about raspbian? Thanks.
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

User avatar
DougieLawson
Posts: 38479
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Shut down rpi with a keyboard key combo

Wed Sep 19, 2018 8:04 pm

I've got a keyboard combo that works in an LXTerminal window.

Press the following keys in order
[S][U][D][O][SPACE][P][O][W][E][R][O][F][F][ENTER]

Don't press the shift or it won't work.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

I'll do your homework for you for a suitable fee.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
mooblie
Posts: 174
Joined: Fri Oct 14, 2016 2:07 pm
Location: The Scottish Highlands

Re: Shut down rpi with a keyboard key combo

Wed Sep 19, 2018 9:14 pm

:D

User avatar
liudr
Posts: 687
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: Shut down rpi with a keyboard key combo

Wed Sep 19, 2018 9:31 pm

What if your GUI is focused on a file browser? Will that key sequence delete an important file without confirmation? What if you're focused on a terminal windows that is running a Python code? :lol:
I'm looking for a method that will initiate a shutdown process regardless which window gets the focus, and what is going on with rpi, just to be clear. The rpi is sealed in a box and you have to type those sequences (followed by ctrl+C when necessary) in work gloves on a vibrating platform possibly in the rain or push a big round button that always shuts the darn thing down. I'm looking for the latter. I've not tried ctrl-alt-del key sequence since I usually do remote access. That might just do the job.
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

DirkS
Posts: 10301
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Shut down rpi with a keyboard key combo

Wed Sep 19, 2018 10:13 pm

liudr wrote: I've not tried ctrl-alt-del key sequence since I usually do remote access. That might just do the job.
By default that starts the taskmanager.

You can change the key mapping by manipulating /home/pi/.config/openbox/lxde-pi-rc.xml (at least in standard Raspbian desktop)
For more details try searching for 'LXDE key mapping' and / or 'openbox key mapping'

grininmonkey
Posts: 145
Joined: Mon Jul 30, 2018 3:44 pm

Re: Shut down rpi with a keyboard key combo

Wed Sep 19, 2018 10:21 pm

To the OP... in my primary computer which uses I3-Gaps (lightweight window manger) I define many key combos to do things which do not interfere with vim or any focused window, etc..... I haven't looked at it, but I would think there is a something similar with openbox on the PI where you can define a leader/mod/prefix key combo following something like the <END> key which would execute shutdown or whatever you like in the form of executing a shell command bound to your defined key-combo

Google for something along those line for which ever window manger and/or desktop environment you might be running?

User avatar
mooblie
Posts: 174
Joined: Fri Oct 14, 2016 2:07 pm
Location: The Scottish Highlands

Re: Shut down rpi with a keyboard key combo

Wed Sep 19, 2018 11:31 pm

Is this any use:

https://www.raspberrypi.org/forums/view ... 1#p1280779

It won't physically remove power, but nothing internal to the Pi will do that without extra/external hardware. However it does put the Pi into a state whereby you can just safely "pull the plug".

BTW: Note that the SAME switch will start up the Pi again. Handy. And being just a push button switch it can be a huge weather-proof glove-friendly one if you wish.

k-pi
Posts: 930
Joined: Sun Feb 12, 2017 1:46 pm
Location: Upper Hale, Surrey, UK.

Re: Shut down rpi with a keyboard key combo

Thu Sep 20, 2018 9:33 am

Rather than sudo poweroff, I prefer sudo halt -p. :D

User avatar
mooblie
Posts: 174
Joined: Fri Oct 14, 2016 2:07 pm
Location: The Scottish Highlands

Re: Shut down rpi with a keyboard key combo

Thu Sep 20, 2018 4:12 pm

k-pi wrote:
Thu Sep 20, 2018 9:33 am
Rather than sudo poweroff, I prefer sudo halt -p. :D
The pros and cons of each being...?

User avatar
DougieLawson
Posts: 38479
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Shut down rpi with a keyboard key combo

Thu Sep 20, 2018 4:26 pm

mooblie wrote:
Thu Sep 20, 2018 4:12 pm
k-pi wrote:
Thu Sep 20, 2018 9:33 am
Rather than sudo poweroff, I prefer sudo halt -p. :D
The pros and cons of each being...?
The halt option causes more wear on the space bar to achieve exactly the same outcome (since they are synonymous).
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

I'll do your homework for you for a suitable fee.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
liudr
Posts: 687
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: Shut down rpi with a keyboard key combo

Fri Sep 21, 2018 1:30 am

mooblie wrote:
Wed Sep 19, 2018 11:31 pm
Is this any use:

https://www.raspberrypi.org/forums/view ... 1#p1280779

It won't physically remove power, but nothing internal to the Pi will do that without extra/external hardware. However it does put the Pi into a state whereby you can just safely "pull the plug".

BTW: Note that the SAME switch will start up the Pi again. Handy. And being just a push button switch it can be a huge weather-proof glove-friendly one if you wish.
Great! That's better than a keyboard combo. It's like a real power button (I know the part RPI can't power itself off)! BTW, I will use a 5V power bank with a bypass so it can be charged and supply 5V to RPI instead of only doing one of the two. Then I will hack the power bank to connect its power switch to an on/off switch on the enclosure.
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

k-pi
Posts: 930
Joined: Sun Feb 12, 2017 1:46 pm
Location: Upper Hale, Surrey, UK.

Re: Shut down rpi with a keyboard key combo

Fri Sep 21, 2018 11:34 am

:lol:
DougieLawson wrote:
Thu Sep 20, 2018 4:26 pm
mooblie wrote:
Thu Sep 20, 2018 4:12 pm
k-pi wrote:
Thu Sep 20, 2018 9:33 am
Rather than sudo poweroff, I prefer sudo halt -p. :D
The pros and cons of each being...?
The halt option causes more wear on the space bar to achieve exactly the same outcome (since they are synonymous).
:D But I often script mine ./off :mrgreen:

DirkS
Posts: 10301
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Shut down rpi with a keyboard key combo

Fri Sep 21, 2018 12:03 pm

k-pi wrote:
Fri Sep 21, 2018 11:34 am
:lol:
DougieLawson wrote:
Thu Sep 20, 2018 4:26 pm
mooblie wrote:
Thu Sep 20, 2018 4:12 pm


The pros and cons of each being...?
The halt option causes more wear on the space bar to achieve exactly the same outcome (since they are synonymous).
:D But I often script mine ./off :mrgreen:
I actually use <ctrl+r>po<enter> :shock:
Just 4 key hits and no space bar.

ch0rtle
Posts: 2
Joined: Sat Nov 16, 2013 11:53 pm

Re: Shut down rpi with a keyboard key combo

Tue Feb 25, 2020 10:25 pm

I stumbled upon this while looking for a similar solution. The Pi is driving a Looking Glass Display, so while not headless, the desktop isn't easy to read. The key sequence WINDOWS>UP>ENTER>ENTER seems to work from different places. Basically a quick way to select the menu option.
Not sure if that's scriptable, but maybe it helps someone. Cheers.

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

Re: Shut down rpi with a keyboard key combo

Tue Feb 25, 2020 11:29 pm

ch0rtle wrote:
Tue Feb 25, 2020 10:25 pm
I stumbled upon this while looking for a similar solution. The Pi is driving a Looking Glass Display, so while not headless, the desktop isn't easy to read. The key sequence WINDOWS>UP>ENTER>ENTER seems to work from different places. Basically a quick way to select the menu option.
Not sure if that's scriptable, but maybe it helps someone. Cheers.
With the latest update to Raspbian [Ctrl] [Alt] [Del] will now bring up the shutdown menu.
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

LTolledo
Posts: 3058
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: Shut down rpi with a keyboard key combo

Wed Feb 26, 2020 9:52 am

klricks wrote: With the latest update to Raspbian [Ctrl] [Alt] [Del] will now bring up the shutdown menu.
I've just updated/full-upgraded now my RPi4B-4G Raspbian Buster with full desktop.....
immediately after that everytime I do [Ctrl] [Alt] [Del]..... the Task Manager keeps popping up .

however...... upon rebooting.....
the Shutdown options window appears....when [Ctrl] [Alt] [Del] is pressed.... so that confirms it

this, however, is not the case with Raspbian Stretch with full desktop
immediately after update/full-upgrade and after rebooting.... the Task Manager keeps popping up when [Ctrl] [Alt] [Del] is pressed.
Last edited by LTolledo on Wed Feb 26, 2020 11:06 am, edited 1 time in total.
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

gsh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1525
Joined: Sat Sep 10, 2011 11:43 am

Re: Shut down rpi with a keyboard key combo

Wed Feb 26, 2020 10:57 am

My solution is to edit /etc/xdg/openbox/lxde-pi-rc.xml

Add the following near one of the other keybindings...

Code: Select all

<keybind key="A-C-O">
  <action name="Execute">
    <command>poweroff</command>
  </action>
</keybind>
<keybind key="A-C-R">
  <action name="Execute">
    <command>reboot</command>
  </action>
</keybind>
Then reboot... Now you can user Ctrl-Alt-O for poweroff or Ctrl-Alt-R for reboot
--
Gordon Hollingworth PhD
Raspberry Pi - Director of Software Engineering

LTolledo
Posts: 3058
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: Shut down rpi with a keyboard key combo

Wed Feb 26, 2020 11:08 am

gsh wrote: Add the following near one of the other keybindings...
Code: Select all

<keybind key="A-C-O">
<action name="Execute">
<command>poweroff</command>
</action>
</keybind>
<keybind key="A-C-R">
<action name="Execute">
<command>reboot</command>
</action>
</keybind>
Then reboot... Now you can user Ctrl-Alt-O for poweroff or Ctrl-Alt-R for reboot
I take this is applicable to stretch as well?
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

gsh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1525
Joined: Sat Sep 10, 2011 11:43 am

Re: Shut down rpi with a keyboard key combo

Wed Feb 26, 2020 11:10 am

YMMV
--
Gordon Hollingworth PhD
Raspberry Pi - Director of Software Engineering

LTolledo
Posts: 3058
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: Shut down rpi with a keyboard key combo

Wed Feb 26, 2020 11:12 am

I'll take that as a "yes" ;)
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

tpylkko
Posts: 406
Joined: Tue Oct 14, 2014 5:21 pm

Re: Shut down rpi with a keyboard key combo

Wed Feb 26, 2020 12:13 pm

doesn't raspbian/rpi have the magic sysrq? I have never tried, but this is what corresponds to "alt+ctrl+del" to reboot in case of a lock down on linux computers. Never tried it on rpi...

edit: in case some one does not know what this is about:
https://en.wikipedia.org/wiki/Magic_SysRq_key

User avatar
DougieLawson
Posts: 38479
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Shut down rpi with a keyboard key combo

Wed Feb 26, 2020 12:26 pm

The RPF kernel does have magic sysrq set.

[R][E][I][S][U][B]
is the magic password.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

I'll do your homework for you for a suitable fee.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Return to “General discussion”