Mouse butonlarını kontrol etmek

Başlatan Zoroaster, 06 Eylül 2017, 10:48:46

Zoroaster

Formumuzun dışını göstermekte olan mouseun butonlarının basılı olup olmadıgını nasıl öğrenirim?
Seytan deliginden kacti.

ByTEK


Klein

procedure TForm5.Timer1Timer(Sender: TObject);
var x, y:integer;
begin


	x := Mouse.CursorPos.X;
	y := Mouse.CursorPos.y;

	Caption := IntToStr(x)+ ':' + IntToStr(y);

end;

Klein

:) Abi sen butonları sormuşsun, ben koordinat örneği yazmışım.
Birazdan (Delphi açılırsa) yazarım.

Klein

unit Unit5;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls;

type
  TForm5 = class(TForm)
    Timer1: TTimer;
    Button1: TButton;
    Memo1: TMemo;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    { Public declarations }
  end;

  MouseLLHookStruct = record
    pt          : TPoint;
    mouseData   : cardinal;
    flags       : cardinal;
    time        : cardinal;
    dwExtraInfo : cardinal;
  end;

 function LowLevelMouseHookProc(nCode, wParam, lParam : integer) : integer; stdcall;

var
  Form5: TForm5;
  mHook : cardinal;
implementation

{$R *.dfm}

procedure TForm5.FormCreate(Sender: TObject);
const
  WH_MOUSE_LL = 14;
begin

  mHook := SetWindowsHookEx(WH_MOUSE_LL, @LowLevelMouseHookProc, hInstance, 0);
end;

function LowLevelMouseHookProc(nCode, wParam, lParam : integer) : integer; stdcall;
// possible wParam values: WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MOUSEMOVE, WM_MOUSEWHEEL, WM_RBUTTONDOWN, WM_RBUTTONUP
var
  info : ^MouseLLHookStruct absolute lParam;
begin
  result := CallNextHookEx(mHook, nCode, wParam, lParam);
  with info^ do begin
    Form5.Label1.Caption := 'X: '+IntToStr(pt.x)+'  Y: '+ IntToStr(pt.y);
    case wParam of
      wm_lbuttondown : Form5.Memo1.Lines.Append(format('pressed left button (%d, %d)'    , [pt.x, pt.y]));
      wm_lbuttonup   : Form5.Memo1.Lines.Append(format('released left button (%d, %d)'   , [pt.x, pt.y]));
      wm_mbuttondown : Form5.Memo1.Lines.Append(format('pressed middle button (%d, %d)'  , [pt.x, pt.y]));
      wm_mbuttonup   : Form5.Memo1.Lines.Append(format('released middle button (%d, %d)' , [pt.x, pt.y]));
      wm_rbuttondown : Form5.Memo1.Lines.Append(format('pressed right button (%d, %d)'   , [pt.x, pt.y]));
      wm_rbuttonup   : Form5.Memo1.Lines.Append(format('released right button (%d, %d)'  , [pt.x, pt.y]));
      wm_mousewheel  : begin
        if smallInt(mouseData shr 16) > 0
        then Form5.Memo1.Lines.Append('scrolled wheel (up)')
        else Form5.Memo1.Lines.Append('scrolled wheel (down)');
      end;
    end;
  end;
end;
end.


Orijinal örnek:
http://lazplanet.blogspot.com.tr/2016/06/how-to-detect-mouse-events-outside-your.html