powershell mouse move does not prevent idle mode

后端 未结 8 1929
猫巷女王i
猫巷女王i 2021-01-30 09:36

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         


        
8条回答
  •  广开言路
    2021-01-30 10:05

    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)
    

提交回复
热议问题