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.
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)"
}
While this does wiggle the mouse it doesn't keep the screen from turning off. So I wrote this: (in python)
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
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 website the variable MOUSEEVENTF_MOVE is a flag to signify that the mouse has moved.
Additionally I found this SO question (How i can send mouse click in powershell) 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.
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.S. This is my first time working with powershell.