luissiscone 7/10/2020, 20:43
Olá
Crie um módulo com esta função :
'32-bit declaration
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Any) As Long
'64-bit declaration
'Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As LongPtr, _
' ByVal wMsg As Long, _
' ByVal wParam As LongPtr, _
' lParam As Any) As LongPtr
'---------------------------------------------------------------------------------------
' Procedure : MonitorPower
' Author : Daniel Pineault, CARDA Consultants Inc.
' Purpose : Turn On/Off the monitor
' Copyright : The following is release as Attribution-ShareAlike 4.0 International
' Req'd Refs: None required
' Req'd : SendMessage API Declaration
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' bMontiorOn: True -> Turn monitor on
' False -> Turn monitor off
'
' Usage:
' ~~~~~~
' Call MonitorPower
'
' Revision History:
' Rev Date(yyyy/mm/dd) Description
' **************************************************************************************
' 1 2018-12-14 Initial Release (Forum help)
'---------------------------------------------------------------------------------------
Public Function MonitorPower(Optional bMontiorOn As Boolean = False)
Const WM_SYSCOMMAND = &H112
Const SC_MONITORPOWER = &HF170&
Const MONITOR_ON = -1&
Const MONITOR_OFF = 2&
On Error GoTo Error_Handler
If bMontiorOn = False Then
SendMessage Application.hWndAccessApp, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF
Else
SendMessage Application.hWndAccessApp, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON
End If
Error_Handler_Exit:
On Error Resume Next
Exit Function
Error_Handler:
MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & _
"Error Source: MonitorPower" & vbCrLf & _
"Error Description: " & Err.Description & _
Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
, vbOKOnly + vbCritical, "An Error has Occurred!"
Resume Error_Handler_Exit
End Function
Chame ela no evento ao mover mouse ou qualquer evento que desejar de um form
No seu caso acho que vai querer criar um temporizador
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call MonitorPower
End Sub