Jump to content

Detecting mouse movement?


Recommended Posts

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

Link to comment
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
Link to comment
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
Link to comment
Share on other sites

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]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...