ControlClick On Text

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
scriptor2016
Posts: 863
Joined: 21 Dec 2015, 02:34

ControlClick On Text

Post by scriptor2016 » 31 Dec 2017, 00:33

Greetings

I have a GUI which is named MyGUI.

It contains hundreds of controls. One of the controls is named MYCONTROL. When I use the advanced Window Spy, and I hover the cursor ontop of this control, the "Text" is surely identified as MYCONTROL. The ClassNN shows as Static217, but this will change as I add more code to MyGUI in the future.

Next, I want to controlclick on it while working in a different application, such as Notepad. So here is my simple code:

Code: Select all

b::
ControlClick, MYCONTROL, MYGUI
Return
But this does not work. I have exhausted my search in the tutorials and on the forums. Unfortunately this seems so simple but I can't find the answer :(

How should I do this simple task?

Thanks for any help!

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: ControlClick On Text

Post by BoBo » 31 Dec 2017, 10:03

Are these AHK Gui controls?

User avatar
boiler
Posts: 17079
Joined: 21 Dec 2014, 02:44

Re: ControlClick On Text

Post by boiler » 31 Dec 2017, 10:37

@BoBobo: Yes, what he described are AHK Gui controls.

@scriptor2016: Make sure that the case matches exactly. You said your Gui name is MyGui, but you put MYGUI in for the WinTitle. That will not be a match. Per the documentation:
Regardless of the current TitleMatchMode, WinTitle, WinText, ExcludeTitle and ExcludeText are case sensitive.

scriptor2016
Posts: 863
Joined: 21 Dec 2015, 02:34

Re: ControlClick On Text

Post by scriptor2016 » 31 Dec 2017, 14:36

sorry, my mistake - yes, the case matches exactly. ANd it is indeed an AHK control. It can be dragged around inside the GUI, so using x/y co-ordinates to click on it wouldn't work since the control might be in different places at any given time

User avatar
KuroiLight
Posts: 327
Joined: 12 Apr 2015, 20:24
Contact:

Re: ControlClick On Text

Post by KuroiLight » 31 Dec 2017, 14:43

Does the control have a title? please post the line in which the control is added.
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]

scriptor2016
Posts: 863
Joined: 21 Dec 2015, 02:34

Re: ControlClick On Text

Post by scriptor2016 » 31 Dec 2017, 14:52

ok, hang on..

scriptor2016
Posts: 863
Joined: 21 Dec 2015, 02:34

Re: ControlClick On Text

Post by scriptor2016 » 31 Dec 2017, 14:55

This line of code is in the GUI that I want to perform the controlclick on. The name of this gui is MYGUI

Code: Select all

Gui, 1: Add, text, %colorgreen% x%xpos_001% y%ypos_001% vMYCONTROL gAppLaunch, MYCONTROL

and then in a seperate script, I have this code:

Code: Select all

space::

ControlClick, MYCONTROL, MYGUI
Return

Guest

Re: ControlClick On Text

Post by Guest » 31 Dec 2017, 14:57

Controlgetpos...

User avatar
boiler
Posts: 17079
Joined: 21 Dec 2014, 02:44

Re: ControlClick On Text

Post by boiler » 31 Dec 2017, 15:15

When you say the name of that GUI, do you mean the title of the window is MYGUI?

Also, you might want to try Static217 or whatever it may change to. I've had success addressing GUI controls that way. If the controls you add are after that one, it should stay at Static217.

scriptor2016
Posts: 863
Joined: 21 Dec 2015, 02:34

Re: ControlClick On Text

Post by scriptor2016 » 31 Dec 2017, 15:23

Yes, the window title is MYGUI.
I even tried replacing MYCONTROL with Static217 and still nothing happens. But I would prefer to not go that route because I would then need to match hundreds of Static controls with their text names, and since this is a script which is constantly being updated and added to, I think it might become too much of a headache.

The documentation says we can controlclick a control using its text using Mode 2, but it doesn't elaborate on it.

User avatar
boiler
Posts: 17079
Joined: 21 Dec 2014, 02:44

Re: ControlClick On Text

Post by boiler » 31 Dec 2017, 21:26

I see the problem. You are clicking on a text control. What do you expect to happen when you click on text? I was assuming it was a button.

scriptor2016
Posts: 863
Joined: 21 Dec 2015, 02:34

Re: ControlClick On Text

Post by scriptor2016 » 31 Dec 2017, 21:35

From the documentation:
Mode 2 (ClassNN or Text): Specify either ClassNN (the classname and instance number of the control) or the name/text of the control, both of which can be determined via Window Spy. When using name/text, the matching behavior is determined by SetTitleMatchMode.

This is what made me think that a controlclick could be performed on a text control. I suppose maybe it can't be done after all.

User avatar
boiler
Posts: 17079
Joined: 21 Dec 2014, 02:44

Re: ControlClick On Text

Post by boiler » 31 Dec 2017, 21:44

Hmm, well, I suppose you still can. So I guess it's supposed to run your routine called AppLaunch. So, I suppose that should still work.

User avatar
boiler
Posts: 17079
Joined: 21 Dec 2014, 02:44

Re: ControlClick On Text

Post by boiler » 31 Dec 2017, 21:50

You must have some other issue because these two scripts work for me:

Script 1:

Code: Select all

Gui, Add, Text, vMyControl gMySub, Click Me
Gui, Show, w200 h100, My GUI
return

MySub:
	MsgBox, Hi there
return
Script 2:

Code: Select all

ControlClick, Click Me, My GUI
I run the first script, and it shows the GUI. Then I run the second script, and it clicks the text which runs the subroutine that shows the MsgBox. That's what I was trying to get you to do. Make simple scripts to isolate what you think the problem is. This shows that it's not what you think. You must have some other problem with your scripts.

scriptor2016
Posts: 863
Joined: 21 Dec 2015, 02:34

Re: ControlClick On Text

Post by scriptor2016 » 31 Dec 2017, 22:19

Yes, you are indeed correct! Your script works. So the problem is on my end with my code. And I think I see where my problem is. A left click on the text control goes right to "gApplaunch" .

And when gApplaunch is activated, the first thing it does is:

Code: Select all

gApplaunch:
KeyWait, LButton, T0.15
If ErrorLevel ; the left click was held down for more than .15 seconds, so goto ControlMove on the next line: 
 {
GoTo, ControlMove ;ControlMove is where the control will be dragged while LButton is still held down
}
else
{
msgbox, you left clicked on MYCONTROL ;the left click down/up happened in under .15 seconds, so it is registered as a normal left click:
}
Return
I think maybe the problem is with the Keywait command. If the controlclick is performed normally (left down and then left up) in under .15 seconds, then it goes to the messagebox (which is what I am trying to do). But because it isn't working, is it maybe going to ControlMove instead?

Is a control click carried out in under .15 seconds by default or is it maybe exceeding the .15 seconds and then moving on to ControlMove?

User avatar
boiler
Posts: 17079
Joined: 21 Dec 2014, 02:44

Re: ControlClick On Text

Post by boiler » 31 Dec 2017, 22:29

Well actually, your main problem is that gApplaunch never gets launched because you are not supposed to put the g in front of it. The gApplaunch in the Gui command tells it to go to a subroutine called Applaunch, not gApplaunch. It's weird that you didn't get an error saying it couldn't find the Applaunch label.

scriptor2016
Posts: 863
Joined: 21 Dec 2015, 02:34

Re: ControlClick On Text

Post by scriptor2016 » 31 Dec 2017, 22:46

oh man, sorry - the g isn't actually there, I mistakenly put that in. My mistake. This is what is really is:

Code: Select all

Applaunch:
KeyWait, LButton, T0.15
If ErrorLevel ; the left click was held down for more than .15 seconds, so goto ControlMove on the next line: 
 {
GoTo, ControlMove ;ControlMove is where the control will be dragged while LButton is still held down
}
else
{
msgbox, you left clicked on MYCONTROL ;the left click down/up happened in under .15 seconds, so it is registered as a normal left click:
}
Return

User avatar
boiler
Posts: 17079
Joined: 21 Dec 2014, 02:44

Re: ControlClick On Text

Post by boiler » 31 Dec 2017, 22:57

Well, I guess you just need to play with the timing. If you’re wondering if it’s even launching that subroutine, then just make it a simple MsgBox and nothing else.

scriptor2016
Posts: 863
Joined: 21 Dec 2015, 02:34

Re: ControlClick On Text

Post by scriptor2016 » 31 Dec 2017, 22:59

thanks boiler. It will take some more troubleshooting but the code you provided does indeed work so I know that it can be done, I'll just have to play around with it some more :)

Post Reply

Return to “Ask for Help (v1)”