ModemJunki Posted November 5, 2020 Posted November 5, 2020 I had an interesting test case to move the mouse at random intervals and capture some data from that. I found this post from @mlowery from 2010 and didn't want to necropost: So I modified that to work with Random() and my own mouse mover to jiggle the mouse. Can anyone think of an easier way? expandcollapse popup#include <Date.au3> ;=============================================================================== ; Description: Moves mouse rando-periodically to prevent screen save ;=============================================================================== ;=============================================================================== ; MAIN ;=============================================================================== HotKeySet("!x", "_done") ; alt+x will exit Global $iRandom = Random(300000, 600000, 1) ; 3 to 10 minutes initial random wait time Beep() ; and why not? While 1 If _Get_Idle_Ticks() > $iRandom Then _MoveMouse() ; move the mouse and moves it back, see function for description $iRandom = Random(300000, 600000, 1) ; 3 to 10 minutes reset of random wait time Beep() ; and why not? EndIf Sleep(5000) ; wait 5 seconds in loop WEnd ;=============================================================================== ; Functions ;=============================================================================== ;=============================================================================== ; Description: Moves the mouse a specified number of pixels and then moves it back ; Parameter(s): $PixX = number of pixels to move in X coord ; $PixY = number of pixels to move in Y coord ; $Speed = 0 ; Requirement(s): None ; Return Value(s): None ; Note(s): High movement values make it look weird ;=============================================================================== Func _MoveMouse($PixX = 1, $PixY = 1, $Speed = 0) ; speed of zero is instantaneous Local $X = $PixX, $Y = $PixY Local $_aPos = MouseGetPos() ; 1st get Mouse x, y: and store in array MouseMove($_aPos[0] + $X, $_aPos[1] + $Y, $Speed) ; move Mouse to Mouse X + $X, Mouse y + $Y MouseMove($_aPos[0], $_aPos[1], $Speed) ; now move back to original coordinates EndFunc ;==>_MoveMouse ;=============================================================================== ; Description: Exits and resets hotkey ; Parameter(s): None ; Requirement(s): None ; Return Value(s): None ; Note(s): ;=============================================================================== Func _done() HotKeySet("!x") Exit EndFunc ;==>_done ;=============================================================================== ; Description: Returns number of ticks since system was idle (determined by mouse/key input) ; Parameter(s): None ; Requirement(s): None ; Return Value(s): Milliseconds since last user input (mouse/key) ; Note(s): ;=============================================================================== Func _Get_Idle_Ticks() Local $struct = DllStructCreate("uint;dword") ; DllStructSetData($struct, 1, DllStructGetSize($struct)) ; DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct)) Local $last_active = DllStructGetData($struct, 2) Return _Date_Time_GetTickCount() - $last_active EndFunc ;==>_Get_Idle_Ticks Always carry a towel.
markyrocks Posted November 6, 2020 Posted November 6, 2020 (edited) Doesn't seem to get any easier to me... I guess it just depends on what you're trying to accomplish. Spoiler HotKeySet("!x", "_done") ; alt+x will exit Beep() ; and why not? While 1 Sleep(Random(180000, 600000, 1)) _MoveMouse() ; WEnd Func _MoveMouse($Speed = 0) ; speed of zero is instantaneous Local $_aPos = MouseGetPos() ; 1st get Mouse x, y: and store in array MouseMove($_aPos[0] + Random(1,@DesktopWidth-$_aPos[0],1), $_aPos[1] + random(1,@DesktopHeight-$_aPos[1],1), $Speed) ; move Mouse to Mouse X + $X, Mouse y + $Y MouseMove($_aPos[0], $_aPos[1], $Speed) ; now move back to original coordinates EndFunc ;==>_MoveMouse Func _done() HotKeySet("!x") Exit EndFunc ;==>_done I guess it could get easier but this is as far as im willing to go. Seems to work for me. Edited November 6, 2020 by markyrocks Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning"
BigDaddyO Posted November 6, 2020 Posted November 6, 2020 if it's just to keep the pc/monitor awake with no screensaver, you can just use a DLL call.
ModemJunki Posted November 6, 2020 Author Posted November 6, 2020 3 hours ago, BigDaddyO said: if it's just to keep the pc/monitor awake with no screensaver, you can just use a DLL call. Neat. Test spec says jiggle the mouse so I jiggle the mouse. But the DLL call is better to keep the system awake, I think. Always carry a towel.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now