程序代码 Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Long '热键 Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Const WM_SYSCOMMAND = &H112& Const SC_MONITORPOWER = &HF170& Private Sub Timer1_Timer() If GetAsyncKeyState(vbKeyF2) Then '如果按下F2 End '结束程序 SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, ByVal -1& '打开显示器 Else SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, ByVal 2& '关闭显示器 End If End Sub
已有评论: