User avatar
liudr
Posts: 672
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: 33847
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

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.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

User avatar
mooblie
Posts: 65
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: 672
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: 9057
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: 62
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: 65
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: 606
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: 65
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: 33847
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

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).
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

User avatar
liudr
Posts: 672
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: 606
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: 9057
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.

Return to “General discussion”

Who is online

Users browsing this forum: asavah, Google [Bot] and 42 guests