Bryan
Bryan

Reputation: 61

Delphi Emulate Keys/Mouse To a Specific window

I was wondering how to target a specific window with key strokes/mouse clicks anyone able to help?

Upvotes: 1

Views: 3549

Answers (2)

RBA
RBA

Reputation: 12584

how to search for a 'window' in the OS, if the OS is windows:

function FindWindowExtd(partialTitle: string): HWND;
var
  hWndTemp: hWnd;
  iLenText: Integer;
  cTitletemp: array [0..254] of Char;
  sTitleTemp: string;
begin
  hWndTemp := FindWindow(nil, nil);
  while hWndTemp <> 0 do begin
    iLenText := GetWindowText(hWndTemp, cTitletemp, 255);//search after the partial name
    sTitleTemp := cTitletemp;
    sTitleTemp := UpperCase(copy( sTitleTemp, 1, iLenText));
    partialTitle := UpperCase(partialTitle);
    if pos( partialTitle, sTitleTemp ) <> 0 then
      Break;
    hWndTemp := GetWindow(hWndTemp, GW_HWNDNEXT);
  end;
  result := hWndTemp;
end;

here you have how to send mouse clicks to a 'window'

http://delphi.about.com/od/vclusing/a/mouseadvanced.htm

how to send keystrokes to another application from Delphi

http://delphi.about.com/od/adptips2004/a/bltip1104_3.htm

if you want something else then modify your question

Upvotes: 3

Sertac Akyuz
Sertac Akyuz

Reputation: 54802

(Regarding your comment to your question) If the button is a standard BUTTON control, find its handle and send a BM_CLICK message to it (take note of the remarks in the documentation for when the dialog is not active).

Upvotes: 3

Related Questions