How can I intercept the push of the physical power button in Windows?

前端 未结 2 992
栀梦
栀梦 2021-01-05 15:53

Is there any way to intercept the event of the physical power button being pressed in order to react to this event? i.e.:

Push button -> My program catche         


        
相关标签:
2条回答
  • 2021-01-05 16:15

    You could use SystemEvents.SessionEnding Event

    However I am not sure if this will work if the power button is pressed, this event Occurs when the user is trying to log off or shut down the system.

    0 讨论(0)
  • 2021-01-05 16:30

    I can explain it to you in theory: The button (it's a button that's tied to shutdown on most systems) has an option under "power options", where you can specificy the action to take when the power button is pressed...

    It's that ACTION event you're looking for that's bound to the button by windows that THEN instantiates the shutdown event. There's programs that dissect and monitor windows variables and calls, you'd have to use one of those to figure it out and intercept/override it.

    0 讨论(0)
提交回复
热议问题