Solved

Send Enter Key to s Dos program running under Windows 98

Posted on 1998-08-03
7
207 Views
Last Modified: 2010-04-04
Previously, I have a Dos program running under Windows. I am writing a Delphi program now to run the program using the Winexec command. Some point in time, when I am in the main window of the Delphi program I wrote, I need to switch windows over to the Dos program. I need to send a ENTER key to the Dos program. I have tried using the sendmessage command as follows but it didn't worked. Don't know why.
I am trying to do a SendKey function like in Visual Basic

SetForeGroundWindow(HdSimulate);
Sendmessage(HdSimulate, WM_Char, $0d, 0);
  where hdsimulate is the handle to the dos windows.

Can someone please help ?
0
Comment
Question by:SellandBuy
  • 2
  • 2
  • 2
  • +1
7 Comments
 

Author Comment

by:SellandBuy
Comment Utility
Edited text of question
0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
I fear, simulating the key from your Delphi application won't work (but I'm not completely sure), because the dos keyboard input buffer is somehow not compatible.
But I'm sure the simulation would work, if you would write a keyboard vxd.  :-(
0
 
LVL 3

Expert Comment

by:Matvey
Comment Utility
WM_Char is supose to send a charecter key ('A', 't'...). Try WM_KEYDOWN.

SendMessage(<handle>, WM_KEYDOWN, VK_ENTER, 0);
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 8

Accepted Solution

by:
ZifNab earned 100 total points
Comment Utility
Hi SellandBuy,

Try it this way :

Procedure PostText( hw: HWND; Const S: String );
Var
  i: Integer;
Begin
  For i:= 1 To Length(S) Do
  begin
    SetForegroundWindow( hw );
    keybd_event(Ord(UpCase(S[i])), Mapvirtualkey(Ord(UpCase(S[i])), 0), 0, 0 );
    sleep(100);
  end;
End;

Regards, Zif.

(PS. Reject answer if Matvey's solution works and give then points to Matvey)
0
 

Author Comment

by:SellandBuy
Comment Utility
What is it that sendmessage command does not work ?
0
 
LVL 3

Expert Comment

by:Matvey
Comment Utility
Yo guys. I see the SendMessage doesn't work. Hard to tell why - propably the messages aren't posted to the dos window. Instead of this it's a good idea to simulate key presses. Cool thing Zif - didn't know about this stuff.
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
Hi,

don't know exactly why sendmessage doesn't work :-(. Sorry about this.

Think I made a little mistake, this is better :

Procedure PostText( hw: HWND; Const S: String );
    Var
      i: Integer;
    Begin

      SetForegroundWindow( hw ); <- isn't really nessecarry, only needed if you don't know if window keeps active.

      For i:= 1 To Length(S) Do
      begin
        keybd_event(Ord(UpCase(S[i])), Mapvirtualkey(Ord(UpCase(S[i])), 0), 0, 0 );
        sleep(100);
      end;
    End;

And this should be a better way, although I find it much the same :

Procedure PostVKey( vkey: Byte );
Begin
 keybd_event( vkey, MapVirtualkey(vkey, 0), 0, 0 );
 keybd_event( vkey, MapVirtualkey(vkey, 0), KEYEVENTF_KEYUP, 0 );
End;

Procedure PostText( hw: HWND; Const S: String );
Var
   i: Integer;
 Begin
  For i:= 1 To Length(S) Do PostVkey( Ord(UpCase(S[i]))) ;
 End;

Zif.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now