2个回答
展开全部
建议你这样试试看:
- 电脑一般无按键输入一定分钟后锁屏,所以每分钟模拟鼠标或键盘按下一个键就可以了。
模拟用户操作控制面板中,找到锁屏设置项,关闭。不同的Windows系统步骤可能不一定,需要查找控制面板相关窗口的句柄,模拟鼠标点击来完整调整操作。
由于Windows安全机制,据我所知好像没有函数能直接禁用电脑锁屏,只有锁屏的,没有阻止锁屏的。
API声明代码:
一般使用API的SendMessage和keybd_event和mouse_event
public static class 窗体API {
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, string lParam);
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, StringBuilder lParam);
/// <summary>
/// 向窗口发送消息,执行后马上返回。
/// </summary>
/// <param name="hWnd"></param>
/// <param name="Msg"></param>
/// <param name="wParam"></param>
/// <param name="lParam"></param>
/// <returns></returns>
[DllImport("User32.dll", EntryPoint = "PostMessage")]
public static extern int PostMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("user32.dll", EntryPoint = "keybd_event", SetLastError = true)]
public static extern void keybd_event(Keys bVk, byte bScan, int dwFlags, int dwExtraInfo);
[DllImport("user32.dll", EntryPoint = "mouse_event", SetLastError = true)]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
[DllImport("User32.dll", EntryPoint = "SetCursor")]
public static extern int SetCursor(int hCursor);
[DllImport("User32.dll", EntryPoint = "SetCursorPos")]
public static extern int SetCursorPos(int x, int y);
[DllImport("user32.dll", EntryPoint = "GetCursorPos")]
public static extern int GetCursorPos(ref MOUSEPOINT lpPoint);
}
模拟按键
public class 模拟 {
public static void 模拟按键(Keys 按键) {
窗体API.keybd_event(按键, 0, 0, 0);
窗体API.keybd_event(按键, 0, 2, 0);
}
public static void 模拟按键(Keys 组合键, Keys 按键) {
窗体API.keybd_event(组合键, 0, 0, 0);
窗体API.keybd_event(按键, 0, 0, 0);
窗体API.keybd_event(按键, 0, 2, 0);
窗体API.keybd_event(组合键, 0, 2, 0);
}
public static void 模拟按键(Keys 组合键1, Keys 组合键2, Keys 按键) {
窗体API.keybd_event(组合键1, 0, 0, 0);
窗体API.keybd_event(组合键2, 0, 0, 0);
窗体API.keybd_event(按键, 0, 0, 0);
窗体API.keybd_event(按键, 0, 2, 0);
窗体API.keybd_event(组合键2, 0, 2, 0);
窗体API.keybd_event(组合键1, 0, 2, 0);
}
public static void 按下(Keys 按键) {
窗体API.keybd_event(按键, 0, 0, 0);
}
public static void 抬起(Keys 按键) {
窗体API.keybd_event(按键, 0, 2, 0);
}
public static void 鼠标位置(int x, int y) {
窗体API.SetCursorPos(x, y);
}
/// <summary>相对当前位置的移动</summary>
public static void 鼠标移动(int x, int y) { 窗体API.mouse_event(0x1, x, y, 0, 0); }
public static void 按下左键(int x, int y) { 窗体API.mouse_event(0x2, x, y, 0, 0); }
public static void 抬起左键(int x, int y) { 窗体API.mouse_event(0x4, x, y, 0, 0); }
public static void 按下右键(int x, int y) { 窗体API.mouse_event(0x8, x, y, 0, 0); }
public static void 抬起右键(int x, int y) { 窗体API.mouse_event(0x10, x, y, 0, 0); }
public static void 按下中键(int x, int y) { 窗体API.mouse_event(0x20, x, y, 0, 0); }
public static void 抬起中键(int x, int y) { 窗体API.mouse_event(0x40, x, y, 0, 0); }
/// <summary>距离正数表示向上滚动,负值表示向下滚动。轮击定义为WHEEL_DELTA,即120。</summary>
public static void 鼠标滚动(int x, int y, int 距离) { 窗体API.mouse_event(0x800, x, y, 距离, 0); }
public static void 鼠标移至(int x, int y) { 窗体API.mouse_event(0x8000, x, y, 0, 0); }
}
调用的时候直接 模拟.模拟按键(Keys.Up) 就可以了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询