2

I have a power key on my keyboard, and I want to run a script when it's pressed.

I looked around and didn't found anything on this, for what I've seen, people always have been satisfied with what logind.conf is offering, here is the interesting part of man logind.conf:

HandlePowerKey=, HandleSuspendKey=, HandleHibernateKey=, HandleLidSwitch=, HandleLidSwitchDocked=
       Controls how logind shall handle the system power and sleep keys and the lid switch to trigger actions such as system power-off or suspend. Can be one of "ignore", "poweroff", "reboot", "halt", "kexec", "suspend", "hibernate", "hybrid-sleep", and "lock". If "ignore", logind will never handle these keys. If
       "lock", all running sessions will be screen-locked; otherwise, the specified action will be taken in the respective event. Only input devices with the
       "power-switch" udev tag will be watched for key/lid switch events.  HandlePowerKey= defaults to "poweroff".  HandleSuspendKey= and HandleLidSwitch= default to
       "suspend".  HandleLidSwitchDocked= defaults to "ignore".  HandleHibernateKey= defaults to "hibernate". If the system is inserted in a docking station, or if
       more than one display is connected, the action specified by HandleLidSwitchDocked= occurs; otherwise the HandleLidSwitch= action occurs.

       A different application may disable logind's handling of system power and sleep keys and the lid switch by taking a low-level inhibitor lock
       ("handle-power-key", "handle-suspend-key", "handle-hibernate-key", "handle-lid-switch"). This is most commonly used by graphical desktop environments to take
       over suspend and hibernation handling, and to use their own configuration mechanisms. If a low-level inhibitor lock is taken, logind will not take any action
       when that key or switch is triggered and the Handle*= settings are irrelevant.

I didn't managed to set bold text in code block (and didn't used quote block since it puts all in a single line and it then clearly unreadable), I then repeat the interesting part here:

Controls how logind shall handle the system power and sleep keys and the lid switch to trigger actions such as system power-off or suspend. Can be one of "ignore", "poweroff", "reboot", "halt", "kexec", "suspend", "hibernate", "hybrid-sleep", and "lock".

Or I am in the wrong way and this is just for keyboard keys, and not power button ?

In any case, previously, it was easy with acpi, one just had to replace the power_button script in /usr/lib/acpid/, isn't there something equivalent for systemd ?

Thanks.

PS: How to change Power button shutdown action to run a script under systemd suggested in comments does not answer my question, as I answered this is to manage power key from keyboard, not power button.

6
  • 5
    Does this answer your question? How to change Power button shutdown action to run a script under systemd
    – Quasímodo
    Jan 17, 2020 at 12:42
  • Thanks but unfortunately not, this is, as many answers I found on the subject, to manage power key from keyboard, not power button...
    – gluttony
    Jan 20, 2020 at 6:47
  • what is the difference of powerKey and powerButton? Jan 23, 2020 at 9:25
  • @gluttony I think you want to capture a button press on your keyboard rather than than the ACPI power button. If I have got this the wrong way round please re-edit your question to make absolutely clear what it is you want to do.
    – roaima
    Jan 23, 2020 at 15:46
  • Thanks @roaima, since my question has been marked as duplicate I've done what stackexchange suggested me, i.e. ask a new question, this is what I did here: unix.stackexchange.com/questions/563603/…
    – gluttony
    Jan 24, 2020 at 9:50

1 Answer 1

0

I didn't see this question is no more set duplicate, I then opened another one for which I found an answer (for openbox at least), since I don't know how to set duplicate I just put the link to the answer here: https://unix.stackexchange.com/a/566910/390900

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .