Is there a means of validating a ControlSetText command?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TXShooter
Posts: 165
Joined: 13 Dec 2017, 09:27

Is there a means of validating a ControlSetText command?

19 Oct 2018, 09:33

I'm having random lag and not-in-focus problems that I am trying to circumvent without the use of a 'Sleep' command as I'm trying to speed things up in my script, and I would rather just simply use a 'validate entry' feature instead. I thought of using While loops to confirm an entry has indeed been made in a child window's control (ie edit, combobox, checkbox, etc) before moving on, but I'm not having much success in the implementation of it.

Here's what I have, but in the end the MsgBox displays "" instead of the value that's supposed to be inserted into the Edit control (which also is still ""). I'm currently getting a warning that a local variable named 'If' isn't defined, which really throws me off.

Code: Select all

SetConsole(cCommand,vValue) {
			bState = ""		; Reset our validator
			ControlGet, ID, Hwnd,,Edit1, Child Window
			ControlFocus,, ahk_id %ID%
			While (WinExist("Child Window") && If (bState="")) {
				ControlSetText,, %cCommand%%vValue%, ahk_id %ID%
				ControlGetText, bState, ahk_id %ID%
			}
			MsgBox %bState%
(...)
}
I've tried this script with While (WinExist("Child Window") && bState="") { , but bState still is "" instead of the the value %cCommand%%vValue%.

And I've tried While,(WinExist("Child Window") && (bState<>"%cCommand%%vValue%")) { which never exits the While (bState doesn't get set).

Note:
For whatever reason, when I use Edit1, this particular Child Window that I'm dealing with will not accept an entry. It doesn't matter how long I set a Sleep cycle before implementing the command, the ClassNN property just doesn't work:

Code: Select all

Sleep, 10000
ControlSetText,Edit1, %cCommand%%vValue%, ahk_id %ID%
1) What am I missing on the While?
2) Is there an undocumented Validator switch for ControlSetText that will not continue until it can validate that the control's text was entered correctly?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Is there a means of validating a ControlSetText command?

19 Oct 2018, 11:39

Code: Select all

;before:
While (WinExist("Child Window") && If (bState="")) {
While,(WinExist("Child Window") && (bState<>"%cCommand%%vValue%")) {

;after:
while (WinExist("Child Window") && (bState="")) {
while (WinExist("Child Window") && (bState<>cCommand vValue)) {
Cheers.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
TXShooter
Posts: 165
Joined: 13 Dec 2017, 09:27

Re: Is there a means of validating a ControlSetText command?

19 Oct 2018, 19:07

jeeswg wrote:
19 Oct 2018, 11:39

Code: Select all

while (WinExist("Child Window") && (bState<>cCommand vValue)) {
Cheers.
Jeeswg,
Thank you! That does help.

Would it be a good idea to add a feature request that validates ControlSetText as complete before continuing, or has that already been done and we're waiting?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Is there a means of validating a ControlSetText command?

19 Oct 2018, 19:39

I would just use ControlGetText to check, or create a custom ControlSetText function that used ControlGetText to check.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
TXShooter
Posts: 165
Joined: 13 Dec 2017, 09:27

Re: Is there a means of validating a ControlSetText command?

20 Oct 2018, 19:44

jeeswg wrote:
19 Oct 2018, 19:39
I would just use ControlGetText to check, or create a custom ControlSetText function that used ControlGetText to check.
Ok, now you're just teasing me. lol. How does one go about creating a custom ControlSetText function?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Is there a means of validating a ControlSetText command?

20 Oct 2018, 20:09

I've never had any problems with ControlSetText, so I'm wondering if this is really the solution to your problem, however, here's a custom function.

Code: Select all

q::
ControlGetText, vText, Edit1, A
if (vText = "")
	MsgBox, % MyControlSetText("abc", "Edit1", "A")
return

MyControlSetText(vText, vControl:="", vWinTitle:="", vWinText:="", vExcludeTitle:="", vExcludeText:="")
{
	local
	ControlSetText, % vControl, % vText, % vWinTitle, % vWinText, % vExcludeTitle, % vExcludeText
	Loop, 5
	{
		ControlGetText, vText2, % vControl, % vWinTitle, % vWinText, % vExcludeTitle, % vExcludeText
		if (vText == vText2)
			return A_Index
		Sleep, 100
	}
	return 0
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
TXShooter
Posts: 165
Joined: 13 Dec 2017, 09:27

Re: Is there a means of validating a ControlSetText command?

21 Oct 2018, 17:47

jeeswg wrote:
20 Oct 2018, 20:09
I've never had any problems with ControlSetText, so I'm wondering if this is really the solution to your problem, however, here's a custom function.

Code: Select all

q::
ControlGetText, vText, Edit1, A
if (vText = "")
	MsgBox, % MyControlSetText("abc", "Edit1", "A")
return

MyControlSetText(vText, vControl:="", vWinTitle:="", vWinText:="", vExcludeTitle:="", vExcludeText:="")
{
	local
	ControlSetText, % vControl, % vText, % vWinTitle, % vWinText, % vExcludeTitle, % vExcludeText
	Loop, 5
	{
		ControlGetText, vText2, % vControl, % vWinTitle, % vWinText, % vExcludeTitle, % vExcludeText
		if (vText == vText2)
			return A_Index
		Sleep, 100
	}
	return 0
}
Jeeswg,
You're exhibiting the exact thing that I'm trying to get around... too much time.

In my current application (dealing with adding two detailed markers back-to-back in Reaper's DAW (End of song 1 / Start of song 2)), there's a lag between the time it takes for a child-window to pop up, type that entry using ControlSetText, (validate that entry) and close that window. By the time it's all said and done, the next calling for the next entry using the same pop up is come and gone, thus hanging things up and missing the 2nd entry completely. I can put pauses into just about everything and make ControlSetText work, but in this case I need speed and accuracy or the 2nd marker is off by several seconds, and the rendered product is starting at the wrong point. There's something about this Reaper that is slowing things down to the point that I'm having to back away from AHK and learn how to write scripts IN Reaper.

How exactly does AHK do it with ControlS/GetText? Is that a DLL Function?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Is there a means of validating a ControlSetText command?

21 Oct 2018, 17:56

- I think you need to describe the whole situation from start to finish. Consider mentioning the following:
- So you press/click something, and if you do nothing, a popup comes and goes, and another popup comes and goes.
- Do you ever have two popups visible at the same time?
- Is it possible to do what you want manually and reliably?
- (Can you change the amount of time a popup is visible?)

- It sounds like you need WinWait, and then ControlSetText. You could edit my function to do more loops, and wait a shorter amount of time.

- There is a ControlSetText function in script2.cpp, it uses SendMessage with WM_SETTEXT.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ArkuS, Google [Bot], mikeyww and 315 guests