Solved

How to send commands to other apps?

Posted on 1998-06-21
1
148 Views
Last Modified: 2010-04-04
Hi, what i mean is i.e i open telnet client with winexec
how i send it parameters like login and password and host.
I want make a program that you write host, password & login. It will connect to it automaticly.
If you can help me do it for 50pts. please thanks.
0
Comment
Question by:dima_sherman
1 Comment
 
LVL 1

Accepted Solution

by:
pjdb earned 50 total points
ID: 1354824
If the apps have the keyboard focus, use the following SendKeys function. However If you use ShellExecute instead of WinExec you have the handle of the windows and then use it for the handle (hw) instead of hw:=GetFocus.

Function SendKeys(keys:String):Boolean;
Var
      hw:Hwnd;
      i:Byte;
Begin
      Result:=False;
      If Length(keys)>0 Then
            hw:=GetFocus;
            If hw<>0 Then
            Begin
                  For i:=1 to length(keys) do
                        Case keys[i] Of
                        #9:      {tab}
                              Begin
                                    KeyBD_event(vk_Tab, $45, KeyEventf_ExtendedKey Or 0, 0);
                                    KeyBD_event(vk_Tab, $45, KeyEventf_ExtendedKey Or KeyEventf_KeyUp, 0);
                        end;
                        #13:      {return}
                              Begin
                                    KeyBD_event(vk_Return, $45, KeyEventf_ExtendedKey Or 0, 0);
                                    KeyBD_event(vk_Return, $45, KeyEventf_ExtendedKey Or KeyEventf_KeyUp, 0);
                              End;
                        #27:      {escape}
                              Begin
                                    KeyBD_event(vk_Escape, $45, KeyEventf_ExtendedKey Or 0, 0);
                                    KeyBD_event(vk_Escape, $45, KeyEventf_ExtendedKey Or KeyEventf_KeyUp, 0);
                              End;
                        Else      {any other key}
                              PostMessage(hw, wm_char, word(keys[i]), 1);
                  End;
                  Result:=True;
            End;
End;      {SendKeys}
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question