Forum > LCL
Is there build in way to distinguish between single mouse down and double clicks
jamie:
Is there something wrong with the "OnDlbClick" that is already there?
daniel_sap:
--- Quote from: LV on November 22, 2024, 11:52:59 am ---This trick works for me:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.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 ShowMessage('Panel Right Double'); end;end;
--- End quote ---
Very simple and clear approach, but still it triggers the Double click after one Mouse down. This will be perfect if you don't care about this one extra mouse down.
silvercoder70, Something like your solution I was thinking to implement(and may be still will go in this direction)
but when I saw your approach Warfley, I started to think that mouse ups are also important in this case.
And even another interesting situation can happen. Double click without release of the button (with hold).
Also, I read that windows by itself is starting timer for double click.
May be the timer solution is good, not to do a lot of empty iterations, combined with proper mouse up handling.
And I can implement it in some base custom control - TMyBaseCustomControl - so all inherited controls can benefit of it.
But if it is implement in LCL by default could be beneficial to all.
I saw this comment in TControl.WndProc - so I see there is that the focus is also involved in the game
It explains also why the mouse down event is sent immediately
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- LM_LBUTTONDOWN, LM_LBUTTONDBLCLK: begin Include(FControlState, csLButtonDown); { The VCL holds up the mouse down for dmAutomatic and sends it, when it decides, if it is a drag operation or not. This decision requires full control of focus and mouse, which do not all LCL interfaces provide. Therefore the mouse down event is sent immediately. Further Note: Under winapi a LM_LBUTTONDOWN ends the drag immediate. For example: If we exit here, then mouse down on TTreeView does not work any longer under gtk. } if FDragMode = dmAutomatic then BeginAutoDrag; end; LM_LBUTTONUP: begin Exclude(FControlState, csLButtonDown); end; end;
Ten_Mile_Hike:
--- Quote from: jamie on November 23, 2024, 04:01:52 pm ---Is there something wrong with the "OnDlbClick" that is already there?
--- End quote ---
--- Code: Text [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Jamie...Always asking the right questions :) :D
Ten_Mile_Hike:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);var Diff: double;begin if Button1.Tag = 0 then //First user click after Oncreate (Keep your Tag at 0 at design time) begin Button1.Tag := 1; D2 := Now + 1; end; Button1.tag := Button1.Tag * -1; case Button1.Tag of -1: D1 := now; 1: D2 := now; end; Diff := ABS(D2 - D1) * 1000000000; if Diff < 5000 then {<- You can adjust this value} begin Button1.Caption := 'Double'; D1 := Now; D2 := now; end else begin Sleep(300); {<-This is the trick to it all. Adjust the value to suit yourself but the smaller you make it the more chance "Single" will appear when DblClick is tried} Button1.Caption := 'Single'; end;end;
--- Code: Text [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Here is a "Dubious" solution to your question
jamie:
This is my version, close to another above but I found a 100 ms not working very well.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);Const WaitingForDouble:Boolean = false;Var T:Dword;begin If WaitingForDouble Then Begin Caption := 'Double Click'; WaitingForDouble := false; Exit; end; WaitingForDouble := True; T := GetTickCount; While GetTickCount-T < 250 Do Application.PRocessMessages; If WaitingForDouble Then Begin Caption := 'Single Click'; End;WaitingForDouble := false;end;
Hows that?
I double that will work in other widgets; seems something is strange with them, but this was a windows test.
Navigation
[0] Message Index
[#] Next page
[*] Previous page