Jump to content

ControlSend Alternative Methods


Adele
 Share

Recommended Posts

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

  • 2 weeks later...

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.

Link to comment
Share on other sites

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

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

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

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
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...