Solved

Send key sequence to ms-dos prompt

Posted on 2004-10-28
382 Views
Last Modified: 2010-04-05
Hello,

I want to send a key-sequence, "abcdef" for example, to the dos command prompt with the sendMessage function.
I can get the handle, no problem, but after i didn't know what is the WM_COMMAND to send text.
I've tried with WM_SETTEXT but that change the caption of the console...

That's all ;-)

 
0
Question by:krypto2000
    8 Comments
     
    LVL 12

    Expert Comment

    by:Ivanov_G
    WM_KEYDOWN maybe...
    0
     
    LVL 27

    Expert Comment

    by:kretzschmar
    would be my guess too

    WM_KEYDOWN and WM_KEYUP combination
    0
     
    LVL 17

    Expert Comment

    by:geobul
    SendMessage(handle, WM_CHAR, $41, 0); // sends 'A' to a command prompt window (handle)
    0
     
    LVL 17

    Expert Comment

    by:geobul
    A more readable version is:
    SendMessage(h, WM_CHAR, Ord('A'), 0);
    0
     
    LVL 27

    Expert Comment

    by:kretzschmar
    good point, geo ;-)
    0
     
    LVL 17

    Accepted Solution

    by:
    And a routine:

    procedure SendToDosWindow(h: HWND; what: string);
    var
      i: integer;
    begin
      for i := 1 to Length(what) do
        SendMessage(h, WM_CHAR, Ord(what[i]), 0);
    end;

    // usage
    var
      h: HWND;
    begin
      h := FindWindow(nil, 'Command Prompt');
      if IsWindow(h) then begin
        SendToDosWindow(h, 'abcdef');
      end else ShowMessage('Window not found');
    end;

    Regards, Geo
    0
     
    LVL 17

    Expert Comment

    by:geobul
    Thanks meikl. Lots of attempts for automating third-party softwares administration/supervision tasks recently seem to have an effect ;-)
    0
     

    Author Comment

    by:krypto2000
    that's not realy hard but i have time not so much ;-)
    thank you very much, the points is for you geobul !!
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Prepare to Pass the CompTIA A+ 900 Series Exam

    CompTIA aims to adapt its A+ Certification to reflect the most current knowledge and skills needed by today's IT professionals--and this year's 2016 exam is harder than ever. This certification is one of the most highly-respected and sought after in IT.

    Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
    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…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    856 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

    16 Experts available now in Live!

    Get 1:1 Help Now