How can I intercept a physical power button press in Windows?

Is there a way to capture the physical power button press event to respond to this event? i.e:.

Push button -> My program catches the event -> My program performs action.

My goal is to write a program / service in C # that will listen to the power button event, and then open the β€œAsk me what to do” dialog box (as in the days of Windows XP).

+5
source share
2 answers

You can use the SystemEvents.SessionEnding Event

However, I'm not sure if this will work if you press the power button, this event occurs when the user tries to log out or turn off the system.

0
source

: ( , ) " ", , ...

ACTION, , , THEN . , Windows, , / .

0

All Articles