Finding the number of the pressed gui button Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
spithaka
Posts: 3
Joined: 13 Apr 2019, 10:59

Finding the number of the pressed gui button

13 Apr 2019, 11:13

With the code shown I can find out the label of the button pressed and a rough way of getting the number of the button but I haven't been able to find anything telling me how, if I can, to get the number of the button completely accurately.

Code: Select all

ButtonArray := ["Apples", "Bananas", "Cabbage", "Dolomite", "Eberries", "Flotsam","Mushrooms","Chips","Curry","Damsons","Elderberries","Flan","A","B","C","D","E","F","A","B","C","D","E","Final"]
ButtonNumber := 1
TheNumberOfButton := 1
px := 20
py := 20
Gui, new,,Select a product
Gui, Show, W570 H760 X2000 Y1000,
loop 2
{
loop, 6
{
	MyButtonLabel := ButtonArray[ButtonNumber]
	posx = x%px%
	posy= y%py%
	Gui, Add, Button, gMyButtonLabel %posx% %posy% w80 h80, %MyButtonLabel%
	ButtonNumber := ButtonNumber + 1
	px := px + 90
}
px := 20
py := py+90
}
Gui, Show
return

MyButtonLabel:
Gui, Submit
CoordMode, Mouse, Window
MouseGetPos, MouseX, MouseY
Butty := floor( (MouseX+75) /90) + 6 * floor((MouseY-45) / 90) -4
MsgBox Button Pressed %A_GuiControl% Button %Butty%
ExitApp[Codebox=text file=Untitled.txt][/Codebox]
spithaka
Posts: 3
Joined: 13 Apr 2019, 10:59

Re: Finding the number of the pressed gui button

13 Apr 2019, 12:01

So I changed the code adding a loop in the section dealing with the pressed button which seems to work okay for me.

But is there not a simpler way?

Code: Select all

MyButtonLabel:
Exit :=0
loop
{
CoordMode, Mouse, Window
MouseGetPos, MouseX, MouseY,,Butty
Gui, Submit
Exit := 1
}
until Exit = 1
;Butty := floor( (MouseX+75) /90) + 6 * floor((MouseY-45) / 90) -4
MsgBox Label of Button Pressed %A_GuiControl% Number of Button Pressed %Butty%
ExitApp
garry
Posts: 3764
Joined: 22 Dec 2013, 12:50

Re: Finding the number of the pressed gui button  Topic is solved

13 Apr 2019, 12:38

I tried this, control / vVariable

Code: Select all

ButtonArray := ["Apples", "Bananas", "Cabbage", "Dolomite", "Eberries", "Flotsam","Mushrooms","Chips","Curry","Damsons","Elderberries","Flan"]
ButtonNumber := 1
px := 20
py := 20
Gui, new,,Select a product
Gui, Show, W570 H760 X2000 Y1000,
i=0
loop 2
{
loop, 6
{
i++
	MyButtonLabel := ButtonArray[ButtonNumber]
	posx = x%px%
	posy= y%py%
	Gui, Add, Button, gMyButtonLabel2 %posx% %posy%  w80 h80 v%i%_%MyButtonLabel%  , %MyButtonLabel%
	ButtonNumber := ButtonNumber + 1
	px := px + 90
}
px := 20
py := py+90
}
Gui, Show
return
Guiclose:
exitapp

MyButtonLabel2:
Gui, Submit,nohide
Mousegetpos,,,,Control
MsgBox,You Pressed Button %A_GuiControl%`n%control%   ;- control (Button1-12)
return
;=========================================

spithaka
Posts: 3
Joined: 13 Apr 2019, 10:59

Re: Finding the number of the pressed gui button

14 Apr 2019, 03:13

That's great, thanks for your help garry. I tried searching on this topic but got nowhere so it's nice to get such a quick and helpful response.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 388 guests