我之前在这种情况下所做的不是禁用屏幕保护程序,而是阻止屏幕保护程序启动。为此,我会定期(在计时器上)向操作系统发送“Left-Shift Up”击键。
C#:
[DllImport("user32")]
private static extern void keybd_event(byte bVirtualKey, byte bScanCode, int dwFlags, int dwExtraInfo);
private const byte VK_LSHIFT = 0xA0;
private const int KEYEVENTF_KEYUP = 0x0002;
// When the timer elapses, send Left Shift Up
private void timer1_Tick(object sender, EventArgs e)
{
keybd_event(VK_LSHIFT, 0x45, KEYEVENTF_KEYUP, 0);
}
VB.net:
Private Const VK_LSHIFT As Byte = 160
Private Const KEYEVENTF_KEYUP As Integer = 2
Private Declare Sub keybd_event Lib "user32" (ByVal bVirtualKey As Byte, ByVal bScanCode As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
' When the timer elapses, send Left Shift Up
Private Sub timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)
keybd_event(VK_LSHIFT, 69, KEYEVENTF_KEYUP, 0)
End Sub
(我不是 vb 开发人员,我只是通过自动 c# -> vb.net 转换器运行 c# 代码)
我认为 Left Shift Up 击键最不可能干扰应用程序。可能发生的最糟糕的情况是,如果在计时器触发的同时,您将左移向下,它将导致移位结束。
当然,您可以使用任何其他键来阻止屏幕保护程序激活。