Strange ControlGet Behavior Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
morreo
Posts: 27
Joined: 08 Dec 2022, 10:57

Strange ControlGet Behavior

Post by morreo » 01 Feb 2023, 11:58

Hello,

I have a program with a checkbox that I am trying to always have unchecked when I activate the hotkey. The checkbox ClassNN is WindowsForms10.BUTTON.app.0.3a48e15_r6_ad115 and the Window Title is Monkey Cancel for Stellar (5.1.1.0) - GG-TSYS.cfg. Below I will describe the strange behavior I'm experiencing.

Here is my code:

Code: Select all

F1::

WinWaitActive, Monkey Cancel for Stellar (5.1.1.0) - GG-TSYS.cfg
ControlGet, check1, Checked,,WindowsForms10.BUTTON.app.0.3a48e15_r6_ad115, Monkey Cancel for Stellar (5.1.1.0) - GG-TSYS.cfg
If check1 = 1
{
	ControlClick, WindowsForms10.BUTTON.app.0.3a48e15_r6_ad115, Monkey Cancel for Stellar (5.1.1.0) - GG-TSYS.cfg
    	; Checkbox is checked
	MsgBox, checked
}
Else
{
    ; Checkbox is not checked
	MsgBox, Unchecked
}
This is what the checkbox looks like
image.png
image.png (576 Bytes) Viewed 597 times
image.png
image.png (390 Bytes) Viewed 597 times
When I first activate the script, pressing the hotkey (F1) will do absolutely nothing regardless if the checkbox is checked or not. However, when I check the box (Or unchecked the box), I get the MsgBox, Unchecked.
After this initial Check/Uncheck, then pressing the hotkey (F1) will always give the MsgBox, Unchecked regardless if the box is checked or unchecked.

I read the ControlGet documentation and I'm just not sure what I am doing wrong.

gmoises
Posts: 74
Joined: 18 Nov 2017, 16:43

Re: Strange ControlGet Behavior

Post by gmoises » 01 Feb 2023, 13:34

This could be the problem

When you press F1 your code executes WinWaitActive, if the window is not activated, the code keeps waiting.
if you expect the code to run even if the Window is not active, skip the WinWaitActive line

When you click the checkbox, this activates the window and the code can proceed.

morreo
Posts: 27
Joined: 08 Dec 2022, 10:57

Re: Strange ControlGet Behavior

Post by morreo » 01 Feb 2023, 14:06

You're right. That was A problem. I fixed it to say WinActivate.

However, it still does not acknowledge that it is checked. It always says it's unchecked

Here's the new code

Code: Select all

F1::

WinActivate, Monkey Cancel for Stellar (5.1.1.0) - GG-TSYS.cfg
ControlGet, check1, Checked,,WindowsForms10.BUTTON.app.0.3a48e15_r6_ad115, Monkey Cancel for Stellar (5.1.1.0) - GG-TSYS.cfg
If check1 = 1
{
	ControlClick, WindowsForms10.BUTTON.app.0.3a48e15_r6_ad115, Monkey Cancel for Stellar (5.1.1.0) - GG-TSYS.cfg
    ; Checkbox is checked
	MsgBox, checked
}
Else
{
    ; Checkbox is not checked
	MsgBox, Unchecked
}

morreo
Posts: 27
Joined: 08 Dec 2022, 10:57

Re: Strange ControlGet Behavior

Post by morreo » 01 Feb 2023, 16:56

I did more experiments to try to figure this out

Code: Select all

WinActivate, Monkey Cancel for Stellar (5.1.1.0) - GG-TSYS.cfg
WinWaitActive, Monkey Cancel for Stellar (5.1.1.0) - GG-TSYS.cfg
ControlGet, check1, Checked,,WindowsForms10.BUTTON.app.0.3a48e15_r6_ad115, Monkey Cancel for Stellar (5.1.1.0) - GG-TSYS.cfg ;0 whether it's checked or unchecked
This code definitely returns a 0 for the check1 variable when the checkbox is checked. Is it possible ControlGet just doesn't work for this particular program? (All other hotkey functions work fine). Maybe there is some kind of work around to always have the checkbox turn off when the hotkey is pressed?
Last edited by morreo on 02 Feb 2023, 16:39, edited 1 time in total.

morreo
Posts: 27
Joined: 08 Dec 2022, 10:57

Re: Strange ControlGet Behavior

Post by morreo » 02 Feb 2023, 16:22

After a lot of digging, I find that this problem might go a lot deeper than just writing wrong code

viewtopic.php?t=4118
and
viewtopic.php?f=76&t=75009&p=324276&hilit=CheckBox+Status+of+a+WindowsForms10+Control#p324276

I don't mean to jump the gun especially as i'm a complete novice when it comes to AutoHotKey or coding in general, but there might be some serious issues in AutoHotKey ControlGet,,Checked subcommand with .NET programs. This issue seems to be happening to a lot of people. Although these threads are very old, I'm worried that the issue still exists as I don't see a solution in any of the threads I read.

morreo
Posts: 27
Joined: 08 Dec 2022, 10:57

Re: Strange ControlGet Behavior  Topic is solved

Post by morreo » 03 Feb 2023, 13:53

I have had a lot of confirmations that AutoHotKey does not like using ControlGet ONLY using the Checked subcommand (There might be others, but that's the only one I know for sure) when dealing with .NET.

I used the following workaround and it seems to work:

Code: Select all

F1::

WinActivate, Monkey Cancel for Stellar (5.1.1.0) - GG-TSYS.cfg
WinWaitActive, Monkey Cancel for Stellar (5.1.1.0) - GG-TSYS.cfg

ControlGetPos, ControlX, ControlY, ControlWidth, ControlHeight, WindowsForms10.BUTTON.app.0.3a48e15_r6_ad115, Monkey Cancel for Stellar (5.1.1.0) - GG-TSYS.cfg

PixelSearch, FoundX, FoundY, ControlX, ControlY, ControlX + ControlWidth, ControlY + ControlHeight, 0x202020, 0, Fast RGB
If (FoundX > 0) and (FoundY > 0)
{
ControlClick, WindowsForms10.BUTTON.app.0.3a48e15_r6_ad115, Monkey Cancel for Stellar (5.1.1.0) - GG-TSYS.cfg
}

Post Reply

Return to “Ask for Help (v1)”