Docfxit

[RESOLVED] I'm having trouble with ControlSend

11 posts in this topic

#1 ·  Posted (edited)

#RequireAdmin
Local $UserCode1

~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/
; I have a variable called $UserCode1
~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/
$UserCode1 = ClipGet()
MsgBox($MB_SYSTEMMODAL, "", "$UserCode1 = " & $UserCode1)  ;This displays the correct variable

~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/
;I have the correct handle of a window I prove with this code
~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/
While 1 
    ; To test the handle run this code
    ; Convert the handle to a string.
    Local $sHWnd = String($hWnd)
    ; Minimize the Notepad window and wait for 2 seconds.
    WinSetState(HWnd($sHWnd), "", @SW_MINIMIZE)
    Sleep(2000)
    ; Restore the Notepad window and wait for 2 seconds.
    WinSetState(HWnd($sHWnd), "", @SW_RESTORE)
    Sleep(2000)
; It does minimize and restore the window
WEnd

~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/
; I have the correct Control ID I test with this code
~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/
While 1 
    $Test=ControlCommand ( $hWnd, "Edit1", "", "IsVisible", "" )
    If $Test=1 Then ExitLoop
    Sleep (100)
WEnd
MsgBox(0, "It is visible now", "Gotcha")
; I get the message "Gotcha"

~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/
; I'm trying to put the contents of the variable into the field AutoIt v3 Window Info shows as ClassnameNN Edit1
~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/
ControlSend($hWnd, "", "Edit1", $UserCode1)

~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/
; It's not sending the contents of $UserCode1 into the field
~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/~/

Does anyone know what I am doing wrong?

 

Thanks,

Docfxit

Edited by Docfxit

Share this post


Link to post
Share on other sites



#2 ·  Posted

Why are you converting the handle to a string, and then having to convert it back to a handle when you need to use it?

Your ControlCommand and ControlSend are different, you have the ControlID in the *Command function in the text parameter and in the ControlID parameter in the *Send function. So, your test is invalid and I'm surprised it ever exits the second loop.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#3 ·  Posted

9 hours ago, BrewManNH said:

Why are you converting the handle to a string, and then having to convert it back to a handle when you need to use it?

Your ControlCommand and ControlSend are different, you have the ControlID in the *Command function in the text parameter and in the ControlID parameter in the *Send function. So, your test is invalid and I'm surprised it ever exits the second loop.

1. This is not my production code.  It is simplified to make it easier to find the problem.

2. I am converting the handle to a string to test it to make sure it's working.  With this test I know I'm working with the correct window.  This test will not be in my code that I use when it all works.

3. Thank you for catching the ControliD on the ControlCommand.  I have changed it.

$Test=ControlCommand ( $hWnd, "", "Edit1", "IsVisible", "" )

Now that I know the handle is defiantly correct, and the ControlID is recognized as valid, I would like some help in trying to figure out why the $UserCode1 isn't being sent to Edit1.   Could it be $UserCode1 is not in the correct form?

Thanks,

Docfxit

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Sometimes I end up with more than one occurrence of a window title.

You said you were sure that you had the correct window, but I've never converted a hWin to a string so I don't understand.

You can do a:

$aWin = WinList($win_title)

ConsoleWrite("Found: " & $aWin[0][0] & " matching windows")

to see how many windows exist with the title.  There are often more than one window even when only one is visible.

Edited by Xandy

I am not a lawyer.  (-_-) Xandy About  (^o^) Discord - Xandy Programmer

Share this post


Link to post
Share on other sites

#5 ·  Posted

5 minutes ago, Xandy said:

Sometimes I end up with more than one occurrence of a window title.

You said you were sure that you had the correct window, but I've never converted a hWin to a string so I don't understand.

You can do a:

$aWin = WinList($win_title)

ConsoleWrite("Found: " & $aWin[0][0] & " matching windows")

to see how many windows exist with the title.  There are often more than one window even when only one is visible.

Thank you for the code.  The result is Found: 1 matching windows.

With the code I have, I can see the window I am targeting is minimized and then restored.  I see it's defiantly the correct window that is getting selected.

Thanks,

Docfxit

Share this post


Link to post
Share on other sites

#6 ·  Posted

I figured out I have had success with pasting the clipboard into the edit box.

I have not had success with putting $userCode1 into the clipboard.

This is the code I used:

$UserCode1 = ClipGet()        ; This doesn't work

Send("{ALTDOWN}t{ALTUP}{CTRLDOWN}v{CTRLUP}") ; This does paste into the window but not what is in $UserCode1

ControlSend($hWnd, "", "Button1", $UserCode1)    ; This does not work

How can I get the contents of $UserCode1 into the clipboard?

Thanks,

Docfxit

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I can do a right click with the mouse and past in the correct numbers.

Does anyone have any idea why AutoIt can paste from the clipboard?

Docfxit

Edited by Docfxit
Posted question

Share this post


Link to post
Share on other sites

#8 ·  Posted

I discovered using the window handle doesn't work.

I discovered using the window Text in AutoIt Window Info doesn't work.

I discovered using the class in AutoIt Window Info does work.

It's working now.

Thanks,

Docfxit

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

If nothing is working for you you can download the UIA_V0_63.zip package and run the simplespy.au3 to see if that gets information.  Hotkey to get control under mouse is: (CTRL + W).

From: UIA

You can see if there is any information listed there about your control and try the UIA system against your control.  I only made it thru example 3.  My Win7@64bits version needed a "start" pattern to be a "Start" (I think).

Edited by Xandy

I am not a lawyer.  (-_-) Xandy About  (^o^) Discord - Xandy Programmer

Share this post


Link to post
Share on other sites

#10 ·  Posted

Thanks,

Docfxit

Share this post


Link to post
Share on other sites

#11 ·  Posted

1 hour ago, Docfxit said:

I discovered using the class in AutoIt Window Info does work.

It's working now.

Thanks,

Docfxit

Opps xD


I am not a lawyer.  (-_-) Xandy About  (^o^) Discord - Xandy Programmer

Share this post


Link to post
Share on other sites

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