Показать сообщение отдельно

  #2  
Старый 01.12.2007, 11:40
kair
Участник форума
Регистрация: 12.10.2006
Сообщений: 158
С нами: 10305026

Репутация: 187
По умолчанию

Цитата:
Сообщение от zer0c0o1  
подскажите вот хочу написать трайн под игру =) возник вопрос как посылать сообщение нажатия клавиши другому приложению

этот код который посылает данные в блокнот, а именно символы hello значением string

Цитата:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
wnd: HWND;
i: Integer;
s: string;
begin
wnd := FindWindow('notepad', nil);
if wnd <> 0 then
begin
wnd := FindWindowEx(wnd, 0, 'Edit', nil);

// Write Text in Notepad.
// Text ins Notepad schreiben.
s := 'Hello';
for i := 1 to Length(s) do
SendMessage(wnd, WM_CHAR, Word(s[i]), 0);
// Simulate Return Key.
PostMessage(wnd, WM_KEYDOWN, VK_RETURN, 0);
// Simulate Space.
PostMessage(wnd, WM_KEYDOWN, VK_SPACE, 0);
end;
end;
var
wnd: HWND;
begin

wnd := FindWindow('WordPadClass', nil);

if wnd <> 0 then
begin
wnd := FindWindowEx(wnd, 0, 'RICHEDIT', nil);
end

end.
 
Ответить с цитированием