powershell mouse move does not prevent idle mode

后端 未结 8 1768
猫巷女王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:04

    I tried a mouse move solution too, and it likewise didn't work. This was my solution, to quickly toggle Scroll Lock every 4 minutes:

    Clear-Host
    Echo "Keep-alive with Scroll Lock..."
    
    $WShell = New-Object -com "Wscript.Shell"
    
    while ($true)
    {
      $WShell.sendkeys("{SCROLLLOCK}")
      Start-Sleep -Milliseconds 100
      $WShell.sendkeys("{SCROLLLOCK}")
      Start-Sleep -Seconds 240
    }
    

    I used Scroll Lock because that's one of the most useless keys on the keyboard. Also could be nice to see it briefly blink every now and then. This solution should work for just about everyone, I think.

    See also:

    • https://ss64.com/vb/sendkeys.html
    • http://devguru.com/content/technologies/wsh/wshshell-sendkeys.html

提交回复
热议问题