Page 1 of 1

GuiLButton similar to GuiEscape?

Posted: 10 May 2021, 10:46
by likethevegetable
I'm playing around with simple gui's with AHK. In one example I found, pressing the escape key will exit the gui, example shown below. I would like to replicate this behavior, but for a right or left click of the mouse. Is there an equivalent, perhaps GuiLButton?

Code: Select all

GuiEscape:
    gui_destroy()
    return

Re: GuiLButton similat to GuiEscape?  Topic is solved

Posted: 10 May 2021, 11:09
by mikeyww

Code: Select all

LButton::
RButton::
GuiEscape:
Gui, Destroy
Return
Alternative is OnMessage with a system message. OnMessage pertains only to the script's window, which in most uses pertains to a GUI.

Re: GuiLButton similat to GuiEscape?

Posted: 10 May 2021, 11:11
by likethevegetable
Does this effectively remap my LButton and RButton permanently? Any chance this may impact my computer's performance?

Re: GuiLButton similat to GuiEscape?

Posted: 10 May 2021, 11:36
by likethevegetable
I found that this solution blocks Lbutton and Rbutton. My concern is that this remaps the clicks. I would only want LButton and RButton to be remapped if the GUI is opened.

Re: GuiLButton similat to GuiEscape?

Posted: 10 May 2021, 11:50
by mikeyww
Yes, the buttons are "trapped" until changed, or until the script exits. If you just want to click on the GUI instead, then see the alternative that I mentioned in the post.

More broadly, one can use an #If directive to provide a required context for a hotkey; explained in the documentation, with examples.

I have never found that the mere existence of a hotkey affects performance. You can always measure it through a CPU monitor, etc. The design of a hotkey routine could affect performance when that routine is being executed.