gpt4 book ai didi

winapi - 以编程方式阻止 Windows 屏幕保护程序启动

转载 作者:行者123 更新时间:2023-12-01 16:24:14 26 4
gpt4 key购买 nike

是否有推荐的方法来阻止 Windows 屏幕保护程序启动?我发现的最接近的是 this article ,但我真正想做的是告诉 Windows 计算机没有空闲,而不是愚弄当前设置的屏幕保护程序值。

最佳答案

为了测试,我将屏幕保护程序设置为 1 分钟并需要密码。

我 try catch SC_SCREENSAVE 并在 VB .Net 中返回 -1。正如所评论的,它在没有屏幕保护程序密码时有效,但如果屏幕保护程序密码处于事件状态,则失败。 (我在Windows XP 中尝试过)。我还将其放入计时器的滴答事件中,每 1000 毫秒一次:

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

这不起作用。光标来回晃动,1 分钟后屏幕保护程序会短暂闪烁,然后关闭。屏幕保护程序只打开一会儿,不足以要求输入密码。但是,闪光灯还是很难看。

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

然后我看了一眼这个问题其他地方提到的“JiggleMouse”的代码。 JiggleMouse 使用 SendInput。 SendInput 有效! 屏幕保护程序不闪烁。我在计时器内调用了 SendInput,每 50 秒触发一次(略小于屏幕保护程序的最小超时时间 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com