Snippet for the lazy guys:
Code: Select all
Procedure SendKeys(handle,window$,keys$)
  If window$<>"" : handle=FindWindow_(0,window$) : EndIf ; Use window$ instead of handle.
  If IsWindow_(handle)=0 ; Does the target window actually exist?
    ProcedureReturn 0 ; Nope, so report 0 for failure to type.
  Else
    ; This block gives the target window the focus before typing.
    thread1=GetWindowThreadProcessId_(GetForegroundWindow_(),0)
    thread2=GetWindowThreadProcessId_(handle,0)
    If thread1<>thread2 : AttachThreadInput_(thread1,thread2,#True) : EndIf
    SetForegroundWindow_(handle) ; Target window now has the focus for typing. THIS FAILS!
This all works like a charme, but only if i really interact with my program.
This server is meant to be remotely controlled, so no real user, and GetForegroundWindow_() will return NULL , therefor the Sendkey-Function fails.
I've tried to SetForegroundWindow but no luck at all.
Some applications can be controled through SendMessage and #WM_CHAR, but not these i'm trying to reach, so this possibility won't help me either.
Any ideas, how to force my Application to get the Foreground back ?
Or maybe another way ?

