How to check for double click?
Monkey Forums/Monkey Programming/How to check for double click?
| ||
Likely some simple command, but I have no idea how to check for double clicking. Just need to use it for an if statement if doubleclick Then ... Thanks |
| ||
I don't know if this will be helpful to you. I created a mouse class that take care of double clicks as well as the frame at which the mouse was pressed and the frame at which the mouse was released. there is probably somebody out here who has a better example maybe you can extract something from here that can help you: you need to add mouse.Update() to the top of the "OnCreate" method. and use mouse.DoubleClick() to check. you can adjust the double click sensitivity by adjusting the value of "REPEATTIME". |
| ||
Here is my solution for double clicking. There is a BUT to this code though. Now your single click has a delay of 200ms. Well whatever number you put here:If (Millisecs() - mouseHitTime) > 200 Then May be someone has a solution that can do it without the delay. Anyway here is the code: |
| ||
Here's my solution (similar to Ferdi's): Basically, count the number of clicks within a click-initiated time period, and handle accordingly. |
| ||
I has something similar to do when looking for a double touch. I went for something general in the form of an EventRecorder and that allows for recording all kind of sequential behaviors that in turn trigger a condition. [monkeycode] Import diddy Import geometry Import monkey.math Import debug Class RecordEntry Field location:HOPoint Field pointer:Int Field occuredOn:Int Method New(x:Int,y:Int,pointer:Int) Self.location = New HOPoint(x,y) Self.pointer = pointer Self.occuredOn = Millisecs() End End Class EventRecorder Field recordedQueue: ArrayList<RecordEntry> Field doubleClickDetectionEnabled:Bool Const DOUBLE_CLICK_SPATIAL_TOLERANCE := 20 '20 Pixels should be ok. To test. Const DOUBLE_CLICK_TEMPORAL_TOLERANCE := 500 'in millisecs Method New() recordedQueue = New ArrayList<RecordEntry> Self.Clear() 'Maybe Overkill FIXME Self.DisableDoubleClickDetection() End Method Clear:Void() recordedQueue.Clear() End Method EnableDoubleClickDetection() Self.doubleClickDetectionEnabled = True End Method DisableDoubleClickDetection() Self.doubleClickDetectionEnabled = False End Method Record(x,y,pointer) recordedQueue.AddLast(New RecordEntry(x,y,pointer)) End Method DoubleClickDetected:Bool(pointer:Int) 'RULE for double click: two last events recorded are 'more or less on the same place and close enough in time 'and for the same pointer 'and for the specified pointer // TODO Local occured := false If (doubleClickDetectionEnabled and (recordedQueue.Size > 1)) Then 'We need to have at least 2 things in the queue Local last:RecordEntry = recordedQueue.Get(recordedQueue.Size-1) Local penultimate:RecordEntry = recordedQueue.Get(recordedQueue.Size-2) If (last.pointer = penultimate.pointer) Then If ((last.occuredOn - penultimate.occuredOn) < DOUBLE_CLICK_TEMPORAL_TOLERANCE) Then If (last.location.CloseEnough(penultimate.location, DOUBLE_CLICK_SPATIAL_TOLERANCE)) Then occured = true 'Consume Self.Clear() 'Check how well this works... EndIf EndIf EndIf EndIf Return occured End End [/monkeycode] |
| ||
Good idea taking into account the spatial tolerance. You might want to try to get it in terms of phyical distance (say 5mm) although in some cases that might have to be estimated. |