Sign in to follow this  
Followers 0
motionman95

Detecting mouse movement?

8 posts in this topic

Is there a function in AutoIt to detect mouse movement? I want to be able to detect if the mouse has been idle for more than 5 minutes, and if so, hide my application. On the return of mouse movement, I want my app to reappear.

Thanks in advance, motionman95 :D


Share this post


Link to post
Share on other sites



Is there a function in AutoIt to detect mouse movement? I want to be able to detect if the mouse has been idle for more than 5 minutes, and if so, hide my application. On the return of mouse movement, I want my app to reappear.

Thanks in advance, motionman95 :D

$s = mousegetpos()
do
$x = 0
if $s = Mousegetpos() then
;???
else
;???
$x = 0
endif
$x = $x + 1
sleep(1000)
untill $x = 300000

Share this post


Link to post
Share on other sites

Will that code work even if the PC is locked?


Share this post


Link to post
Share on other sites

Bump :D


Share this post


Link to post
Share on other sites

Don't bump less than 24 hours after your last post please

Why not try and see?


Giggity

Share this post


Link to post
Share on other sites

See __Timer_IdleChecker() example in my signature.

_Timer_GetIdleTime() checks if Mouse OR Keyboard input happend. If you want to deactivate the WinActive check replace

if @AutoItPID <> WinGetProcess(_WinAPI_GetAncestor(WinGetHandle("[ACTIVE]"), $GA_ROOTOWNER)) then; none of the programs windows are active
        $bIdle = true
    Else
        if _Timer_GetIdleTime() > $iIdle_Time Then; program considered idle after x ms of inactivity
            $bIdle = True
        Else
            $bIdle = False
        endif
    endif

with

if _Timer_GetIdleTime() > $iIdle_Time Then; program considered idle after x ms of inactivity
            $bIdle = True
        Else
            $bIdle = False
        endif

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

If the computer is locked - but logged onto - then then timer and window minimize function will work. The mouse movement is not detected by the script when the computer is locked - at least not in the virtual machine that I tested this on:

$begin = TimerInit()
While 1
    $moved = "no"

    $pos1 = MouseGetPos()
    Sleep(50)
    $pos2 = MouseGetPos()

    If $pos1[0] <> $pos2[0] Then $moved = "yes"
    If $pos1[1] <> $pos2[1] Then $moved = "yes"

    If $moved = "yes" Then
        WinActivate("C:\Doc")
        $begin = TimerInit()
    EndIf

    If TimerDiff($begin) > 300000 And $moved = "no" Then
        WinSetState("C:\Doc", "", @SW_MINIMIZE)
        $begin = TimerInit()
    EndIf
WEnd

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0