Recent

Author Topic: distinguish between left and right mouse button in double click event?  (Read 14594 times)

marunguy

  • New Member
  • *
  • Posts: 23
Hi!

How can I distinguish between left and right mouse button in double click event?

Double click event can be processed in OnDblClick event.
But, it cannot distinguish between left and right mouse button.
Quote
procedure TFormMain.TrayIconMainDblClick(Sender: TObject);
begin
  ShowMessage('double click'); // left, right mouse button ??
end;

I try to process in OnMouseUp event with ssDouble.
ssDouble in Shift not set and I cannot process the left mouse button double click event.
OnMouseDown is same.
Quote
procedure TFormMain.TrayIconMainMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if mbRight = Button then
    ShowMessage('right click')
  else if (mbLeft = Button) and (ssDouble in Shift) then
  begin
    ShowMessage('left double click');  // no executed!!!.
  end;
end;

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4692
  • I like bugs.
Re: distinguish between left and right mouse button in double click event?
« Reply #1 on: August 09, 2013, 02:55:23 pm »
How can I distinguish between left and right mouse button in double click event?

Right double click is not a standard event anywhere AFAIK.
Double click is composed of 2 single clicks, thus you will not see it in a MouseUp event.
You must build the logic somehow yourself for this new event.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

marunguy

  • New Member
  • *
  • Posts: 23
Re: distinguish between left and right mouse button in double click event?
« Reply #2 on: August 10, 2013, 06:14:15 am »
Hi!

I understand that Double Click event is processed in OnMouseDown event.

For TTrayIcon, both left and right double click actions call the OnDblClick().
For TPanel, only left double click action call the OnDblClick() unlike TTrayIcon.

Below code with TPanel works fine for me.
Code: [Select]
procedure TFormMain.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if ssDouble in Shift then
  begin
    if ssLeft in Shift then
      ShowMessage('Panel Left Double')
    else if ssRight in Shift then
      ShowMessage('Panel Right Double');
  end;
end;

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4692
  • I like bugs.
Re: distinguish between left and right mouse button in double click event?
« Reply #3 on: August 10, 2013, 09:05:00 am »
For TTrayIcon, both left and right double click actions call the OnDblClick().
For TPanel, only left double click action call the OnDblClick() unlike TTrayIcon.

Ok, my knowledge of LCL and widgetsets is limited. What you explained sounds inconsistent. Maybe somebody more knowledgeable can comment.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: distinguish between left and right mouse button in double click event?
« Reply #4 on: August 10, 2013, 03:09:54 pm »
It seems that the TShiftState parameter is incorrectly built in Lazarus (and it's not specific to the TTrayIcon component); it's different in Delphi.

Anyway, here is a possible solution:

-use the DblClick and the MouseDown events of the TTrayIcon component
-keep the last button used in MouseDown
-process DblClick event using the last button used

Hereafter just the implementation part of the unit code for such a sample:
Code: [Select]

...
implementation

{$R *.lfm}
{ TForm1 }

var
  LastButton: TMouseButton;

procedure TForm1.TrayIcon1DblClick(Sender: TObject);
begin
  if LastButton=mbLeft then
    ShowMessage('Double Left Click')
  else
    if LastButton=mbRight then
      ShowMessage('Double Rigth Click');
end;

procedure TForm1.TrayIcon1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  LastButton:=Button;
end;

...



JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4692
  • I like bugs.
Re: distinguish between left and right mouse button in double click event?
« Reply #5 on: August 12, 2013, 11:56:00 am »
It seems that the TShiftState parameter is incorrectly built in Lazarus (and it's not specific to the TTrayIcon component); it's different in Delphi.

Could you please create a bug report with example code demonstrating the error.
If you can find a way to fix it in LCL code, still better of course.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: distinguish between left and right mouse button in double click event?
« Reply #6 on: August 13, 2013, 12:01:34 am »
Could you please create a bug report...

IMHO, it's not really a bug.

 

TinyPortal © 2005-2018