我正在努力使用此代码打开显示器。我已经在Windows 10控制面板中设置显示器在10分钟后关闭,但我有一个语音识别用VB编写的应用程序,我需要在通过语音呼叫应用程序时唤醒屏幕。那么是否有通过 Visual Basic 唤醒显示器的代码?我搜索了很长时间但我只找到了一些Java代码。谢谢,祝你有一个美好的一天/晚上! :)
答案 0 :(得分:0)
K,所以,在the article on codeproject的指导下,给this question和pinvoke.net的一些答案,我已经有了一些工作。它可能更干净,但我把它留给你:)。毕竟,它是你的项目;)。
Imports System.Runtime.InteropServices
Public Class Monitor
Private Const WM_SYSCOMMAND As Integer = &H112
Private Const SC_MONITORPOWER As Integer = &HF170
Private Const HWND_BROADCAST As Integer = &HFFFF
Private Const INPUT_MOUSE As Integer = 0
Private Const MOUSEEVENTF_MOVE As Integer = 1
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True)>
Private Shared Function SendInput(<[In]()> ByVal nInput As UInt32,<[In](), MarshalAs(UnmanagedType.LPArray, ArraySubtype:=UnmanagedType.Struct, SizeParamindex:=0)> ByVal pInputs() As INPUT, <[In]()> ByVal cbInput As Int32) As UInt32
End Function
Private Structure INPUT
Public type As Integer
Public dx As Integer
Public dy As Integer
Public mouseData As Integer
Public dwFlags As Integer
Public time As Integer
Public dwExtraInfo As IntPtr
End Structure
Public Shared Sub Disable()
SendMessage(New IntPtr(HWND_BROADCAST), WM_SYSCOMMAND, SC_MONITORPOWER, New IntPtr(2))
End Sub
Public Shared Sub Enable()
Dim input = New INPUT()
input.type = INPUT_MOUSE
input.dx = 1
input.dy = 0
input.mouseData = 0
input.dwFlags = MOUSEEVENTF_MOVE
input.time = 0
input.dwExtraInfo = IntPtr.Zero
SendInput(1, {input}, 28)
End Sub
End Class