Jump to content

Call a function when the mouse moves


dbzfanatic
 Share

Recommended Posts

How do I call a function whenever the mouse moves? It works fine once when I start the loop but only once.

#RequireAdmin

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=C:\Users\Michael\Documents\pixeltest form.kxf
$Form1 = GUICreate("Color Getter", 448, 174, 193, 115)
$Graphic1 = GUICtrlCreateGraphic(280, 0, 161, 161)
$Label1 = GUICtrlCreateLabel("The color of the cursor position is: ", 280, 128, 161, 30)
$btnStart = GUICtrlCreateButton("Start the find process", 8, 16, 113, 17, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnStart
            Check()
    EndSwitch
WEnd

Func Check()
    Do
        $array = MouseGetPos()
        $color = PixelGetColor($array[0], $array[1])
        GUICtrlSetBkColor($Graphic1, $color)
        GUICtrlSetBkColor($Label1, $color)
        GUICtrlSetData($Label1,"The color of the cursor position is: " & $color)
    Until $GUI_EVENT_CLOSE
EndFunc

if it's in the help file please don't go all Posted Image on me, just point me to the proper function.

Edit: works when i have until 0>1 (infinite loop) but the GUI won't close this way.

Edited by dbzfanatic
Link to comment
Share on other sites

Thanks for all the help guys/girls, I guess there isn't really a built-in function so I'll have to do it the hard way :) thanks for the input and code snipets. It's very much appreciated :).

Link to comment
Share on other sites

Thanks for all the help guys/girls, I guess there isn't really a built-in function so I'll have to do it the hard way :) thanks for the input and code snipets. It's very much appreciated :).

You could use larrys mousehook to do this. Check out the source code in MacroGamer in my signature..... I have it calling a function when mouse moves to record mouse movements.

www.itoady.com

A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding

Link to comment
Share on other sites

There was a thread earlier about mousehook and it looked interesting but I don't know what it does, if you'd explain it to me I'd more than happily give it a look.

Link to comment
Share on other sites

Mousehook is a DLL that can give you global keyboard and mouse hooking. You can register the mouse normally in your script but it will only be local to that script. Just looking in MacroGamer.au3 and scroll to very bottom. All the code needed is there. You will also find kh.dll in the same place MacroGamer.zip is in. Hope that helps.

www.itoady.com

A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding

Link to comment
Share on other sites

Have not checked, but I think @Larry has removed the MouseHook posts and links?

Using MouseGetPos() should be better as you can control the polling frequency?

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