如何防止Windows在C#中睡觉? [英] How to prevent windows from sleeping in C#?

查看:90
本文介绍了如何防止Windows在C#中睡觉?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试以编程方式移动鼠标,但这并没有阻止远离PC,因为用户没有移动而不是可能有问题的按键。



我尝试了什么:



我为Ctrl模拟一个按键,但我想将鼠标移动1个像素到向右然后向左一个像素,让PC停止远离PC时间。

I tried moving the mouse programmatically but this didn't stop the "away from PC" because the user didn't do the move instead of the keypress that may be problematic.

What I have tried:

I simulate a keypress for Ctrl but I want to move the mouse 1 pixel to the right and then one pixel to the left and have the PC stop the away from PC time.

推荐答案

你可以使用带有ES_SYSTEM_REQUIRED的SetThreadExecutionState

注意:它是一种原生方法。



关于来自msdn链接的睡眠标准的更多细节

系统睡眠标准(Windows) [ ^ ]
You can use SetThreadExecutionState with ES_SYSTEM_REQUIRED
Note: its a native method.

More details regarding Sleep criteria from msdn link
System Sleep Criteria (Windows)[^]

这篇关于如何防止Windows在C#中睡觉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆