Jump to content

Recommended Posts

Posted

Hello AutoIT community,

Long time I didn't log back here, absolutely happy to see the project is still alive and maintained. AutoIT taught me programming and gave me many joys,
I was trying to automate some setups for a machine, and Powershell was just not enough for my needs:
https://stackoverflow.com/questions/39353073/how-i-can-send-mouse-click-in-powershell
Looking here, it seems quite a clunky task to do.
So, since I automated a lot of stuff in AutoIT, I've decided to get back at it (and it feels so much better now that I'm a full stack developer since a decade).

I managed to automate all the setup and configuration except a point where I need to select a drive in the scroll down list show here:image.png.81cac9988df3bc631dda384c2c38374f.png

I tried all that I know, so I think I'm missing something.

The idea is to focus it, then move up and down with arrow (or Send() a drive letter so it gets highlighted) then follow up with TABS and ENTER and Send() to compile the rest of the form.


Sample script:

#Truecrypt window name
    Local Const $TC71WindowName = "TrueCrypt" 
    Local Const $TC71Location = "C:\Program Files\TrueCrypt\TrueCrypt.exe"
    
    #Configuring TC
    Run($TC71Location)
    Sleep(500) 
    
    If WaitAndActivateWindow($TC71WindowName) Then
        #TC installed Open and configure
        
        MsgBox(0,"Error", "Sending D")
        #Handler of drive select form
        Local $driveControlHandler = HWnd("[CLASS:Static; INSTANCE:2]")
        ControlFocus($driveControlHandler)
        Send("D")
        
        Sleep(200)
        Send("{TAB}")
        Sleep(200)
        Send("{TAB}")
        Sleep(200)
        Send($PathTc)
    Else
        Exit()
    EndIf


The thing revolves around " HWnd("[CLASS:Static; INSTANCE:2]")" where I try to get handle of the window section in the screenshot.
I also tried to get it by Window Name/Text and whatever, but it just seems that I cant navigate or interact with it.

NOTE: The scroll list CANNOT be navigated with tab, arrow or anything. I've aleady tried.

Also I would avoid doing MouseClicks because that's really resolution and window position dependent..

 

If anyone dares to try, heres the setup for Truecrypt 7.1a.
http://www.oldversion.com/windows/truecrypt-7-1

or google it from wherever you feel

BONUS:
I really would like to avoid doing all the navigation in the old fashioned way "TAB TAB TAB ENTER TAB TAB SEND("SOMEKEYS") TAB TAB ENTER SPACE.....", you got what I mean.
I would like to be able to handle buttons by their class/handle to do some bulletproof code.

What am I missing? Why I can't select buttons and windows correctly?
 

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Posted
5 hours ago, Newb said:

The thing revolves around " HWnd("[CLASS:Static; INSTANCE:2]")" where I try to get handle of the window section in the screenshot.
I also tried to get it by Window Name/Text and whatever, but it just seems that I cant navigate or interact with it.

Try replacing the use of 

HWnd(...)

with 

ControlGetHandle(...)

 

Posted
On 10/19/2022 at 4:41 PM, KaFu said:

What do you want to achieve? Mount a container? I know TC supports an extensive list of command line  arguments.

Hello!
I want to automate the setup process and container mount.
I knew about command line but making it with keystrokes was faster
I also want to learn to get control handles efficiently to ease the automation processes.
Anyway, I found a solution, I can just do it with keystrokes, it just required a bit of thinkering with how windows controls work.

I just needed to send a few {UP} and {DOWN} keystrokes

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Posted
On 10/19/2022 at 8:08 PM, OJBakker said:

Try replacing the use of 

HWnd(...)

with 

ControlGetHandle(...)

 

Ok, I will experiment with it.
 

Anyway, I found a solution, I can just do it with keystrokes, it just required a bit of thinkering with how windows controls work.

I just needed to send a few {UP} and {DOWN} keystrokes

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Posted (edited)

Update:
I tried 

ControlGetHandle

As suggested.

NOTE: To make the Window info detection work, I had to  deactivate Spy++ logic detection or else it won't detect all the properties correctly

image.png.3c3983f164307a808424a8625950cb68.png
But maybe I'm doing something wrong in clicking the control.
Here's what I do:
 

WinActivate($WindowTitle)
$a = ControlGetHandle("TrueCrypt","E&xit",1062)
if Not $a Then
    MsgBox(0,"No handle","Not found")
Else
    MsgBox(0,"Handle", String($a))
EndIf
ControlClick($a, "E&xit", 1062)

Here's with spy:
image.thumb.png.d52980b91dd9e6e885d78987d567be03.png

Trying to close the program and it will stay in the traybar (so I can't kill the process).

Handle is found:

image.png.469dfec2ee57dd947a92c7e434771d4a.png

The click just doesn't happen.
Anyone can help?

 

EDIT: 
More info:
I tried to check return value of controlclick

MsgBox(0,"ctrlcickreturn", String(ControlClick($a, "E&xit", 1062)))

and it returns 0, so basically looks like it's not working

Edited by Newb

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Posted (edited)

Add 

ControlFocus(...)

before the

ControlClick(...)

Your are using the wrong values for the parameters parameters of the control* functions. The first 2 parameters identify the window, the 3 parameter identifies the control, so you do not need the handle for the control to use the controlclick function.

Edited by OJBakker
additional info.
Posted
On 10/21/2022 at 12:04 AM, OJBakker said:

Add 

ControlFocus(...)

before the

ControlClick(...)

Your are using the wrong values for the parameters parameters of the control* functions. The first 2 parameters identify the window, the 3 parameter identifies the control, so you do not need the handle for the control to use the controlclick function.

Ok everything worked out wonderfully.
Thank you!

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...