Skip to content

Instantly share code, notes, and snippets.

@Virenbar
Created October 26, 2016 11:32
Show Gist options
  • Save Virenbar/b03e818e2ebc58a85e42940dbc7e33f1 to your computer and use it in GitHub Desktop.
Save Virenbar/b03e818e2ebc58a85e42940dbc7e33f1 to your computer and use it in GitHub Desktop.
Delphi Mouse
uses
...
, Windows
, ...
;
type
TMouseBtnType = (mbLeft, mbMiddle, mbRight);
const
MOUSE_BTN_VKEYS: Array [TMouseBtnType] of Integer = (VK_LBUTTON, VK_MBUTTON, VK_RBUTTON);
(* This function returns true when the specified mouse button is pressed *)
function IsMouseBtnDown(const AMouseBtn: TMouseBtnType): Boolean;
begin
Result := GetAsyncKeyState(MOUSE_BTN_VKEYS[AMouseBtn])
AND $8000 <> 0;
end;
(* This function returns true when any of the mouse button is pressed *)
function IsMouseBtnDown: Boolean;
begin
Result := (GetAsyncKeyState(VK_LBUTTON)
OR GetAsyncKeyState(VK_MBUTTON)
OR GetAsyncKeyState(VK_RBUTTON)
)
AND $8000 <> 0;
end;
uses
...
, Windows
...
;
(* This function returns true if the mouse buttons are swapped *)
function IsMouseBtnSwapped: Boolean;
begin
Result := GetSystemMetrics(SM_SWAPBUTTON) <> 0;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment