Jump to content

Recommended Posts

Posted

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

 

  • Moderators
Posted

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...