Detecting an unsuccesful click

Get help with using AutoHotkey and its commands and hotkeys
israelss
Posts: 3
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: 471
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: 548
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: 123
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: 3
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: 548
Joined: 16 Oct 2013, 13:53

Re: Detecting an unsuccesful click

Yesterday, 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: 471
Joined: 15 Jun 2015, 06:21

Re: Detecting an unsuccesful click

Yesterday, 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: 3
Joined: 15 Mar 2019, 04:05

Re: Detecting an unsuccesful click

Yesterday, 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: 424
Joined: 05 May 2018, 12:23

Re: Detecting an unsuccesful click

Yesterday, 17:18

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

Re: Detecting an unsuccesful click

Yesterday, 17:20

israelss wrote:
Yesterday, 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.

Return to “Ask For Help”

Who is online

Users browsing this forum: Ahk_fan, Google [Bot], paik1002, sinkfaze, teadrinker, Trisolaris and 27 guests