https://github.com/librerpi/rpi-tools/b ... oxy/main.cif you open an event device with the GRAB flag set, then the events dont go to any other application, so you can get exclusive use of the button
then you just need to find the right path to the power button, likely this symlink
and now its up to your application to issue a shutdown on double-click
the only issue for the power button, is that the firmware will issue an improper shutdown if you hold the button for a few seconds, so beware of that
Code:
int fd = open("/dev/input/event0", O_RDWR); int ret = ioctl(fd, EVIOCGRAB, (void*)1); struct input_event ev[64]; int rd = read(events[i].data.fd, ev, sizeof(ev));
Code:
root@raspberrypi:~# ls -l /dev/input/by-path/platform-pwr_button-event lrwxrwxrwx 1 root root 9 Apr 16 09:17 /dev/input/by-path/platform-pwr_button-event -> ../event0
and now its up to your application to issue a shutdown on double-click
the only issue for the power button, is that the firmware will issue an improper shutdown if you hold the button for a few seconds, so beware of that
Statistics: Posted by cleverca22 — Wed Apr 30, 2025 12:12 am