Solved

Send Enter Key to s Dos program running under Windows 98

Posted on 1998-08-03
7
210 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
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Newbie Thread Programming 1 161
Comparing dates in Delphi. Greater than/ Less than 3 215
Press three keys together and trigger a function 3 60
Wincontrol not (correctly) drawn 15 40
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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

840 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