Jump to content
Sign in to follow this  
myspacee

Send text to a window without focus

Recommended Posts

myspacee

hello,

try to send some text to an open window.

Find this that send text when notepad gain focus:

Local $hWnd = WinGetHandle("Untitled - Notepad")

While WinExists($hWnd)
    If WinActive($hWnd) Then ControlSetText($hWnd, "", "[CLASSNN:" & ControlGetFocus($hWnd) & "]","What you want")
    Sleep(10)
WEnd

but windows is redrawn and mantain only send text not older (also with flag = 0)

my goal :

- a script that send text to a window without focus, or

- that send text to last window with focus.

Thank you for info,

m.

Share this post


Link to post
Share on other sites
Zedna

Local $hWnd = WinGetHandle("Untitled - Notepad")

While WinExists($hWnd)
    ControlSetText($hWnd, "", "Edit1","What you want")
    Sleep(10)
WEnd

Edited by Zedna

Share this post


Link to post
Share on other sites
myspacee

thank you for reply,

but not solve my problem:

Make little step forward:

#Include <Misc.au3>
$dll = DllOpen("user32.dll")

while 1 

    $focused_window = winGetTitle("[ACTIVE]")
    $hWnd = WinGetHandle($focused_window)
    sleep(100)
    
    If _IsPressed("0D", $dll) Then;if you press [enter]
        ControlSetText($hWnd, "", "Edit1","What you want",0)
    EndIf
    
    
WEnd

This script send some text on focused window when press [enter]

problem are :

- how find focused window classname and relative controlID ?

[now send text only to notepad]

ControlSetText ( "title", "text", controlID, "new text" [, flag] )

- how avoid window to be redrawn ?

[', flag]' seems not working]

m.

Share this post


Link to post
Share on other sites
myspacee

better:

#Include <WinAPI.au3>

#Include <Misc.au3>
$dll = DllOpen("user32.dll")

Local $h_my_script = WinGetHandle(@ScriptName)

while 1 

    $focused_window = winGetTitle("[ACTIVE]")
    $hWnd = WinGetHandle($focused_window)
    sleep(100)
    
    If _IsPressed("0D", $dll) Then;if you press [enter]
        
        if $h_my_script <> $hWnd Then
            _WinAPI_SetFocus($hWnd)
            Send("Today's time/date is")
        EndIf
    EndIf
    
    _WinAPI_SetFocus($h_my_script)
    
    
WEnd

anyone can improve/correct ?

m.

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
Sign in to follow this  

×