使用 C 在 Windows 中强制按键或鼠标移动
我需要在显示器从睡眠状态恢复/唤醒后打开它。做到这一点的唯一方法似乎是通过鼠标移动或按键。 Windows 7 上的 C 语言有什么方法可以模拟这种情况,以便唤醒监视器吗?
I need to turn a monitor on after it resumes/wakes from sleep. The only way it seems to do this is by mouse movement or keypress. Is there any way in C on Windows 7 to simulate this so the monitor wakes up?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一个名为 Caffeine 的实用程序可以执行此操作...我只是提到它,因为它每 59 秒发送一次 F15 键...因此这可能是更好的按键发送方式。
There is a utility named Caffeine that does this... I only mention it because it sends the F15 key every 59 seconds... so that may be a better key press to send.
我查看了它,因为它上面有批处理标签,但我看到您想使用 C ?在 VBS 中,您可以轻松使用以下命令发送按键。这可以从批处理文件中调用,或者如果您正在用 C 编译某些东西,这也不难。
设置 objShell = CreateObject("WScript.Shell")
Do While True
objShell.SendKey("+")
WScript.Sleep 60000
Loop
//注意发送的键是+键。您可以更改此设置以及它等待发送按键的时间,当前为 60000(1 秒为 1000)如果您在程序开始时调用它,它将保持运行并将按键发送到系统,直到vbs 脚本终止。
您还可以使用不太可能妨碍当时正在打字的人的键,例如数字锁定键。
I viewed this as it has the batch tag on it, but I see that you want to use C ? In VBS you can easily use the follwing to send a keypress. This can be called from a batch file or if you are compiling something in C It should not be hard either.
Set objShell = CreateObject("WScript.Shell")
Do While True
objShell.SendKey("+")
WScript.Sleep 60000
Loop
//Note that the key being sent is the + key. You can change this as well as the time it waits to send the keypress which is currently 60000 (1 second would be 1000) If you call this at the start of your program it will remain running and will send the keystroke to the system until the vbs script is terminated.
You could also use a key that wont likely hinder someone who is typing at the time, such as the numlock key.