Sign in to follow this  
Followers 0
InjuredDeer

If Gui Button Pushed Then?

3 posts in this topic

im making a Gui that when presssing on the button will activate a function. i stopped coding about 10 years ago with au3 and decided to start back up because it is so damn fun.

so when i push down on $bottomright1 i want it to run func mousepos()

$Form1_1 = GUICreate("Form1", 442, 241, 186, 145)
$TopLeft = GUICtrlCreateButton("TopLeft", 72, 16, 75, 25)
$TopLeft2 = GUICtrlCreateButton("TopLeft2", 72, 56, 75, 25)
$TopLeft3 = GUICtrlCreateButton("TopLeft3", 72, 96, 75, 25)
GUICtrlCreateLabel("", 312, 16, 4, 4)
$BottomRight2 = GUICtrlCreateButton("BottomRight2", 152, 56, 73, 25)
$BottomRight1 = GUICtrlCreateButton("BottomRight1", 152, 16, 73, 25)
$BottomRight3 = GUICtrlCreateButton("BottomRight3", 152, 96, 73, 25)

GUISetState(@SW_SHOW)



Func MousePos()
 
 Local $aMgp = 0

    
    While 1
       
        $aMgp = MouseGetPos()

      
        ToolTip("x: " & $aMgp[0] & ", y: " & $aMgp[1], $aMgp[0] + 10, $aMgp[1] + 10)

        
        Sleep(50)
    WEnd
EndFunc   

Func _Terminate()
    Exit
EndFunc

 

Share this post


Link to post
Share on other sites



@InjuredDeer welcome to the forum. You need a while loop to look for activity on your GUI, like so:

#include <GUIConstantsEx.au3>

$Form1_1 = GUICreate("Form1", 442, 241, 186, 145)
$TopLeft = GUICtrlCreateButton("TopLeft", 72, 16, 75, 25)
$TopLeft2 = GUICtrlCreateButton("TopLeft2", 72, 56, 75, 25)
$TopLeft3 = GUICtrlCreateButton("TopLeft3", 72, 96, 75, 25)
GUICtrlCreateLabel("", 312, 16, 4, 4)
$BottomRight2 = GUICtrlCreateButton("BottomRight2", 152, 56, 73, 25)
$BottomRight1 = GUICtrlCreateButton("BottomRight1", 152, 16, 73, 25)
$BottomRight3 = GUICtrlCreateButton("BottomRight3", 152, 96, 73, 25)

GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $BottomRight1
                MousePos()
        EndSwitch
    WEnd

Func MousePos()
 Local $aMgp = 0
    While 1
        $aMgp = MouseGetPos()
        ToolTip("x: " & $aMgp[0] & ", y: " & $aMgp[1], $aMgp[0] + 10, $aMgp[1] + 10)
        Sleep(50)
    WEnd
EndFunc

Func _Terminate()
    Exit
EndFunc

Be aware that once you enter your MousePos function you have created an endless While Loop, so it will never leave that function.

1 person likes this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

thankyou so much! and yes thankyou for looking at the mousepos() i knew it was endless but thankyou for commenting that also. 

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  
Followers 0