【发布时间】:2015-11-11 05:00:03
【问题描述】:
我正试图阻止屏幕保护程序启动。 我试过发送击键,但它们都需要按标题抓取一个窗口。 如果桌面上没有打开的窗口,则没有什么可以抓取的。
所以我找到了一些可行的方法,但我不是 C# 向导。 它基于Simulating a keypress AND keyrelease in another application?
下面的代码应该发送 1,但我遗漏了一些东西。在我从 Powershell 调用新类型之前,我没有收到任何错误。 在这个工作之后,我想让它发送一个 F15 来重置屏幕保护程序倒计时但不修改屏幕上的东西。 (但我要先爬,先发送 1s)
Add-Type @"
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
public static class PressKeyForMe
{
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
//public static void Main(string[] args)
public static void Main()
{
//This code will press and hold the '1' button for 3 secs, and then will release for 1 second
//VK_F15 0x7E
keybd_event((byte)0x31, (byte)0x02, 0, UIntPtr.Zero);
Thread.Sleep(3000);
keybd_event((byte)0x31, (byte)0x82, (uint)0x2, UIntPtr.Zero);
Thread.Sleep(1000);
}
}
}
"@
cls
#all of these give me: Unable to find type
[void] [PressKeyForMe]::Main()
[void] [ConsoleApplication1]::PressKeyForMe()
[void] [PressKeyForMe.Main]
[void] [ConsoleApplication1.Main]
[void] [ConsoleApplication1.PressKeyForMe]::Main()
【问题讨论】:
标签: c# powershell