Jump to content

detect if mouse not in win coords..


Recommended Posts

#include <GUIConstants.au3>
$Form1 = GUICreate("AForm1", 622, 447, 194, 152)
GUISetState(@SW_SHOW)

While 1
    $WinPos = WinGetPos($Form1)
    $MousePos = MouseGetPos()
    
    If $MousePos[0] <> $WinPos[0] Or $MousePos[1] <> $WinPos[1] Then NotOnGui()
        
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
;;;;;;;
    EndSelect
WEnd
Exit

Func NotOnGui()
    Msgbox(0,'Not','Out of pos')
EndFunc

Hello This code should detect if mouse move of the gui, then do a function.. what am I not doing right?

Edited by WTS
Link to comment
Share on other sites

  • Moderators

If $MousePos[0] < $WinPos[0] Or _
        $MousePos[0] > $WinPos[0] + $WinPos[2] Or _
        $MousePos[1] < $WinPos[1] Or _
        $MousePos[1] > $WinPos[1] + $WinPos[3] Then NotOnGui()

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Thanks!

Do you know how to implement a timer function? lets say I move the mouse off the gui, it counts down lets say for 3 seconds and then does NotOnGui, but the count down resets if I have the mouse back on the GUI before it reaches 3 seconds..

Link to comment
Share on other sites

  • Moderators

Thanks!

Do you know how to implement a timer function? lets say I move the mouse off the gui, it counts down lets say for 3 seconds and then does NotOnGui, but the count down resets if I have the mouse back on the GUI before it reaches 3 seconds..

Yes...

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Well that was no fun, you asked if I knew how, I said yes, and you left it alone :yawn:

#include <GUIConstants.au3>
Global $TimerStart = 0
$Form1 = GUICreate("AForm1", 622, 447, 194, 152)
GUISetState(@SW_SHOW)

While 1
    Local $WinPos = WinGetPos($Form1)
    Local $MousePos = MouseGetPos()
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
    If $MousePos[0] < $WinPos[0] Or _
        $MousePos[0] > $WinPos[0] + $WinPos[2] Or _
        $MousePos[1] < $WinPos[1] Or _
        $MousePos[1] > $WinPos[1] + $WinPos[3] Then
        If $TimerStart == 0 Then $TimerStart = TimerInit()
        NotOnGui(3)
    Else
        $TimerStart = 0
    EndIf
    Sleep(10)
WEnd
Exit

Func NotOnGui($TimeLapse)
    If TimerDiff($TimerStart) / 1000 >= $TimeLapse Then
        MsgBox(64, 'Info:', 'You were outside the GUI for ' & $TimeLapse & ' seconds or more.')
    EndIf
EndFunc
Is one way...

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

sorry.. I was busy watching my sister, thanks again..

Hmmm :D

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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...