发现模拟鼠标移动只有加上耗内存的延时才起作用,这样做很不好啊!!!

解决方案 »

  1.   

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Const WM_SYSCOMMAND = &H112&
    Const SC_MONITORPOWER = &HF170&Private Sub Timer1_Timer()
    SendMessage Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, 2&'显示
    End Sub
      

  2.   

    控制面版->电源管理->显示器电源
      

  3.   

    '晕,参数错了.
    '这样:
    SendMessage Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, -1&
      

  4.   

    '试一下用SENDKEYS.
    Private Sub Timer1_Timer()
    SendKeys "{DOWN}"
    End Sub
      

  5.   

    第一个试的就是sendkeys啊,急
      

  6.   

    用GetCurrentProcess、AdjustTokenPrivileges、LookupPrivilegeValue、OpenProcessToken  等函数详见MSDN
      

  7.   

    Public Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long       '鼠标移动
    Public Type PointAPI
        X As Long
        Y As Long
    End Type
    Public Pnt As PointAPI
        '     'These values MUST be public
    Public OldX As Long
    Public OldY As Long'form
    Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
    Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    Private Const MOUSEEVENTF_MOVE = &H1        '  mouse move
    Private Const MOUSEEVENTF_LEFTDOWN = &H2    '  left button down
    Private Const MOUSEEVENTF_LEFTUP = &H4      '  left button up
    Private Const MOUSEEVENTF_ABSOLUTE = &H8000 '  absolute movePublic Sub Mouseup()                 '防待机
        Dim TEMPX, TEMPY
        GetCursorPos Pnt
        OldX = Pnt.X '* Screen.TwipsPerPixelX
        OldY = Pnt.Y '* Screen.TwipsPerPixelY    Dim posx, posy, a    posx = OldX - 1: posy = OldY    a = SetCursorPos(posx, posy)    mouse_event MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_LEFTUP, posx, posy, 0, 0
        Dim fff As Long
        For fff = 1 To 500000000
        Next    GetCursorPos Pnt
        TEMPX = Pnt.X '* Screen.TwipsPerPixelX
        TEMPY = Pnt.Y '* Screen.TwipsPerPixelY
        If TEMPX <> OldX - 1 Or TEMPY <> OldY Then Exit Sub    posx = OldX: posy = OldY - 1
        a = SetCursorPos(posx, posy)
        mouse_event MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_LEFTUP, posx, posy, 0, 0    For fff = 1 To 500000000
        Next    GetCursorPos Pnt
        TEMPX = Pnt.X '* Screen.TwipsPerPixelX
        TEMPY = Pnt.Y '* Screen.TwipsPerPixelY
        If TEMPX <> OldX Or TEMPY <> OldY - 1 Then Exit Sub    posx = OldX + 1: posy = OldY
        a = SetCursorPos(posx, posy)
        mouse_event MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_LEFTUP, posx, posy, 0, 0    For fff = 1 To 500000000
        Next    GetCursorPos Pnt
        TEMPX = Pnt.X '* Screen.TwipsPerPixelX
        TEMPY = Pnt.Y '* Screen.TwipsPerPixelY
        If TEMPX <> OldX + 1 Or TEMPY <> OldY Then Exit Sub    posx = OldX: posy = OldY + 1    a = SetCursorPos(posx, posy)    mouse_event MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_LEFTUP, posx, posy, 0, 0    For fff = 1 To 500000000
        Next    GetCursorPos Pnt
        TEMPX = Pnt.X '* Screen.TwipsPerPixelX
        TEMPY = Pnt.Y '* Screen.TwipsPerPixelY
        If TEMPX <> OldX Or TEMPY <> OldY + 1 Then Exit Sub    posx = OldX: posy = OldY
        a = SetCursorPos(posx, posy)
        ' mouse_event MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_LEFTDOWN, posx, posy, 0, 0
        mouse_event MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_LEFTUP, posx, posy, 0, 0End Sub'timer1:1s
    Private Sub Timer1_Timer()                     
            Static lngZeus As Long                  '防待机
            lngZeus = lngZeus + 1
            If lngZeus = 2 Then
                GetCursorPos Pnt
                OldX = Pnt.X
                OldY = Pnt.Y
            End If
            If lngZeus = 30 Then
                Dim NEWX, NEWY
                GetCursorPos Pnt
                NEWX = Pnt.X
                NEWY = Pnt.Y
                If NEWX = OldX And NEWY = OldY Then                'For lngZeus = 1 To 15
                    ' Screen.MousePointer = lngZeus
                    Mouseup
                    'Next            End If            lngZeus = 1
            End If
    End sub
    这段程序在三台笔记本上试过,可以防止待机,但是这是不合理的,只能证明死循环可以帮助防止待机?