Forum > LCL
Is there build in way to distinguish between single mouse down and double clicks
daniel_sap:
Hi,
I have a custom control which executes code on mouse down.
But when user double clicks I would like to execute different code.
Now, cause the double click event comes after second mouse down the first code is executed (even twice)
I'm planning to implement internal timer after every mouse down, to see if second mouse down will occur in short time,
but wanted to ask if there is something already developed in for custom controls in LCL,
or may be you know better approach to this.
(hm, may be I have to use click, double click, drag)
I'm mentioning drag here, cause this is also needed, not only double clicks, also drags
Thanks
silvercoder70:
Doing this from memory...
you would need to look at (i) using OnMouseDown events, (ii) click counter and (iii) timer to detect time-out for a single click action.
the click counter has to reset at end of each complete action. Hope that makes sense.
LV:
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;
Updated: see also topic https://forum.lazarus.freepascal.org/index.php/topic,62991.msg476740.html#msg476740
silvercoder70:
I think the easiest way is .... :( :-[
--- 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.ClickTimerTimer(Sender: TObject);begin clickCount := 0; ClickTimer.Enabled := False; showMessage('code for single click');end; procedure TForm1.Label1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin Inc(clickCount); if (clickCount = 1) then begin ClickTimer.Enabled := True; end else if (clickCount = 2) then begin clickCount := 0; ClickTimer.Enabled := False; showMessage('code for double click'); end;end;
Warfley:
You can simply do the following:
--- 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 counter: Integer = 0;var start: QWord;begin Inc(counter); if counter > 1 then exit; try start := GetTickCount64; { Threshold for how long to wait for double click in milliseconds } while (GetTickCount64-start < 100) and { if you want to allow for tripple or quadruple clicks change here } (counter < 2) do Application.ProcessMessages; ShowMessage('Clicks: ' + counter.ToString); finally counter := 0; end;end;
PS: You should probably (as in my example) use mouseup not mousedown. Typically mous click events are triggered when the user lifts the button (so when you click and realize mid click you didn't want to you can just not release the button and move the mouse somewhere else). Triggering on mousedown would lead to rather confusing behavior
Navigation
[0] Message Index
[#] Next page