有没有建议的方法来阻止Windows屏幕保护程序启动?我找到的最接近的东西是this article,但是我真正想做的只是告诉Windows计算机不是闲置的,而不是愚弄当前设置的屏幕保护程序值。

最佳答案

为了进行测试,我将屏幕保护程序设置为1分钟,并要求输入密码。

我尝试捕获SC_SCREENSAVE并在VB .Net中返回-1。如前所述,当没有屏幕保护程序密码时,如果屏幕保护程序密码处于 Activity 状态,则失败,而失败,该方法有效。 (我在Windows XP中尝试过)。我还每1000毫秒将其放入Timer的tick事件中:

Static dir As Integer = 4
Cursor.Position = Cursor.Position + New Size(dir, dir)
dir = -dir

没用光标来回摆动,一分钟后,屏幕保护程序会短暂闪烁并关闭。屏幕保护程序仅打开一会儿,时间不足以要求输入密码。但是,闪光灯仍然很难看。

然后,我尝试使用user32.dll的SetCursorPos和GetCursorPos。您可以在pinvoke上查找它们。与上述相同的结果。

然后我偷看了该问题中其他地方提到的“JiggleMouse”代码。 JiggleMouse使用SendInput。 SendInput有效! 屏幕保护程序没有闪烁。我在每隔50秒触发一次的Timer中放入对SendInput的调用(仅小于60秒的最小屏幕保护程序超时)。将鼠标移动0,0的增量就足够了,没有实际的移动。确实有效。放入Tick事件的代码:
Dim i(0) As INPUT
i(0).dwType = INPUT.InputType.INPUT_MOUSE
i(0).mkhi = New MOUSEKEYBDHARDWAREINPUT
i(0).mkhi.mi = New MOUSEINPUT
i(0).mkhi.mi.dx = 0
i(0).mkhi.mi.dy = 0
i(0).mkhi.mi.mouseData = 0
i(0).mkhi.mi.dwFlags = MOUSEINPUT.MouseEventFlags.MOUSEEVENTF_MOVE
i(0).mkhi.mi.time = 0
i(0).mkhi.mi.dwExtraInfo = IntPtr.Zero
SendInput(1, i(0), Marshal.SizeOf(i(0)))

这来自pinvoke.com:
Public Declare Function SendInput Lib "user32" (ByVal nInputs As Integer, ByRef pInputs As INPUT, ByVal cbSize As Integer) As Integer

Public Structure INPUT
    Enum InputType As Integer
        INPUT_MOUSE = 0
        INPUT_KEYBOARD = 1
        INPUT_HARDWARE = 2
    End Enum

    Dim dwType As InputType
    Dim mkhi As MOUSEKEYBDHARDWAREINPUT
End Structure

Public Structure MOUSEINPUT
    Enum MouseEventFlags As Integer
        MOUSEEVENTF_MOVE = &H1
        MOUSEEVENTF_LEFTDOWN = &H2
        MOUSEEVENTF_LEFTUP = &H4
        MOUSEEVENTF_RIGHTDOWN = &H8
        MOUSEEVENTF_RIGHTUP = &H10
        MOUSEEVENTF_MIDDLEDOWN = &H20
        MOUSEEVENTF_MIDDLEUP = &H40
        MOUSEEVENTF_XDOWN = &H80
        MOUSEEVENTF_XUP = &H100
        MOUSEEVENTF_WHEEL = &H800
        MOUSEEVENTF_VIRTUALDESK = &H4000
        MOUSEEVENTF_ABSOLUTE = &H8000
    End Enum

    Dim dx As Integer
    Dim dy As Integer
    Dim mouseData As Integer
    Dim dwFlags As MouseEventFlags
    Dim time As Integer
    Dim dwExtraInfo As IntPtr
End Structure

Public Structure KEYBDINPUT
    Public wVk As Short
    Public wScan As Short
    Public dwFlags As Integer
    Public time As Integer
    Public dwExtraInfo As IntPtr
End Structure

Public Structure HARDWAREINPUT
    Public uMsg As Integer
    Public wParamL As Short
    Public wParamH As Short
End Structure

Const KEYEVENTF_EXTENDEDKEY As UInt32 = &H1
Const KEYEVENTF_KEYUP As UInt32 = &H2
Const KEYEVENTF_UNICODE As UInt32 = &H4
Const KEYEVENTF_SCANCODE As UInt32 = &H8
Const XBUTTON1 As UInt32 = &H1
Const XBUTTON2 As UInt32 = &H2

<StructLayout(LayoutKind.Explicit)> Public Structure MOUSEKEYBDHARDWAREINPUT
    <FieldOffset(0)> Public mi As MOUSEINPUT
    <FieldOffset(0)> Public ki As KEYBDINPUT
    <FieldOffset(0)> Public hi As HARDWAREINPUT
End Structure

关于winapi - 以编程方式阻止Windows屏幕保护程序启动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/463813/

10-11 13:13