Detecting an unsuccesful click

Get help with using AutoHotkey and its commands and hotkeys
israelss
Posts: 4
Joined: 15 Mar 2019, 04:05

Detecting an unsuccesful click

15 Mar 2019, 04:16

Hi,

I need some help with detecting an unsuccessful click.

Basically it is a very simple code where TAB is used to get to the click box.
It is a repetitive action where the code is used in a loop with the aim to click tick boxes.

The following code is used:

Code: Select all

Send {Tab}
Sleep 50
Send {Tab}
Sleep 50
Send {Tab}
Sleep 50
Send {Tab}
Sleep 50
Send {space}
When doing the last “Send {space}” command, the tick box is not clicked (because it is not allowed according to the program I am using and that is an intentional feature, i.e. it shouldn’t be possible).

So, do you know of a way to detect that the tick box was actually not ticked at all?
The reason is that I want to count the number of unclicked tick boxes there are in the loop.

Br
Magnus

Moderator Note: Added code tags. ~ sinkfaze
SOTE
Posts: 599
Joined: 15 Jun 2015, 06:21

Re: Detecting an unsuccesful click

15 Mar 2019, 09:53

Why are you not using ControlSend?
ControlSend [, Control, Keys, WinTitle, WinText, ExcludeTitle, ExcludeText]
https://autohotkey.com/docs/commands/ControlSend.htm

Part of your problem can be that you are sending keys to the wrong window or the timing of when the keys are sent is wrong. To eliminate that possibility, you might want to specify the window you are sending keys to.

However, it's not always possible to use ControlSend, due to the window or control being non-standard. To find this out, use the tool WindowSpy.ahk, which is located in the directory of where you installed AutoHotkey. Usually, C:\Program Files\AutoHotkey, but depends on where you put it. WindowSpy.ahk will tell you the title of the window and the control your mouse is on (if a standard Window).

If ControlSend doesn't work, due to a non-standard GUI, you can try code such as:

Code: Select all

If WinExist("ahk_exe your.exe")  ; can be the window used by your executable or put in the name of the window
{
	WinActivate, ahk_exe your.exe  ; can be the window used by your executable or put in the name of the window
	If  WinActive("ahk_exe your.exe") ; can be the window used by your executable or put in the name of the window
	{
	BlockInput On  ; can use this to stop other input from interfering
	Send whatever keys
	Send whatever keys
	Send whatever keys
	BlockInput Off  ; don't forget to turn off
	}
}
Albireo
Posts: 655
Joined: 16 Oct 2013, 13:53

Re: Detecting an unsuccesful click

15 Mar 2019, 11:45

Start with the analysis from SOTE.

When I want to do the same (eg jump with TAB), TAB is sent as fast as possible, preferably with ControlSend to be sure that TAB is sent to the right window. To know if the cursor has reached the correct field, an analysis is made if the window have changes (eg a field turns blue or button changes color or...). I have a function that controls this. If it does not happen, I get a message.
What can be difficult (I think) is to find exactly the right coordinates, if a color is to be checked. (but that's another question)
User avatar
Tigerlily
Posts: 281
Joined: 04 Oct 2018, 22:31

Re: Detecting an unsuccesful click

15 Mar 2019, 21:36

israelss wrote:
15 Mar 2019, 04:16
Hi,

I need some help with detecting an unsuccessful click.

Basically it is a very simple code where TAB is used to get to the click box.
It is a repetitive action where the code is used in a loop with the aim to click tick boxes.

The following code is used:

Code: Select all

Send {Tab}
Sleep 50
Send {Tab}
Sleep 50
Send {Tab}
Sleep 50
Send {Tab}
Sleep 50
Send {space}
When doing the last “Send {space}” command, the tick box is not clicked (because it is not allowed according to the program I am using and that is an intentional feature, i.e. it shouldn’t be possible).

So, do you know of a way to detect that the tick box was actually not ticked at all?
The reason is that I want to count the number of unclicked tick boxes there are in the loop.

Br
Magnus

Moderator Note: Added code tags. ~ sinkfaze
You may want to look into automating Internet Explorer with COM to do this - sounds like you are trying to interact with a web form, correct?

If so, this will be infinitely more reliable than sending keystrokes/mouse clicks. Sending keystrokes in this repetitive way is usually not 100% consistent/reliable, if there is an alternative, I would recommend going with that. Guessing how long to wait between each keysend with Sleep commands is very cumbersome and when CPU/Memory is being heavily used, may result in failure to execute those send commands at the necessary time.

If you tell us more about the programs you are using to accomplish your task, we will likely be able to help you out better - sometimes the solution you are trying to acheive may not be the best/adequate one.
-TL
israelss
Posts: 4
Joined: 15 Mar 2019, 04:05

Re: Detecting an unsuccesful click

16 Mar 2019, 12:09

Hi,

Thanks for the input.
Some more information about the background and what I am trying to accomplish.

I have inherited the code so of course I would like to make minimal changes to it but still achieving my functionality update.
The existing code all works fine according to specifications (no problems with windows or such).
I just want to add a small feature that will make the output of the code much easier for a lot of people.

The only purpose of the program is to click some tick boxes (in an Oracle program) instead of manually searching for a few hundred items and click them......
The input to the code is an Excel sheet containing a list of "Activities".

So, the program is looking for an "Activity" item in the Excel sheet, then searching for the "Activity" in the Oracle program, finding it and then tabbing to the tick box and eventually click it.
However, some of the tick boxes are not allowed to be ticked (intentionally) and it is this event that I want to detect (to make a end report saying that "Out of your X Activities, Y has not been ticked)..


I was looking at the GuiControlGet command but I could not really get that to work.

Br
/Magnus
Albireo
Posts: 655
Joined: 16 Oct 2013, 13:53

Re: Detecting an unsuccesful click

17 Mar 2019, 05:35

israelss wrote:
16 Mar 2019, 12:09
... I was looking at the GuiControlGet command but I could not really get that to work.
Do you have the right information to GuiControlGet? (Maybe an example of how your command looks can help us?)
How did you find that information?
SOTE
Posts: 599
Joined: 15 Jun 2015, 06:21

Re: Detecting an unsuccesful click

17 Mar 2019, 07:26

israelss wrote:
16 Mar 2019, 12:09
Hi,

Thanks for the input.
Some more information about the background and what I am trying to accomplish.

I have inherited the code so of course I would like to make minimal changes to it but still achieving my functionality update.
The existing code all works fine according to specifications (no problems with windows or such).
When we are referring to windows, we are referring to where the send commands are going. Your posted script is just sending keys to nowhere in particular, so it could be sending those keys to any program.
The only purpose of the program is to click some tick boxes (in an Oracle program)
The Oracle program would usually have a name and window. This likely can be found by using WindowSpy.ahk, which was referenced in a previous post.
I just want to add a small feature that will make the output of the code much easier for a lot of people.

The only purpose of the program is to click some tick boxes (in an Oracle program) instead of manually searching for a few hundred items and click them......
The input to the code is an Excel sheet containing a list of "Activities".

So, the program is looking for an "Activity" item in the Excel sheet, then searching for the "Activity" in the Oracle program, finding it and then tabbing to the tick box and eventually click it.
However, some of the tick boxes are not allowed to be ticked (intentionally) and it is this event that I want to detect (to make a end report saying that "Out of your X Activities, Y has not been ticked)..

I was looking at the GuiControlGet command but I could not really get that to work.
You probably wanted to use ControlGet, not GuiControlGet. These are different. GuiControlGet is usually used on a AutoHotkey GUI that you made, where ControlGet is usually used on any standard Windows GUI. You should refer to the help documentation again.

ControlGet, OutputVar, SubCommand , Value, Control, WinTitle, WinText, ExcludeTitle, ExcludeText
https://autohotkey.com/docs/commands/ControlGet.htm

I don't know about the others reading this, but I'm quite confused by what you are doing. Maybe you could do a screenshot, and post a picture, if you can avoid showing any personal data or cut it out. You can post a screenshot quite easily with ImgBB (https://imgbb.com/) or Imgur (https://imgur.com/upload).

If you are using an Oracle program, then why are you talking about Excel? Why aren't you opening up the Excel program and application directly? Are you referring to a table in a database, that looks like a spreadsheet from Excel, but is not the actual application? This link gives an example of tables, records, and fields from a database. Link- https://www.cengage.com/school/corpview/RegularFeatures/DatabaseTutorial/db_elements/db_elements2.htm
israelss
Posts: 4
Joined: 15 Mar 2019, 04:05

Re: Detecting an unsuccesful click

17 Mar 2019, 12:04

Hi,

First, the code I was providing in the first post was just taken out from the full code. I just wanted to show the sequence of commands I am sending.
Yes, I understand the window concept. The program is toggling between different windows (Oracle and Excel in my case).
The toggling between the windows (Oracle and Excel) works all fine.

I took a snapshot of the Oracle window, see link: https ibb.co /gPzgkBs Broken Link for safety

What the code is intended to do is to use information in Excel as in input to the Oracle program. If looking at the link there is a unique identifier (A1210 for example). In Excel there might be 500 different unique identifiers (where A1210 is one of them).
The program goes through the unique identifiers in Excel, then toggling to the Oracle program. There I use Ctrl+F (in the code) to find the unique identifier, then tabbing to the tick box. There I try to tick the box by using the Send {space} command. This works all fine and tick boxes are ticked. But, in some cases the Oracle program blocks you from ticking the box (intentionally).

It is this "blocking" that I would like to detect (if the tick box was actually ticked or not).
What I would like to achieve at the end is a message saying something like "Out of the 500 unique identifiers, 496 was successfully ticked".

Hopefully this explanation and picture makes my problem a bit more understandable.

Best Regards
Magnus
AHKStudent
Posts: 448
Joined: 05 May 2018, 12:23

Re: Detecting an unsuccesful click

17 Mar 2019, 17:18

do these check boxes have a control name? can you run winspy to see?
SOTE
Posts: 599
Joined: 15 Jun 2015, 06:21

Re: Detecting an unsuccesful click

17 Mar 2019, 17:20

israelss wrote:
17 Mar 2019, 12:04
Hi,

First, the code I was providing in the first post was just taken out from the full code. I just wanted to show the sequence of commands I am sending.
Yes, I understand the window concept. The program is toggling between different windows (Oracle and Excel in my case).
The toggling between the windows (Oracle and Excel) works all fine.

I took a snapshot of the Oracle window, see link: https ibb.co /gPzgkBs Broken Link for safety

What the code is intended to do is to use information in Excel as in input to the Oracle program. If looking at the link there is a unique identifier (A1210 for example). In Excel there might be 500 different unique identifiers (where A1210 is one of them).
The program goes through the unique identifiers in Excel, then toggling to the Oracle program. There I use Ctrl+F (in the code) to find the unique identifier, then tabbing to the tick box. There I try to tick the box by using the Send {space} command. This works all fine and tick boxes are ticked. But, in some cases the Oracle program blocks you from ticking the box (intentionally).

It is this "blocking" that I would like to detect (if the tick box was actually ticked or not).
What I would like to achieve at the end is a message saying something like "Out of the 500 unique identifiers, 496 was successfully ticked".

Hopefully this explanation and picture makes my problem a bit more understandable.

Best Regards
Magnus
This has become a bit "cloak and dagger", for those that understand the meaning. I guess you have your reasons for not posting the other part of the code. No worries, maybe the solution can still be found. OK, so understand that you are definitely switching between some unknown or unnamed Oracle program and Excel.

It looks like you could use ControlClick on the checkbox.
ControlClick , Control-or-Pos, WinTitle, WinText, WhichButton, ClickCount, Options, ExcludeTitle, ExcludeText
https://autohotkey.com/docs/commands/ControlClick.htm

Where your code says Send {space}, is where you could possibly use ControlClick. What you are referring to as a "tick box", is usually called a checkbox in most programming languages. To confirm that, you should use WindowSpy.ahk as suggested, which can give you the window and control name. In WindowSpy.ahk, the name of the control for the checkbox (tick box), might say button. The key point is that you are getting some kind of name for it and that it's not blank or nothing.

Also the Send {Tab} might not be needed. As the ControlClick might can work directly on the window of the Oracle program and the checkbox. But you should confirm if you can get the information about it from WindowSpy.ahk or not. This is also important, because if you can get control information of the Oracle program checkbox, you can usually determine if was successful or unsuccessful checked.

Often when a checkbox is clicked, some indicator change happens. A color change, button position changes, name change, pop-up message, etc... You can also possibly get this information by using ControlGet. ControlGet, OutputVar, SubCommand , Value, Control, WinTitle, WinText, ExcludeTitle, ExcludeText
Read about the part for a checkbox- https://autohotkey.com/docs/commands/ControlGet.htm#Checked

The other part of this, is understanding how the unique identifier is being recognized and then is triggering the switch from the Excel spreadsheet to the Oracle program. Are these unique identifiers: 1) visually identified by the user as unique identifiers 2) the code scans the Excel spreadsheet for unique identifiers?

I mention that, because it might be better to clarify what triggers the program to switch from Excel to the Oracle program. A problem can be occurring in how you are switching back and forth. This is the other part of the code that you haven't shown. It's not so clear if the programs is automatically scanning the Excel spreadsheet for unique identifiers that you have coming from some other source or if you are visually identifying this. Like say that I have a text file with an unique identifiers list that the program is using to match between the Excel spreadsheet and the Oracle program.

Also, if these unique identifiers are always the same, you might not even need the Excel spreadsheet. You could possibly put this list inside of a variable, within your AHK script or executable. However, if these unique identifiers do change, no worries. An AHK script can definitely scan the column or row of an Excel spreadsheet or .csv file to get them. Each cell of the column containing the unique identifer can be read, and then the matching identifier can be found in the Oracle program, triggering having the checkbox clicked. Thus you might not need to do Ctrl+F either. The AHK program could check each cell containing the unique identifier in Excel, then see if it can find it in the Oracle program. Though to switch back and forth between the Excel spreadsheet and Oracle program, it's best to know the names of the windows. Thus that first part of confirming that you can get that with WindowSpy.ahk. You don't have to tell us the name of the Oracle program window, just confirm if it can be identified.
israelss
Posts: 4
Joined: 15 Mar 2019, 04:05

Re: Detecting an unsuccesful click

19 Mar 2019, 05:43

Hi,

Thanks again for your input.

I have been playing around a bit with the ControlGet command now.

What I have been using so far is the following:
ControlGet, testvalue, Checked,, Button1, Preview changes to project,,,

Button 1 is the "name" of checkbox according to WindowsSpy.
Preview changes to project is the name of the active window where the checbox is located.

I use this command directly after the Send {space} command. So, the code looks like this:
Send {space}
ControlGet, testvalue, Checked,, Button1, Preview changes to project,,,

If I get this command correct the OutputVar (testvalue in my case above) should be set to either 1 or 0 depending on if the checkbox is checked or not.

Before executing the ControlGet command I set testvalue := (100). This in order to verify that after the ControlGet command is executed I can see a change in value.
When verifying the testvalue after the command I can see that it is blank (or no number or whatever is the appropriate term)
It is the same result, no matter if the checkbox is checked or not.
What I make out of this is that the ControlGet command is actually executed (since testvalue is changed from before the command).
Have I made any mistakes in the syntax or is it some declarations missing somehow?

Regarding the Excel unique identifiers. The Excel sheet ONLY contains unique identifiers. Could be compared to a set of changes in your SW compared to your latest baseline (i.e. all the updates).
These identifiers (A1210 for example) are listed in the Excel sheet from cell A1 to Axxx. They are highligthed in the Excel sheet manually and then used as a clipboard (by the code). The clipboard input is then used as a loop for finding the unique identifier in the Oracle program (which is Primavera P6). When the identifier is found in Primavera P6 it should be checked in a checkbox (see picture from previous post). BUT, sometimes Primavera P6 is refusing you to check the checkbox due to various reasons (intentional functionality in order not to screw up too much....). These are the cases I want to capture with the ControlGet command.

So, the program runs just fine as it is, there is no bug or such. I just want to add this extra feature of detecting when the checkbox is not checked.

Br
/Magnus
Albireo
Posts: 655
Joined: 16 Oct 2013, 13:53

Re: Detecting an unsuccesful click

19 Mar 2019, 11:45

israelss wrote:
19 Mar 2019, 05:43
.... So, the program runs just fine as it is, there is no bug or such. I just want to add this extra feature of detecting when the checkbox is not checked.
I would check the color of one or some pixels in the checkbox (depending on the color on the background and the check mark)
SOTE
Posts: 599
Joined: 15 Jun 2015, 06:21

Re: Detecting an unsuccesful click

20 Mar 2019, 07:42

israelss wrote:
19 Mar 2019, 05:43
What I have been using so far is the following:
ControlGet, testvalue, Checked,, Button1, Preview changes to project,,,

Button 1 is the "name" of checkbox according to WindowsSpy.
Preview changes to project is the name of the active window where the checbox is located.

I use this command directly after the Send {space} command. So, the code looks like this:
Send {space}
ControlGet, testvalue, Checked,, Button1, Preview changes to project,,,

If I get this command correct the OutputVar (testvalue in my case above) should be set to either 1 or 0 depending on if the checkbox is checked or not.

Before executing the ControlGet command I set testvalue := (100). This in order to verify that after the ControlGet command is executed I can see a change in value.
When verifying the testvalue after the command I can see that it is blank (or no number or whatever is the appropriate term)
It is the same result, no matter if the checkbox is checked or not.
What I make out of this is that the ControlGet command is actually executed (since testvalue is changed from before the command).
Have I made any mistakes in the syntax or is it some declarations missing somehow?

Regarding the Excel unique identifiers. The Excel sheet ONLY contains unique identifiers. Could be compared to a set of changes in your SW compared to your latest baseline (i.e. all the updates).
These identifiers (A1210 for example) are listed in the Excel sheet from cell A1 to Axxx. They are highligthed in the Excel sheet manually and then used as a clipboard (by the code). The clipboard input is then used as a loop for finding the unique identifier in the Oracle program (which is Primavera P6). When the identifier is found in Primavera P6 it should be checked in a checkbox (see picture from previous post). BUT, sometimes Primavera P6 is refusing you to check the checkbox due to various reasons (intentional functionality in order not to screw up too much....). These are the cases I want to capture with the ControlGet command.

So, the program runs just fine as it is, there is no bug or such. I just want to add this extra feature of detecting when the checkbox is not checked.
It looks like WindowSpy.ahk is showing info about the checkbox. It seems you tried to retrieve the data with ControlGet, but are not sure about the method. You shouldn't have to pre-assign a value to testvalue, particularly one like (100). I'm not sure about the logic of doing that.

ControlGet, testvalue, Checked,, Button1, Preview changes to project,,,

This could be the correct code, if "Preview changes to project" is the correct name of the window. Though you probably don't need the extra commas, if you have the correct window title.

What might be happening is you are checking the CheckBox only once, in addition to pre-assigning a value to testvalue might cause trouble. You will need your script to constantly check if the CheckBox has or has not been ticked, which means using a Loop or SetTimer. Loop will check constantly, while SetTimer can check at small time intervals.

I created a test program to show how to see the result of the output variable when using ControlGet. You can play with this, to be clear on using it After playing with it, you can modify this script. Instead of using the Test GUI, you can have it work for the Oracle GUI. Have the ToolTips show you if the Oracle Window CheckBox is or is not checked. From there, instead of using ToolTips, you can have the results written to a file. The easiest way would be to use FileAppend (https://autohotkey.com/docs/commands/FileAppend.htm). Note- Where FileAppend says "text", you can put the results from a variable there, so that is written to a file. But, before moving to that step, see if you can see the results of a successful or unsuccessful check using ToolTip.

Code: Select all

#SingleInstance Force
#NoEnv
SetWorkingDir %A_ScriptDir%
SetBatchLines -1

Gui -DPIScale
Gui Add, CheckBox, x75 y50 w120 h23, CheckBox1
Gui Add, CheckBox, x75 y100 w120 h23, CheckBox2
Gui Show, w250 h150, Test

SetTimer, CheckTicked, 300
Return

CheckTicked:

ControlGet, IsTicked1, Checked,, Button1, Test
ControlGet, IsTicked2, Checked,, Button2, Test
If (IsTicked1 = 1) OR (IsTicked2 != 0)
{
	ToolTip, Checkbox 1 Was Sucessfully Ticked, 70, 55, 1
}
If (IsTicked1 = 0)
{
	Gosub, RemoveToolTip1
}
If (IsTicked2 = 1) OR (IsTicked2 != 0)
{
	ToolTip, Checkbox 2 Was Sucessfully Ticked, 70, 105, 2
}
If (IsTicked2 = 0)
{
	Gosub, RemoveToolTip2
}
Return

RemoveToolTip1:
ToolTip,,,,1
return

RemoveToolTip2:
ToolTip,,,, 2
return

GuiEscape:
GuiClose:
ExitApp

Return to “Ask For Help”

Who is online

Users browsing this forum: autodudekey, DataLife, Google [Bot], manehscripts and 44 guests