A user customises his mouse so he can issue a double-click using the mouse wheel or a special Logitech button. He reports my software recognises only standard left-button double-clicks. Any suggestions as to what I'm failing to provide? How to fix?
software is Delphi Alexandria, VCL, Windows.
This descendant of TDrawgrid looks for double-clicks by setting OnDblClick to a custom procedure in Create:
OnDblClick := DoDoubleClick;
procedure DoDoubleClick(Sender: TObject);
procedure TWS_Grid.DoDoubleClick(Sender: TObject);
begin
if fGridState <> gsNormal then
exit;
if Assigned(On_DoubleClickCell) then
begin
On_DoubleClickCell(self, Col, Row);
just_double_clicked := true;
end;
end;
That On_DoubleClickcell works well with ordinary left button double-clicks. However, my own CheckMouseDown called by OnMouseDown does not accept any other buttons than mbLeft:
procedure TWS_Grid.CheckMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: integer);
var
ACol, AGridRow: integer;
begin
if (Button <> mbLeft) or (not(fGridState in [gsNormal, gsSelecting])) then
exit;
...
Do I need to somehow count clicks in OnMouseDown or OnMouseUp?
Thanks
In order to be checking for double click in OnMouseDown event you should be checking Shift State returned of the said event.
When double click is made (regardless of which button was used to perform double click) the shift state will include ssDouble
.
So use the combination of Button and Shift information to detect needed double click performed.
procedure TForm1.DrawGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if ssDouble in Shift then
begin
case Button of
TMouseButton.mbLeft: MessageDlg('Left button double click', mtInformation, [mbOK],0);
TMouseButton.mbRight: MessageDlg('Right button double click', mtInformation, [mbOK],0);
TMouseButton.mbMiddle: MessageDlg('Mouse wheel double click', mtInformation, [mbOK],0);
end;
end;
end;
Alternately you could also try detecting double click by handling WM_LBUTTONDBLCLK window message recieved by specific window.