Sign in to follow this  
Followers 0
gte

How to send commands to a window that is not the primary active window, without bringing it to the foreground?

11 posts in this topic

I saw this post, but it's not helping

http://www.autoitscript.com/forum/index.ph...l=active+window

I'm writing a keep alive script, and I want it to do this in the background, and if I'm typing, to not let the characters I'm typing interfere with the characters it sends? I can post my script, but none of you will have the software that I'm using, so I'm not sure how much help it will be.

Any ideas on how to send commands to a specific window that is not in focus, does not have a controlid and that I don't want to be in focus, or to interrupt when I'm using my mouse or keyboard for other programs?

Share this post


Link to post
Share on other sites



Run this and then just open a new notepad and try to write what you want but in first notepad will be write "TEST" by 1000 times, without any problem.

#include <String.au3>
AutoItSetOption("WinTitleMatchMode",2)
Run("notepad.exe")
WinWait("Notepad")
WinSetState("Notepad","",@SW_MINIMIZE)
ControlSend("Notepad","","Edit1",_StringRepeat("TEST",1000))

When the words fail... music speaks

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks!

EDIT

Here is what my code looks like, when I use @sw_minimize, it makes it fail

func caprskeepalive()

if ProcessExists('scguiw32.exe') then 
    Sleep (5000)
    
Else    
    $caprsusername = @UserName

AutoItSetOption("WinTitleMatchMode",2)
Run(@ComSpec & " /c " & 'scguiw32.exe -express:caprs.ad.domain.com.1111', "C:\Progra~1\Peregrine\ServiceCenter\RUN\", @SW_HIDE)
WinWait("ServiceCenter - [Login]")
WinSetState("ServiceCenter - [Login]","",@SW_MINIMIZE)
    ControlSend("ServiceCenter - [Login]","","",$caprsusername)
            Sleep(500)
    controlsend('Service Center - [Login]', '', '', "{enter}"); enter one
            sleep (1000)

Run this and then just open a new notepad and try to write what you want but in first notepad will be write "TEST" by 1000 times, without any problem.

#include <String.au3>
AutoItSetOption("WinTitleMatchMode",2)
Run("notepad.exe")
WinWait("Notepad")
WinSetState("Notepad","",@SW_MINIMIZE)
ControlSend("Notepad","","Edit1",_StringRepeat("TEST",1000))
Edited by gte

Share this post


Link to post
Share on other sites

It seems like this would work? In some form?

Am I understanding this correctly when I see that it sends characters to a window at a machine level and not at the keyboard input device level?

#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

Share this post


Link to post
Share on other sites

Can you help me with doing that, I'm looking at the help file for _SendMessage() and having a hard time making sense of it

You must use Winspector to see what messages are used when you manipulate with control.

Then you can try to send these messages to that control by _SendMessage() from AutoIt.

Share this post


Link to post
Share on other sites

Do you think I'll be able to send commands at a machine level with this, instead of emulating the keyboard at an input level? I'm guessing I can do that with user32.dll, but I have no experience with that and would have to do a lot of reading.

I really thought the post that Andreik made was going to work, but that doesn't work with my application ^_^

You must use Winspector to see what messages are used when you manipulate with control.

Then you can try to send these messages to that control by _SendMessage() from AutoIt.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Is there an indepth tutorial on the _sendmessage command and user32.dll?

I think NO.

You must understand some system underlying facts.

Sorry but if you don't have experiences don't expect you will find solution quickly.

Here is reference for SendMessage on MSDN

http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx

Edited by Zedna

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  
Followers 0