Jump to content

Issue with ControlSend


Recommended Posts

I'm writing a program to automate a set of keystrokes in a specific window and repeat the process a given number of times. The problem I'm experiencing is that the keystrokes are also sent to my AutoIT GUI even though I'm using ControlSend. This is only a problem with the GUI, I can select another window without the keystrokes being sent to it.

I've tested sending the keystrokes to other applications to make sure the program receiving the keystrokes isn't the problem.

Secondary problem.. When starting my program I have to select the "receiving" window for the keystrokes to start being sent.

Here's the code, maybe you can pick something up that I've missed.

#include <GUIConstants.au3>
#include <EditConstants.au3>

GUICreate ( "Auto-m-addict" , 560 , 230 )
GuiCtrlCreateLabel("Total session count :", 410, 15)  
$totalsession = GuiCtrlCreateInput("0", 460, 35, 40, 20)
GuiCtrlCreateLabel("Status :", 450, 75)            
$statusedit = GuiCtrlCreateInput("Ready", 440, 95, 80, 20)
GuiCtrlCreateLabel("Cycles :", 450, 135)              
$updninput = GuiCtrlCreateInput("60", 440, 155, 80, 20)
$masterupdn = GuiCtrlCreateUpDown($updninput, $UDS_ARROWKEYS)
GuiCtrlCreateTab(5, 35, 360, 180, $TCS_MULTILINE)    
GuiCtrlCreateTabItem("Blah")                          
$Start=GUICtrlCreateButton ("START", 20,160,70,40) 
$Stop=GUICtrlCreateButton ("STOP", 100,160,70,40) 
GuiCtrlCreateLabel("AHHHHHHHHHHHH", 0, 90, 360, 40, $SS_CENTER)
GUISetState(@SW_SHOW , )

HotKeySet("{ESC}", "terminate")
Global $cycle

While 1
    $msg = GUIGetMsg()
    Select
        Case    $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case    $msg = $Start
            sleep(2000)
            Start()
    EndSelect
WEnd

;counters and keystrokes
Func Start()
    $cycle = GUICtrlRead($updninput)
    $total = GUICtrlRead($totalsession)
    While $cycle > 0
        $cycle = $cycle - 1
        $total = $total + 1
    ;updown manipulation
        GUICtrlSetData($statusedit, "Working")
        GUICtrlSetData($updninput, $cycle)
    ;session total manipulation
        GUICtrlSetData($totalsession, $total)
        
    ;keystroke
        ControlSend ("Untitled - Notepad" , "" , "" , "{UP}")
        stall()
    WEnd
EndFunc

;stalls between loops and checks for user input
Func stall()
    $count = 0
    while $count <= 30
        $msg = GUIGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $Stop
            $cycle = 0
            GUICtrlSetData($statusedit, "Stopped")
        EndSelect
        $count = $count + 1
        sleep(50)
    WEnd
EndFunc

Func terminate()
    $quitforme = MsgBox(1, "EXIT", "Quit Program?")
    while   $quitforme = 1
        Exit 0
    wend
EndFunc

Thanks in advance.

Link to comment
Share on other sites

  • Moderators

Use the control id or the classnameNN of the window you want to send too... Your code has obviously been altered to protect the "innocent", so my second guess is that you named your real GUI the same name as the other window or close to it.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Use the control id or the classnameNN of the window you want to send too... Your code has obviously been altered to protect the "innocent", so my second guess is that you named your real GUI the same name as the other window or close to it.

Actually I even went so far in my troubleshooting to try using AutoItSetOption("WinTitleMatchMode", 3) to match the title exactly (char and case). But that didn't have an effect. I wish it was something simple like two similar titles, but if you run the code I provided using "Auto-m-addict" as the GUI title and notepad as the receiving app you get the same issue I'm facing.

I can't get a control ID from the target application but I did try using the classname. I may have misused it though.

I have also tried using ControlFocus() with the title and classname.

ControlSend ("[CLASS:Notepad]" , "", "", "{UP}")
Edited by MistakenCreation
Link to comment
Share on other sites

ControlSend ("[CLASS:Notepad]" , "", "", "{UP}")
Your not sending the text to a control the Notepad edit control is Edit1..

ControlFocus("Untitled - Notepad","","Edit1")
ControlSend ("Untitled - Notepad" , "", "Edit1", "Text I want to send")
Link to comment
Share on other sites

Your not sending the text to a control the Notepad edit control is Edit1..

ControlFocus("Untitled - Notepad","","Edit1")
ControlSend ("Untitled - Notepad" , "", "Edit1", "Text I want to send")

Ah my mistake. I was under the impression that any one of the first three args(Title, text, control) would work. Hmm... That's a problem though. I was trying to use ControlSend so that the application didn't need to be the active window. But I can't pull any control information from the window.

>>>> Window <<<<

Title: TheApp

Class: TheApp.App

Position: 8, 21

Size: 1030, 798

Style: 0x14CA0000

ExStyle: 0x00040100

>>>> Control <<<<

Class:

Instance:

ID:

Text:

Position:

Size:

ControlClick Coords:

Style:

ExStyle:

Is there any way to set up a dummy control with certain coordinates inside the target window? Or maybe there's a better way that you know of.

Edited by MistakenCreation
Link to comment
Share on other sites

  • Moderators

Ah my mistake. I was under the impression that any one of the first three args(Title, text, control) would work. Hmm... That's a problem though. I was trying to use ControlSend so that the application didn't need to be the active window. But I can't pull any control information from the window.

Is there any way to set up a dummy control with certain coordinates inside the target window? Or maybe there's a better way that you know of.

What's the applications name, and what/where exactly are you trying to interact with it at? You could probably have you answer in a few moments rather than dancing around everything.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
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
 Share

  • Recently Browsing   0 members

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