How to specify parameters for ControlClick?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Cyrano
Posts: 12
Joined: 29 Mar 2023, 17:03

How to specify parameters for ControlClick?

Post by Cyrano » 30 Mar 2023, 11:38

I've got ControlClick working for single clicks, but I haven't been successful in getting double-clicks.

I understand the documentation to mean that a maximum of 8 parameters can be specified:
Image

I also understand this to mean that if one chooses to omit any parameters while also attempting to specify parameters of higher number, then one must use commas to tell AHK which higher-number parameter is being specified.

In the following script, my intent is:
  • When a user keystroke of lowercase b is entered, it executes a single click on the control "Static232" in window 797108.
  • When a user keystroke of uppercase B is entered, it executes a double click on the control "Static232" in window 797108.
When I run this script, hotkey b works as intended. Hotkey B does not; it appears to have the same effect as does hotkey b.

Code: Select all

b::
{
   ControlClick  "Static232", 797108
	return
}

+b::
{
   ControlClick  "Static232", 797108,  ,  ,  2
	return
}

User avatar
mikeyww
Posts: 26947
Joined: 09 Sep 2014, 18:38

Re: How to specify parameters for ControlClick?

Post by mikeyww » 30 Mar 2023, 12:45

Hello,

This worked for me in Notepad. It needed a brief delay before the release.

Code: Select all

#Requires AutoHotkey v2.0
winTitle := 'ahk_exe notepad.exe'
x        := 50
y        := 14

+b:: {
 ControlClick  'X' x ' Y' y, winTitle,,, 2, 'D'
 Sleep 25
 ControlClick  'X' x ' Y' y, winTitle,,, 2, 'U'
 SoundBeep 1000
}
EDIT: I realized that this script doesn't make sense.
Last edited by mikeyww on 30 Mar 2023, 13:42, edited 1 time in total.

Rohwedder
Posts: 7647
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How to specify parameters for ControlClick?

Post by Rohwedder » 30 Mar 2023, 13:09

Hallo,
ControlClick does not automatically release the modifier keys.
Perhaps?:

Code: Select all

+b::
{
   KeyWait "Shift"
   ControlClick  "Static232", 797108,  ,  ,  2
}

User avatar
mikeyww
Posts: 26947
Joined: 09 Sep 2014, 18:38

Re: How to specify parameters for ControlClick?

Post by mikeyww » 30 Mar 2023, 13:35

Yeah, I guess my last script didn't actually make any sense, and yet this newer script does not fully work as I expected. I'll do some more testing....

If you're looking to select text: is that the goal, and does anyone know if it's possible with ControlClick?

Cyrano
Posts: 12
Joined: 29 Mar 2023, 17:03

Re: How to specify parameters for ControlClick?

Post by Cyrano » 30 Mar 2023, 14:08

Alas, neither suggestion was effective.

I've found a workaround (involving a different control), so there's no urgency at the moment to get this resolved ... but the engineer in me would sure like to figure it out eventually. :geek:

Cyrano
Posts: 12
Joined: 29 Mar 2023, 17:03

Re: How to specify parameters for ControlClick?

Post by Cyrano » 30 Mar 2023, 16:09

mikeyww wrote:
30 Mar 2023, 13:35
If you're looking to select text: is that the goal, and does anyone know if it's possible with ControlClick?
No, I don't need to select text. I just want to double-click on the control, which when done manually has a desired effect.

User avatar
mikeyww
Posts: 26947
Joined: 09 Sep 2014, 18:38

Re: How to specify parameters for ControlClick?

Post by mikeyww » 30 Mar 2023, 19:51

OK. I think that Rohwedder's script should have worked, but some windows or controls do not respond to these Control... functions.

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

Re: How to specify parameters for ControlClick?

Post by swagfag » 31 Mar 2023, 04:10

physically double-clicking the left mouse button need not be functionally equivalent to PostMessaging(WM_LBUTTONDOWN/UP) twice (which is what ControlClick does in the background) to some random control in a random window
what the observed behavior will be, depends on how the receiving application will decide to process these messages

User avatar
mikeyww
Posts: 26947
Joined: 09 Sep 2014, 18:38

Re: How to specify parameters for ControlClick?

Post by mikeyww » 31 Mar 2023, 04:27

Is there a better way to simulate it?

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

Re: How to specify parameters for ControlClick?

Post by swagfag » 31 Mar 2023, 05:09

who knows, depends on the application. most of the time ur express goal is not actually to click something twice but to get at whatever effect the action of clicking something twice would lead to. there may be other ways of triggering this effect that dont involve clicking

User avatar
mikeyww
Posts: 26947
Joined: 09 Sep 2014, 18:38

Re: How to specify parameters for ControlClick?

Post by mikeyww » 31 Mar 2023, 05:20

Thank you, swagfag.

Rohwedder
Posts: 7647
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How to specify parameters for ControlClick?

Post by Rohwedder » 31 Mar 2023, 06:19

Maybe Lexikos's (v1) ControlFromPoint() will help you?
https://www.autohotkey.com/board/topic/15458-controlclick-fails-to-perform-a-double-click-in-the-pos-mode/
Lexikos: "You can manually send WM_LBUTTONDBLCLICK and WM_LBUTTONUP messages to the control. Seems to work in my C++.net test app, but not the Mouse Properties dialog..."

Post Reply

Return to “Ask for Help (v2)”