Вопрос
От слов к делу…
var
HookHandle: hHook;
function HookProc(Code: integer; WParam: word; LParam: Longint): Longint;
stdcall;
var
msg: PEVENTMSG;
begin
if Code >= 0 then begin
result := 0;
msg := Pointer(LParam);
with Form1 do
case msg.message of
WM_MOUSEMOVE: Caption := IntToStr(msg.ParamL) + #32 + IntToStr(msg.ParamH);
WM_LBUTTONDOWN: CheckBox1.Checked := true;
WM_LBUTTONUP: CheckBox1.Checked := false;
WM_RBUTTONDOWN: CheckBox2.Checked := true;
WM_RBUTTONUP: CheckBox2.Checked := false;
WM_KEYUP: CheckBox3.Checked := false;
WM_KEYDOWN: CheckBox3.Checked := true;
end; end else
result := CallNextHookEx(HookHandle, code, WParam, LParam);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.FormStyle := fsStayOnTop;
CheckBox1.Enabled := false;
CheckBox1.Caption := 'left button';
CheckBox2.Enabled := false;
CheckBox2.Caption := 'right button';
CheckBox3.Enabled := false;
CheckBox3.Caption := 'keyboard';
HookHandle := SetWindowsHookEx(WH_JOURNALRECORD, @HookProc, HInstance, 0);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
if HookHandle <> 0 then
UnhookWindowsHookEx(HookHandle);
end;
При нажатии на клавишу win все перестает работать. В чем проблема?
Ответ
if Code >= 0 then begin result := 0; msg := Pointer(LParam); with Form1 do case msg.message of WM_MOUSEMOVE: Caption := IntToStr(msg.ParamL) + #32 + IntToStr(msg.ParamH); WM_LBUTTONDOWN: CheckBox1.Checked := true; WM_LBUTTONUP: CheckBox1.Checked := false; WM_RBUTTONDOWN: CheckBox2.Checked := true; WM_RBUTTONUP: CheckBox2.Checked := false; WM_KEYUP: CheckBox3.Checked := false; WM_KEYDOWN: CheckBox3.Checked := true; //Вот это дописать попробуйте — else result := CallNextHookEx(HookHandle, code, WParam, LParam); //До сюда — end; end else result := CallNextHookEx(HookHandle, code, WParam, LParam);
A.Z.
Copyright 2000-2004 Сообщество Чайников
Контактная информация