powershell 鼠标移动不会阻止空闲模式 [英] powershell mouse move does not prevent idle mode

查看:86
本文介绍了powershell 鼠标移动不会阻止空闲模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开始之前,这是我在 PowerShell 中编写的第一个小代码 :)

Before I start, here is my very first little code I wrote in PowerShell :)

[System.Windows.Forms.Cursor]::Position = `
    New-Object System.Drawing.Point($pos.X, ($pos.Y - 1))
[System.Windows.Forms.Cursor]::Position = `
    New-Object System.Drawing.Point($pos.X, $pos.Y)

我想达到什么目的?

好吧,我想每 4 分钟移动一次鼠标光标以防止屏幕保护程序出现(上面代码中的每一秒都用于测试).每次向上和向下一个像素时,代码确实会立即移动鼠标.问题是,屏幕保护程序(或 Windows 的空闲模式)仍在出现.

Well, I want to move the mouse cursor every 4 minutes to prevent the screensaver from appearing (every second in the code above for testing). The code does really move the mouse every time one pixel up and then down immediately. The thing is, the screensaver (or idle mode of windows) is still appearing.

现在,我正在学习 PowerShell,但我对 Windows 架构几乎没有经验.

Now, I am learning PowerShell and I have little experience with the Windows architecture.

有人看到我的错误吗?我非常感谢您的回答!:D提前致谢.

Does anybody see my mistake? I would appreciate an answer a lot! :D Thanks in advance.

推荐答案

来自博客的解决方案 使用 PowerShell 防止桌面锁定或屏幕保护程序 对我有用.这是相关的脚本,它只是向 shell 发送一个句点:

The solution from the blog Prevent desktop lock or screensaver with PowerShell is working for me. Here is the relevant script, which simply sends a single period to the shell:

param($minutes = 60)

$myshell = New-Object -com "Wscript.Shell"

for ($i = 0; $i -lt $minutes; $i++) {
  Start-Sleep -Seconds 60
  $myshell.sendkeys(".")
}

以及评论中的替代方法,将鼠标移动一个像素:

and an alternative from the comments, which moves the mouse a single pixel:

$Pos = [System.Windows.Forms.Cursor]::Position
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point((($Pos.X) + 1) , $Pos.Y)
$Pos = [System.Windows.Forms.Cursor]::Position
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point((($Pos.X) - 1) , $Pos.Y)

这篇关于powershell 鼠标移动不会阻止空闲模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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