title: Powershell script to keep computer from going to idle
body: <p>I'm trying to keep my computer from going into idle mode. So I'm trying to write a script that will wiggle my mouse. This is a slightly customized version of a powershell script I found. </p>
  
  <pre><code>param($cycles = 60)
  
  
  Add-Type -AssemblyName System.Windows.Forms
  $screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
  for ($i = 0; $i -lt $cycles; $i++) {
  
  Start-Sleep -Seconds 3
  
  [Windows.Forms.Cursor]::Position = "$($screen.Width),$($screen.Height)"
  Start-Sleep -Seconds 3
  
  [Windows.Forms.Cursor]::Position = "$($screen.Left),$($screen.Top)"
  }
  </code></pre>
  
  <p>While this does wiggle the mouse it doesn't keep the screen from turning off. So I wrote this: (in python)</p>
  
  <pre><code>import ctypes, time, datetime
  
  mouse_event = ctypes.windll.user32.mouse_event
  MOUSEEVENTF_MOVE = 0x0001
  print("press ctrl-c to end mouse shaker")
  try:
      while True:
          mouse_event(MOUSEEVENTF_MOVE,25,0,0,0)
          time.sleep(1)
          mouse_event(MOUSEEVENTF_MOVE,0,25,0,0)
          time.sleep(1)
          mouse_event(MOUSEEVENTF_MOVE,-25,0,0,0)
          time.sleep(1)
          mouse_event(MOUSEEVENTF_MOVE,0,-25,0,0)
          time.sleep(1)
  except KeyboardInterrupt:
      pass
  </code></pre>
  
  <p>This python code will keep my screen from going to sleep and prevents the machine from becoming idle. I believe the issue is because in the powershell scrip I never send the os the "MOUSEEVENTF_MOVE = 0x0001" string. According to the Microsoft <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms646260(v=vs.85).aspx" rel="nofollow noreferrer">website</a> the variable MOUSEEVENTF_MOVE is a flag to signify that the mouse has moved. </p>
  
  <p>Additionally I found this SO question (<a href="https://stackoverflow.com/questions/39353073/how-i-can-send-mouse-click-in-powershell">How i can send mouse click in powershell</a>) that seems to be doing this exact thing but is also clicking, which I don't want. I've tried just commenting out those lines but the "SendImput" I think is expecting some input causing it to fail.</p>
  
  <p>So here is my question. How do I pass the MOUSEEVENTF_MOVE variable in the powershell code? I'm thinking it should have the same effect as my python code. </p>
  
  <p>P.S. This is my first time working with powershell.</p>