Jump to content
Sign in to follow this  
dbzfanatic

Call a function when the mouse moves

Recommended Posts

dbzfanatic

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

Share this post


Link to post
Share on other sites
dbzfanatic
qazwsx

also u could but ur _check func in case else so u can loop it but still close the gui.

Share this post


Link to post
Share on other sites
dbzfanatic

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

Share this post


Link to post
Share on other sites
Toady

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

Share this post


Link to post
Share on other sites
dbzfanatic

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.

Share this post


Link to post
Share on other sites
Toady

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

Share this post


Link to post
Share on other sites
Uten

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?

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.