Mouse click is detected -> gui destroyed. How?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
teosc
Posts: 54
Joined: 17 Jun 2017, 04:56

Mouse click is detected -> gui destroyed. How?

24 Jun 2017, 04:35

Hi guys, I want to introduce the following function to my script:

"If a mouse click is detected on the active window -> gui destroyed"

How can I proceed?
Thank you very much
Last edited by teosc on 03 Jul 2017, 05:03, edited 1 time in total.
User avatar
boiler
Posts: 16915
Joined: 21 Dec 2014, 02:44

Re: Mouse click is detected -> gui destroyed. How?

24 Jun 2017, 05:10

I'm assuming that by "on the active window" you mean the GUI window. If so:

Assign your GUI's hwnd to a variable called GuiID by adding +HwndGuiID to your first GUI command, and add this conditional hotkey definition:

Code: Select all

#IfWinActive, ahk_id %GuiID%
LButton::Gui, Destroy
If you mean any window as long as it's active, then set a LButton hotkey, and destroy the GUI if the window under the mouse is the active window. If it's not, just send a click so it behaves normally.
teosc
Posts: 54
Joined: 17 Jun 2017, 04:56

Re: Mouse click is detected -> gui destroyed. How?

24 Jun 2017, 10:38

Thanks, but in this way the click function is canceled .... because it looks like hotkeys.

Each command with the LButton does not run.

Or am I wrong?
User avatar
boiler
Posts: 16915
Joined: 21 Dec 2014, 02:44

Re: Mouse click is detected -> gui destroyed. How?

24 Jun 2017, 11:40

The hotkey is activated only if the GUI window is active. That's what the directive in the first line does.

If you're talking about the 2nd approach, that's why you send a click otherwise.
teosc
Posts: 54
Joined: 17 Jun 2017, 04:56

Re: Mouse click is detected -> gui destroyed. How?

24 Jun 2017, 13:30

Can not destroy gui "after" any command sent to the active window?

I'm looking but I do not find a solution...
User avatar
boiler
Posts: 16915
Joined: 21 Dec 2014, 02:44

Re: Mouse click is detected -> gui destroyed. How?

24 Jun 2017, 19:54

I don't know what you mean by any command sent to the active window. Commands sent by who or what? You want to destroy the gui any time any command is sent to whichever window is active?
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Mouse click is detected -> gui destroyed. How?

24 Jun 2017, 21:08

----> The gui keeps getting created because the settimer is still running and creating them. <----

If this is going to be more than a one time use consider hiding the gui and not destroying it.
Then show and hide as needed.

HTH
teosc
Posts: 54
Joined: 17 Jun 2017, 04:56

Re: Mouse click is detected -> gui destroyed. How?

25 Jun 2017, 02:33

boiler wrote:I don't know what you mean by any command sent to the active window. Commands sent by who or what? You want to destroy the gui any time any command is sent to whichever window is active?

Yes, after each command or typing or any interaction sent by me manually in the active window, for example after a mouse click or a typing of some letter or number with keyboard, ecc.

Sorry for my bad english :facepalm:
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Mouse click is detected -> gui destroyed. How?

25 Jun 2017, 03:03

boiler wrote:#IfWinActive, ahk_id %GuiID%
This is not valid. #IfWinActive does not support variables.

If you want to detect mouse clicks on the GUI itself and do not need the mouse hook for some other reason, it is much better to use OnMessage(0x201, ...) than a mouse hotkey. However, I guess that's not what teosc wants.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Mouse click is detected -> gui destroyed. How?

25 Jun 2017, 07:10

Re. #IfWinActive you could do something like this:

Code: Select all

Gui, +Lastfound +AlwaysOnTop +Toolwindow +HwndhWnd
GroupAdd, WinGroupGui, % "ahk_id " hWnd
;...
return

#IfWinActive, ahk_group WinGroupGui
LButton::Gui, Destroy
Although as was said, OnMessage has its benefits.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
teosc
Posts: 54
Joined: 17 Jun 2017, 04:56

Re: Mouse click is detected -> gui destroyed. How?

25 Jun 2017, 14:44

I'm trying to introduce "onmessage" in my script to destroy / hide frame border after any click or typing in the active window.
But it does not seem to work, where am I wrong?
Last edited by teosc on 03 Jul 2017, 05:03, edited 1 time in total.
User avatar
boiler
Posts: 16915
Joined: 21 Dec 2014, 02:44

Re: Mouse click is detected -> gui destroyed. How?

25 Jun 2017, 18:41

A few issues with your script:
- You should have a return after your border_color assignment to mark the end of the auto-execute section of your script.
- You should have gotten a nonexistent function error with IfWinExist("A"). However, if you add a space between the If and WinExist to make it legal syntax, then it's a meaningless line. The result of that conditional statement will always be true because the active window (whatever it happens to be at that time) exists by definition.
- You shouldn't have a function call inside of the DrawRect subroutine (or any subroutine, really). Move the Guidestroy function to the end of the script, or before the MButton hotkey definition.
- You should put the OnMessage(0x201, "Guidestroy") line up in the auto-execute section. It will automatically trigger a call to Guidestroy when the GUI is clicked on.
-There will be likely be more things to clean up, but it doesn't make sense to talk about them until the above items are cleaned up.
teosc
Posts: 54
Joined: 17 Jun 2017, 04:56

Re: Mouse click is detected -> gui destroyed. How?

26 Jun 2017, 03:52

boiler wrote:A few issues with your script:
- You should have a return after your border_color assignment to mark the end of the auto-execute section of your script.
- You should have gotten a nonexistent function error with IfWinExist("A"). However, if you add a space between the If and WinExist to make it legal syntax, then it's a meaningless line. The result of that conditional statement will always be true because the active window (whatever it happens to be at that time) exists by definition.
- You shouldn't have a function call inside of the DrawRect subroutine (or any subroutine, really). Move the Guidestroy function to the end of the script, or before the MButton hotkey definition.
- You should put the OnMessage(0x201, "Guidestroy") line up in the auto-execute section. It will automatically trigger a call to Guidestroy when the GUI is clicked on.
-There will be likely be more things to clean up, but it doesn't make sense to talk about them until the above items are cleaned up.

Many many many thanks.
The observation regarding the ifwinexist function is right, what I want is that not every "message 0x201" is considered but only those sent in the active window and next popup window (by third app) the script resume drawing board!
(But I do not know how to do it :( )
I'm trying to implement your suggestions, this is how I changed but not successful.
Last edited by teosc on 03 Jul 2017, 05:13, edited 1 time in total.
User avatar
boiler
Posts: 16915
Joined: 21 Dec 2014, 02:44

Re: Mouse click is detected -> gui destroyed. How?

26 Jun 2017, 07:52

OnMessage is only going to detect clicks on your GUI, not any other window. And even if that's OK, as Lexikos suggested, it's probably still not a fit for your goal. But I'm not fully understanding what your goal is. If you are first trying to determine if the window was already active when it got clicked on, OnMessage will alert you after it was clicked, and it will be made active by clicking on it before you have a chance to see if it already was.

That's why I was suggesting using a LButton hotkey because you hijack it before it registers a click, and you can see if the window under the mouse is active and you can destroy the GUI. If it's not, then you can send the click so it will behave as a normal mouse click.
teosc
Posts: 54
Joined: 17 Jun 2017, 04:56

Re: Mouse click is detected -> gui destroyed. How?

28 Jun 2017, 16:52

boiler wrote: That's why I was suggesting using a LButton hotkey because you hijack it before it registers a click, and you can see if the window under the mouse is active and you can destroy the GUI. If it's not, then you can send the click so it will behave as a normal mouse click.
It is exactly what I would like to do but also in the active window I would like the lbutton to be considered first as a command and only then as a hotkey.

When I click on a point i would like before the Lclick would be considered as a simple click, and only then as hotkey for destroy gui ... without setting a double click!

It's possible?
User avatar
boiler
Posts: 16915
Joined: 21 Dec 2014, 02:44

Re: Mouse click is detected -> gui destroyed. How?

28 Jun 2017, 19:10

I don't know what you mean that you want it considered first as a command then as a hotkey. By setting it as a hoykey, you can have it do whatever you want. You can execute other commands, you can send a mouse click, or whatever.
teosc
Posts: 54
Joined: 17 Jun 2017, 04:56

Re: Mouse click is detected -> gui destroyed. How?

29 Jun 2017, 05:15

boiler wrote:I don't know what you mean that you want it considered first as a command then as a hotkey. By setting it as a hoykey, you can have it do whatever you want. You can execute other commands, you can send a mouse click, or whatever.
Edit, ty
Last edited by teosc on 03 Jul 2017, 05:13, edited 2 times in total.
User avatar
boiler
Posts: 16915
Joined: 21 Dec 2014, 02:44

Re: Mouse click is detected -> gui destroyed. How?

29 Jun 2017, 05:56

What do you mean by "find the command on 'Find Seat'"? Do you mean you want to determine if the mouse is over the Find Seat button, and if so, then destroy the frame Gui without sending a click? And if it's not on that button, then send a click as normal?

If so, that's exactly what I described in the approach I outlined.
teosc
Posts: 54
Joined: 17 Jun 2017, 04:56

Re: Mouse click is detected -> gui destroyed. How?

29 Jun 2017, 12:21

boiler wrote:What do you mean by "find the command on 'Find Seat'"? Do you mean you want to determine if the mouse is over the Find Seat button, and if so, then destroy the frame Gui without sending a click? And if it's not on that button, then send a click as normal?

If so, that's exactly what I described in the approach I outlined.
No no, much more simply I would like any click made on the active window ... actually appear as a click rather than as a hotkey.

If I click somewhere in the active window, such as "Find Seat", I would like to actually click on Find Seat and only after it is considered as a variable to destroy gui.
If I set LButton as hotkeys to destroy the frame border, the click I send does not occur on the Find Seat button but is eaten by AHK as a hotkey.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: CrowexBR, Google [Bot], montie, Rohwedder and 202 guests