ControlClick to click on X of window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
marcela
Posts: 4
Joined: 17 Sep 2017, 17:37

ControlClick to click on X of window

17 Sep 2017, 17:44

Hi ,

In shortcut :

ControlClick, X971 Y5, ahk_class Chrome_WidgetWin_1

Which is X in Chrome, used to close window.
In some other apps same... mean nothing happens.
Why ControlClick wont work for click X on titlebar ? I have checked it on other areas of window and works fine.

Please help!
Thank You
:beer:
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: ControlClick to click on X of window

18 Sep 2017, 02:54

Why you don't use Process to shut down that chrome instance?
marcela
Posts: 4
Joined: 17 Sep 2017, 17:37

Re: ControlClick to click on X of window

18 Sep 2017, 03:42

My project needs exactly "click method" not "process" one.

Anybody willing to help ? Please
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: ControlClick to click on X of window

18 Sep 2017, 03:47

I would recommend to use WinClose:

Code: Select all

q::
WinClose, ahk_class Chrome_WidgetWin_1
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
marcela
Posts: 4
Joined: 17 Sep 2017, 17:37

Re: ControlClick to click on X of window

18 Sep 2017, 04:26

Hi,
It cant be WinClose , my project needs a click method. Any ideas ?
marcela
Posts: 4
Joined: 17 Sep 2017, 17:37

Re: ControlClick to click on X of window

18 Sep 2017, 06:40

alt f4 is not a click. i need only click by mouse method. any ideas ?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: ControlClick to click on X of window

18 Sep 2017, 15:17

I've provided some methods which use Acc to invoke the close button, or to locate its position. I have also provided a two-liner to close Chrome. Btw are you sure that the problem is not Admin windows?

Code: Select all

q:: ;chrome - click close button
WinGetPos, vWinX, vWinY, vWinW, vWinH, A
ControlClick, % Format("X{} Y{}", vWinW-45, 10), A
return

;==============================

;Acc library (MSAA) and AccViewer download links - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

;w:: ;notepad - get close button location
WinGet, hWnd, ID, A
oAcc := Acc_Get("Object", "2", 0, "ahk_id " hWnd)
oRect := Acc_Location(oAcc, 5)
vAccLocation := Format("x{} y{} w{} h{}", oRect.x, oRect.y, oRect.w, oRect.h)
;oAcc.accDoDefaultAction(5) ;invoke close
MsgBox, % vAccLocation
oAcc := oRect := ""
return

;==============================

;e:: ;chrome - get close button location
WinGet, hWnd, ID, A
WinGetPos, vWinX, vWinY, vWinW, vWinH, % "ahk_id " hWnd
oAcc := Acc_Get("Object", "4.1.1.4", 0, "ahk_id " hWnd)
oRect := Acc_Location(oAcc)
vAccLocation := Format("x{} y{} w{} h{}", oRect.x, oRect.y, oRect.w, oRect.h)
vAccLocation2 := Format("{} {}", oRect.x-vWinX-vWinW, oRect.y-vWinY)
;oAcc.accDoDefaultAction(0) ;invoke close
;MsgBox, % vAccLocation
MsgBox, % vAccLocation2
oAcc := oRect := ""
return

;vAccLocation2:
;the position of the close button (it's top-left corner)
;relative to the top-right corner of the window
;when the window is maximised/not maximised:
;not full screen: -47 1
;full screen: -54 8
;so click at for example: (width-45, 10)
;that coordinate will contain the close button
;whether the window is maximised or not

;q:: ;chrome - click close button
;WinGetPos, vWinX, vWinY, vWinW, vWinH, A
;ControlClick, % Format("X{} Y{}", vWinW-45, 10), A
;return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: ControlClick to click on X of window

18 Sep 2017, 15:38

I did some tests and like you said: ControlClick works on some areas of the window but not others. E.g. I was able to click on Notepad, on the Edit control, below the minimise button (causing the caret to be moved to the text there), but not on the minimise button.

Generally speaking the title bar is not a control, and that's probably why it's failing to work on title bar buttons, even when the coordinates are correct. Google Chrome is the exception, not the rule, because its close button is part of a control. Also, look up the term: non-client area.

To invoke close therefore, you could use the Acc library (see above), WinClose, MouseClick/Click, Send and {Click}, WM_LBUTTONDOWN/WM_LBUTTONUP.

For an example with WM_LBUTTONDOWN/WM_LBUTTONUP, see 'click without moving the cursor', at:
jeeswg's documentation extension tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=33596
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
icuurd12b42
Posts: 202
Joined: 14 Aug 2016, 04:08

Re: ControlClick to click on X of window

20 Sep 2017, 02:19

why do you need the "Click Method"? Clicking the X on the title bar is the same as clicking the left Control Box and selecting the close menu... is the same as hitting alt f4, is the same as calling WinClose, is the same as sending the window a WM_CLOSE message. All these close the window and chrome should run the exact same code internally.

I'm asking because
1) I am intrigued by your insistance because
2) how you get the window to close should yield the same result internally in chrome

Do you have a hidden window on top of the close button or something that reacts to the mouse?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb and 299 guests