Solved

Send Enter Key to s Dos program running under Windows 98

Posted on 1998-08-03
7
212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 

Author Comment

by:SellandBuy
ID: 1359590
Edited text of question
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1359591
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
ID: 1359592
WM_Char is supose to send a charecter key ('A', 't'...). Try WM_KEYDOWN.

SendMessage(<handle>, WM_KEYDOWN, VK_ENTER, 0);
0
Technology Partners: 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!

 
LVL 8

Accepted Solution

by:
ZifNab earned 100 total points
ID: 1359593
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
ID: 1359594
What is it that sendmessage command does not work ?
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1359595
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
ID: 1359596
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

726 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