Get current laptop lid state

前端 未结 2 1284
一生所求
一生所求 2021-02-08 20:53

I\'m writing a C# app (specifically for laptops) and I want to be aware of the state of the lid, i.e. when is it open and when is it closed.

I\'ve already used pInvoke a

2条回答
  •  梦谈多话
    2021-02-08 21:35

    So after a long search led by @Llwyd's answer, I found a solution. I noticed that when the lid is closed the device is removed from the device manager, so the solution is to check whether it is there or not. The code behind it is a bit massive to upload here so I won't, but the following was need: 1) Identify Internal screen's name\ID with WmiMonitorConnectionParams and VideoOutputTechnology and state (DISPLAY_DEVICE_ATTACHED and/or DISPLAY_DEVICE_ACTIVE) 2) Once I know the device's name/ID I can easily look it up by enumerating System.Windows.Forms.Screen.AllScreens (or save the value from the DISPLAY_DEVICE_ATTACHED)

提交回复
热议问题