Solved

Send Enter Key to s Dos program running under Windows 98

Posted on 1998-08-03
7
208 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 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

18 Experts available now in Live!

Get 1:1 Help Now