The documentation for the GUI's button control seems to be wrong.

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
daiaji
Posts: 2
Joined: 29 May 2017, 19:13

The documentation for the GUI's button control seems to be wrong.

Post by daiaji » 14 Aug 2022, 09:07

https://www.autohotkey.com/docs/commands/GuiControls.htm#Button

Code: Select all

#Requires AutoHotkey v2.0-beta

#n::
{
	MyGui := Gui()
	MyBtn := MyGui.Add("Button", "Default w80", "OK")
	MyBtn.OnEvent("Click", MyBtn_Click())  ; 当点击时调用 MyBtn_Click.
}

MyBtn_Click() {
	Msgbox "OK"
}
I wrote these codes and run.
But when I press Win+n, the MyBtn_Click function seems to be executed immediately.
But according to the introduction in the documentation, this function should be called after I click the OK button?

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: The documentation for the GUI's button control seems to be wrong.

Post by swagfag » 14 Aug 2022, 10:16

"the MyBtn_Click function seems to be executed immediately" because that is precisely what u instructed ahk to do: MyBtn.OnEvent("Click", MyBtn_Click()) - call the function
also, ure linking to v1 docs
also, u dont understand the v2 docs(u need to pass a function reference, not call the function. in other words: MyBtn.OnEvent("Click", MyBtn_Click))
also, u still dont understand the v2 docs(ur click handler is declared as a 0-ary function and will blow up as soon as the Click event would attempt to inject GuiCtrlObj and Info when calling the handler function)

Post Reply

Return to “Ask for Help (v2)”