Solved

controlling other application from Delphi

Posted on 2002-03-30
6
309 Views
Last Modified: 2010-04-04
Hi guys!

Is there a way to control another application using Delphi?

 In fact, my problem is this one: I have a commercial application that has some nasty limitations. This a very special purpose database. So this application let me print any data record, but only one at a time. I want to write a program in delphi that sends to the proper menu the mouse clicks (or the hot keys associated) to that application so I can print all the records I need without having to go to each menu each time.

Any ideas?

best regards,
Manuel Lopez (lopem)
0
Comment
Question by:lopem
6 Comments
 
LVL 44

Accepted Solution

by:
CrazyOne earned 100 total points
ID: 6907934
This is simple approach to it you might need to use the Sleep function to get some timing issues sorted out.

hw := FindWindow(nil, 'The Microsoft Hearts Network');
PostMessage(hw, WM_SETFOCUS, 0, 0);
PostMessage(hw, WM_KEYDOWN, VK_RETURN, 0);
PostMessage(hw, WM_KEYUP, VK_RETURN, 0);

Sleep(1000);
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6907942
I think to send a hotkey you need to use the VK_MENU + virtual key (maybe something like this VK_MENU + VK_A)
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6908483
listening
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Expert Comment

by:quantum2
ID: 6909434
{****************************************************}
{              SendKeys Unit for Delphi 32           }
{    Copyright (c) 1999 by Borut Batagelj (Slovenia) }
{                       Aleksey Kuznetsov (Ukraine)  }
{            Home Page: www.utilmind.com             }
{            E-Mail: info@utilmind.com               }
{****************************************************}

unit SendKeys;

interface

uses
  Windows, SysUtils;

const
  SK_BKSP = #8;
  SK_TAB = #9;
  SK_ENTER = #13;
  SK_ESC = #27;
  SK_ADD = #107;
  SK_SUB = #109;
  SK_F1 = #228;
  SK_F2 = #229;
  SK_F3 = #230;
  SK_F4 = #231;
  SK_F5 = #232;
  SK_F6 = #233;
  SK_F7 = #234;
  SK_F8 = #235;
  SK_F9 = #236;
  SK_F10 = #237;
  SK_F11 = #238;
  SK_F12 = #239;
  SK_HOME = #240;
  SK_END = #241;
  SK_UP = #242;
  SK_DOWN = #243;
  SK_LEFT = #244;
  SK_RIGHT = #245;
  SK_PGUP = #246;
  SK_PGDN = #247;
  SK_INS = #248;
  SK_DEL = #249;
  SK_SHIFT_DN = #250;
  SK_SHIFT_UP = #251;
  SK_CTRL_DN = #252;
  SK_CTRL_UP = #253;
  SK_ALT_DN = #254;
  SK_ALT_UP = #255;

procedure SendKeyString(Text: String);
procedure SendKeysToTitle(WindowTitle: String; Text: String);
procedure SendKeysToHandle(WindowHandle: hWnd; Text: String);
procedure MakeWindowActive(wHandle: hWnd);
function GetHandleFromWindowTitle(TitleText: String): hWnd;

implementation

procedure SendKeyString(Text: String);
var
   i: Integer;
   Shift: Boolean;
   vk, ScanCode: Word;
   ch: Char;
   c, s: Byte;
const
   vk_keys: Array[0..9] of Byte =
      (VK_HOME, VK_END, VK_UP, VK_DOWN, VK_LEFT,
       VK_RIGHT, VK_PRIOR, VK_NEXT, VK_INSERT, VK_DELETE);
   vk_shft: Array[0..2] of Byte = (VK_SHIFT, VK_CONTROL, VK_MENU);
   flags: Array[False..True] of Integer = (KEYEVENTF_KEYUP, 0);
begin
   Shift := False;
   for i := 1 to Length(Text) do
    begin
     ch := Text[i];
     if ch >= #250 then
      begin
       s := Ord(ch) - 250;
       Shift := not Odd(s);
       c := vk_shft[s shr 1];
       ScanCode := MapVirtualKey(c,0);
       Keybd_Event(c, Scancode, Flags[shift], 0);
      end
     else
      begin
       vk := 0;
       if ch >= #240 then
        c := vk_keys[Ord(ch) - 240]
       else
        if ch >= #228 then {228 (F1) => $70 (vk_F1)}
         c := Ord(ch) - 116
        else
         if ch < #110 then
          c := Ord(ch)
         else
          begin
           vk := VkKeyScan(ch);
           c := LoByte(vk);
          end;
       ScanCode := MapVirtualKey(c,0);
       if not Shift and (Hi(vk) > 0) then { $2A = scancode of VK_SHIFT }
        Keybd_Event(VK_SHIFT, $2A, 0, 0);
       Keybd_Event(c,scancode, 0, 0);
       Keybd_Event(c,scancode, KEYEVENTF_KEYUP, 0);
       if not Shift and (Hi(vk) > 0) then
        Keybd_Event(VK_SHIFT, $2A, KEYEVENTF_KEYUP, 0);
      end;
    end;
end;

procedure MakeWindowActive(wHandle: hWnd);
begin
  if IsIconic(wHandle) then
   ShowWindow(wHandle, SW_RESTORE)
  else
   BringWindowToTop(wHandle);
end;

function GetHandleFromWindowTitle(TitleText: String): hWnd;
var
  StrBuf: Array[0..$FF] of Char;
begin
  Result := FindWindow(PChar(0), StrPCopy(StrBuf, TitleText));
end;

procedure SendKeysToTitle(WindowTitle: String; Text: String);
var
  Window: hWnd;
begin
  Window := GetHandleFromWindowTitle(WindowTitle);
  MakeWindowActive(Window);
  SendKeyString(Text);
end;

procedure SendKeysToHandle(WindowHandle: hWnd; Text: String);
begin
  MakeWindowActive(WindowHandle);
  SendKeyString(Text);
end;

end.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7014845
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still open in 7 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20103843.html
http://www.experts-exchange.com/questions/Q.20106401.html
http://www.experts-exchange.com/questions/Q.11362697.html
http://www.experts-exchange.com/questions/Q.20143988.html
http://www.experts-exchange.com/questions/Q.20171229.html
http://www.experts-exchange.com/questions/Q.20190216.html
http://www.experts-exchange.com/questions/Q.20190226.html
http://www.experts-exchange.com/questions/Q.20193039.html
http://www.experts-exchange.com/questions/Q.20195740.html
http://www.experts-exchange.com/questions/Q.20230594.html
http://www.experts-exchange.com/questions/Q.20241586.html
http://www.experts-exchange.com/questions/Q.20273100.html
http://www.experts-exchange.com/questions/Q.20281799.html
http://www.experts-exchange.com/questions/Q.20283305.html
http://www.experts-exchange.com/questions/Q.20297478.html
http://www.experts-exchange.com/questions/Q.20299749.html



*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7094046
Zero response from anyone, finalized.
Moondancer - EE Moderator
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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