powershell mouse move does not prevent idle mode

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

    <# Stay Awake by Frank Poth 2019-04-16 #>
    
    (Get-Host).UI.RawUI.WindowTitle = "Stay Awake"
    
    [System.Console]::BufferWidth  = [System.Console]::WindowWidth  = 40
    [System.Console]::BufferHeight = [System.Console]::WindowHeight = 10
    
    $shell = New-Object -ComObject WScript.Shell
    
    $start_time = Get-Date -UFormat %s <# Get the date in MS #>
    $current_time = $start_time
    $elapsed_time = 0
    
    Write-Host "I am awake!"
    
    Start-Sleep -Seconds 5
    
    $count = 0
    
    while($true) {
    
      $shell.sendkeys("{NUMLOCK}{NUMLOCK}") <# Fake some input! #>
    
      if ($count -eq 8) {
    
        $count = 0
        Clear-Host
    
      }
    
      if ($count -eq 0) {
    
        $current_time = Get-Date -UFormat %s
        $elapsed_time = $current_time - $start_time
    
        Write-Host "I've been awake for "([System.Math]::Round(($elapsed_time / 60), 2))" minutes!"
    
      } else { Write-Host "Must stay awake..." }
    
      $count ++
    
      Start-Sleep -Seconds 2.5
    
    }
    

    The part that matters is $shell.sendkeys("{NUMLOCK}{NUMLOCK}") This registers two presses on the numlock key and fools the shell into thinking input was entered. I wrote this today after searching through various scripts that didn't work for me. Hope it helps someone!

提交回复
热议问题