Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Send Enter Key to s Dos program running under Windows 98

Posted on 1998-08-03
7
Medium Priority
?
215 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 8

Accepted Solution

by:
ZifNab earned 300 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

618 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