我环顾四周,没有在上面发现任何东西,因为我看到的是,人们总是对logind.conf提供的内容感到满意,下面是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.然后我在这里重复一个有趣的部分:
控制logind应如何处理系统电源和睡眠键以及盖子开关,以触发系统断电或暂停等操作。可以是“忽略”、“断电”、“重新启动”、“停止”、"kexec“、”暂停“、"hibernate”、“混合睡眠”和“锁”。
还是我走错了路,这只是为了键盘键,而不是电源按钮?
在任何情况下,在以前的情况下,使用acpi很容易,只需替换/usr/lib/acpid/中的D4脚本就行了,对systemd来说,难道没有类似的东西吗?
NB (重要):如何使用系统在键盘电源键上运行脚本?不是复制的,因为它被错误地标记为没有回答我的问题的如何更改电源按钮关闭操作以在系统d下运行脚本的副本,因为这是从键盘管理电源键,而不是电源按钮:

正如@TooTea所建议的那样,整合到这个案例中的按钮可能被看作是按键盘按钮,无论如何,在检查过之后,我没有这样的/dev/input/by-path/platform-i8042-serio-0-event-kbd文件来监控按下的键,然后它肯定不会回答我的问题。
发布于 2020-02-11 09:34:13
最后,我找到了一个解决方案,但幸运的是,我使用的是openbox:
在我的例子中,在LXDE下,编辑~/.config/openbox/lxde-rc.xml并在 ... 部分添加:
command or script to run例如,在我的测试中,我打开了一个弹出窗口,上面写着"Power按下“:
zenity --info --text="Power off pressed"然后,在终端类型openbox-lxde --reconfigure中,按下您的塔壳电源按钮,然后显示以下消息:

编辑:我忘记提到(但不确定这是强制性的),我将系统关机按钮设置为零,要检查此按钮,请转到“开始菜单”系统“->”系统“->”首选项“->”电源管理器,并确保“当按下电源按钮时”设置为“什么都不做”:

https://unix.stackexchange.com/questions/563603
复制相似问题