Adele

ControlSend Alternative Methods

4 posts in this topic

#1 ·  Posted (edited)

Hello everyone. I'm preparing a macro program. Users will able to create themselves macros and they will able to use them on games or programs whatever they want. But I'd like to they should be able to run the macro when the window is working in background so I can't use Send() function. I can use ControlSend() function but many programs don't accept keystrokes which sent by ControlSend() because ControlSend() needs a ControlId. Do you know any alternative for ControlSend(). It should work like Send() function but in background. Thank you in advance.

Edited by Adele

Share this post


Link to post
Share on other sites



Hi @Adele.

No, ControlSend does not require a controlID. See my my example below (I just modified line 14 from the ControlSend example)

Example()

Func Example()
    ; Run Notepad
    Run("notepad.exe")

    ; Wait 10 seconds for the Notepad window to appear.
    Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)

    ; Wait for 2 seconds.
    Sleep(2000)

    ; Send a string of text to the edit control of Notepad. The handle returned by WinWait is used for the "title" parameter of ControlSend.
    ControlSend($hWnd, "", "", "This is some text")

    ; Wait for 2 seconds.
    Sleep(2000)

    ; Close the Notepad window using the handle returned by WinWait.
    WinClose($hWnd)

    ; Now a screen will pop up and ask to save the changes, the classname of the window is called
    ; "#32770" and simulating the "TAB" key to move to the second button in which the "ENTER" is simulated to not "save the file"
    WinWaitActive("[CLASS:#32770]")
    Sleep(500)
    Send("{TAB}{ENTER}")
EndFunc   ;==>Example

As you can see, the example still works fine. I believe if no ControlID is specified, the control with focus is the target.

Share this post


Link to post
Share on other sites

#3 ·  Posted

there may be a ControlID that the window info tool is not showing.  try these additional control info sniffer tools...

https://www.autoitscript.com/forum/topic/164226-get-all-windows-controls/

 

https://www.autoitscript.com/forum/topic/126716-control-viewer-autoit-window-info-tool/


if @error Then
	MsgBox(262192,"",@ComputerName&" slaps "&@UserName&" around a bit with a large trout!")
	EndIf

>Exit code: 0

REAL search results

"Yeah yeah yeah, patience. How long will that take?"  -Ed Gruberman

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

See iuiautomation udf i made. Alternatives

  1. Setfocus and copy paste
  2. Setfocus and send
  3. Keybd_event
  4. Sendinput
  5. Iuiautomaton textpattern
  6. Iaccessible patterns

In background probably only 5 and 6 but will frequently not be implemented.

Edited by junkew

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