* * *

Author Topic: Mouse button for clicking Buttons  (Read 290 times)

Valdas

  • New member
  • *
  • Posts: 35
Mouse button for clicking Buttons
« on: July 16, 2017, 04:43:55 pm »
Hello,

right handed people using Left mouse button, left handed using Right mouse button. How I can determine which Mouse Button is dedicated for clicking Buttons on Form, is there any function for that?

howardpc

  • Hero Member
  • *****
  • Posts: 2242
Re: Mouse button for clicking Buttons
« Reply #1 on: July 16, 2017, 05:28:38 pm »
Create an OnMouseDown handler for the button. Then complete the code skeleton something like this:
Code: Pascal  [Select]
  1. implementation
  2.  
  3. uses typinfo, Dialogs;
  4.  
  5. procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton;
  6.   Shift: TShiftState; X, Y: Integer);
  7.  
  8.   function ButtonToStr(aButton: TMouseButton): string;
  9.   begin
  10.     Result:=GetEnumName(TypeInfo(TMouseButton), Ord(Button));
  11.     Delete(Result,1,2);
  12.   end;
  13.  
  14. begin
  15.   ShowMessageFmt('%s button was pressed',[ButtonToStr(Button)]);
  16. end;

GetMem

  • Hero Member
  • *****
  • Posts: 2209
Re: Mouse button for clicking Buttons
« Reply #2 on: July 16, 2017, 06:53:07 pm »
Under windows it's easy, you can call function GetSystemMetrics, like this:
Code: Pascal  [Select]
  1. function GetSystemMetrics(nIndex: Integer): Integer; stdcall; external 'user32.dll';
  2.  
  3. procedure TForm1.Button1Click(Sender: TObject);
  4. const
  5.   SM_SWAPBUTTON = 23;
  6. begin
  7.   if GetSystemMetrics(SM_SWAPBUTTON) = 0 then
  8.     ShowMessage('Left handed mouse')
  9.   else
  10.     ShowMessage('Right handed mouse');
  11. end;

Under linux/osx you can call xmodemap or modprobe with TProcess.
« Last Edit: July 16, 2017, 07:01:15 pm by GetMem »

Valdas

  • New member
  • *
  • Posts: 35
Re: Mouse button for clicking Buttons
« Reply #3 on: July 17, 2017, 11:03:07 am »
 Thanks for info.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus