Jump to content

Detect Mouse move outside a window region


Go to solution Solved by ioa747,

Recommended Posts

I am new in AutoIT and need help detect the Mouse Move position.

If I move the mouse outside a Window region, the script will show a message that I have moved the mouse outside.

Example: I have a Window region size is 640 x 480 pixel, If I move the mouse outside that one, the script will show a message.

Link to comment
Share on other sites

  • Solution

1

#include <StaticConstants.au3>

Local $MyGui = GUICreate("TaskPin GUI", 640, 480, -1, -1)
GUICtrlCreateLabel("", 0, 0, 640, 480, $SS_GRAYFRAME)
GUISetState(@SW_SHOW)

MouseMove(@DesktopWidth / 2, @DesktopHeight / 2, 1)

;**********************************
While 1
    Switch GUIGetMsg()
        Case -3     ;$GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch

    $aTrigger = GUIGetCursorInfo($MyGui)
    If $aTrigger[4] = 0 Then ConsoleWrite("mouse outside a Window region" & @CRLF)
    Sleep(10)
WEnd
;**********************************

2

#include <StaticConstants.au3>

Local $MyGui = GUICreate("TaskPin GUI", 640, 480, -1, -1)
GUISetState(@SW_SHOW)

MouseMove(@DesktopWidth / 2, @DesktopHeight / 2, 1)

;**********************************
While 1
    Switch GUIGetMsg()
        Case -3     ;$GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch

    If Not IsMouseOverWin($MyGui) Then ConsoleWrite("mouse outside a Window region" & @CRLF)
    Sleep(10)
WEnd
;**********************************

Func IsMouseOverWin($hWnd)
    Local $aMPos = MouseGetPos()
    Local $aWPos = WinGetPos($hWnd)
    ;$aWPos[0]=Xposition ;$aWPos[1]=Yposition ;$aWPos[2]=Width ;$aWPos[3]=Height
    If $aMPos[0] > $aWPos[0] And $aMPos[1] > $aWPos[1] And $aMPos[0] < $aWPos[0] + $aWPos[2] And $aMPos[1] < $aWPos[1] + $aWPos[3] Then
        Return True
    EndIf
    Return False
EndFunc   ;==>IsMouseOverWin

 

I know that I know nothing

Link to comment
Share on other sites

Compacted version of @ioa747's first one.

#include <StaticConstants.au3>

Local $MyGui = GUICreate("TaskPin GUI", 640, 480, -1, -1)
GUICtrlCreateLabel("", 0, 0, 640, 480, $SS_GRAYFRAME)
GUISetState(@SW_SHOW)

MouseMove(@DesktopWidth / 2, @DesktopHeight / 2, 1)

;**********************************
While GUIGetMsg() <> -3 ? GUIGetCursorInfo($MyGui)[4] = 0 ? ConsoleWrite("mouse outside a Window region" & @CRLF) : Sleep(10) : ExitLoop
WEnd
;**********************************

 

Some guy's script + some other guy's script = my script!

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