mouse sol click

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
Lord_Ares
Üye
Mesajlar: 1070
Kayıt: 15 Eki 2006 04:33
Konum: Çorlu

mouse sol click

Mesaj gönderen Lord_Ares »

arkadaşlar uzun zamandır, harici ortamda mouse 'un sol tuşuna basılıp basılmadığını yakalamaya çalışıyordum. sorumun cevabını buldum sizlerle paylaşmak istedim.
Birtek mouse double click yaptığını yakalayamadım.

formunuza bir adet listbox, iki button, bir adet applicationsevents componenti koyun.

private
FHookStarted : Boolean;
implementation
var
JHook: THandle;



function JournalProc(Code, wParam: Integer; var EventStrut: TEventMsg): Integer; stdcall;
var
Char1: PChar;
s: string;
begin
{this is the JournalRecordProc}
Result := CallNextHookEx(JHook, Code, wParam, Longint(@EventStrut));
{the CallNextHookEX is not really needed for journal hook since it it not
really in a hook chain, but it's standard for a Hook}
if Code < 0 then Exit;

{you should cancel operation if you get HC_SYSMODALON}
if Code = HC_SYSMODALON then Exit;
if Code = HC_ACTION then
begin
{
The lParam parameter contains a pointer to a TEventMsg
structure containing information on
the message removed from the system message queue.
}
s := '';

if EventStrut.message = WM_LBUTTONUP then
s := 'Left Mouse UP at X pos ' +
IntToStr(EventStrut.paramL) + ' and Y pos ' + IntToStr(EventStrut.paramH);

if EventStrut.message = WM_LBUTTONDOWN then
s := 'Left Mouse Down at X pos ' +
IntToStr(EventStrut.paramL) + ' and Y pos ' + IntToStr(EventStrut.paramH);

if EventStrut.message = WM_RBUTTONDOWN then
s := 'Right Mouse Down at X pos ' +
IntToStr(EventStrut.paramL) + ' and Y pos ' + IntToStr(EventStrut.paramH);

if (EventStrut.message = WM_RBUTTONUP) then
s := 'Right Mouse Up at X pos ' +
IntToStr(EventStrut.paramL) + ' and Y pos ' + IntToStr(EventStrut.paramH);

if (EventStrut.message = WM_MOUSEWHEEL) then
s := 'Mouse Wheel at X pos ' +
IntToStr(EventStrut.paramL) + ' and Y pos ' + IntToStr(EventStrut.paramH);

if (EventStrut.message = WM_MOUSEMOVE) then
s := 'Mouse Position at X:' +
IntToStr(EventStrut.paramL) + ' and Y: ' + IntToStr(EventStrut.paramH);


if s <> '' then
Form1.ListBox1.ItemIndex := Form1.ListBox1.Items.Add(s);
end;
end;

procedure TForm1.BaslatClick(Sender: TObject);
begin
if FHookStarted then
begin
ShowMessage('Mouse is already being Journaled, can not restart');
Exit;
end;
JHook := SetWindowsHookEx(WH_JOURNALRECORD, @JournalProc, hInstance, 0);
{SetWindowsHookEx starts the Hook}
if JHook > 0 then
begin
FHookStarted := True;
end
else
ShowMessage('No Journal Hook availible');
end;

procedure TForm1.DurdurClick(Sender: TObject);
begin
FHookStarted := False;
UnhookWindowsHookEx(JHook);
JHook := 0;
end;

procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin

Handled := False;
if (Msg.message = WM_CANCELJOURNAL) and FHookStarted then
JHook := SetWindowsHookEx(WH_JOURNALRECORD, @JournalProc, 0, 0);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
{make sure you unhook it if the app closes}
if FHookStarted then
UnhookWindowsHookEx(JHook);
end;


sanırım double click olayını yakalamak için şunu denedim ama olmadı fikri olan varsa paylaşırsa sevinirim.function içine şu kodu ekledim.

if EventStrut.message = WM_LBUTTONDBLCLK then
s := 'Mouse Double click at X pos ' +
IntToStr(EventStrut.paramL) + ' and Y pos ' + IntToStr(EventStrut.paramH);
Cevapla