How to differentiate Click from MouseDblClick?
9 posts
• Page 1 of 1
How to differentiate Click from MouseDblClick?
In APL2000, there are three separate events: onClick, onMouseDouble, and onMouseDown. In Dyalog APL, there are two: MouseDown and MouseDblClick.
APL2000's separate onClick and onMouseDouble allows me to differentiate a single click from a double click. In Dyalog APL, since there is no onClick event and all I have is MouseDown, because both a single click and a double click both generate a MouseDown event, I can't differentiate them.
I thought of starting a Timer upon receipt of a MouseDown event and, if no double-click happens within, say, 500 msec, assume it's a Click. But if I do receive a double-click within that 500 msec, then assume it's not a Click and ignore the MouseDown and just process the MouseDblClick.
But that seems like overkill. Does anyone know how to more easily determine the difference between a click and a doubleclick, or have any other suggestions?
Thanks.
APL2000's separate onClick and onMouseDouble allows me to differentiate a single click from a double click. In Dyalog APL, since there is no onClick event and all I have is MouseDown, because both a single click and a double click both generate a MouseDown event, I can't differentiate them.
I thought of starting a Timer upon receipt of a MouseDown event and, if no double-click happens within, say, 500 msec, assume it's a Click. But if I do receive a double-click within that 500 msec, then assume it's not a Click and ignore the MouseDown and just process the MouseDblClick.
But that seems like overkill. Does anyone know how to more easily determine the difference between a click and a doubleclick, or have any other suggestions?
Thanks.
- Rav
- Posts: 31
- Joined: Tue Jul 25, 2023 4:41 pm
Re: How to differentiate Click from MouseDblClick?
You may want to look at the Select event which may correspond to APL2000's Click event.
- paulmansour
- Posts: 432
- Joined: Fri Oct 03, 2008 4:14 pm
Re: How to differentiate Click from MouseDblClick?
paulmansour wrote:You may want to look at the Select event which may correspond to APL2000's Click event.
Thanks, Paul, I appreciate your help. Unfortunately, what the user is clicking on is a Form (and they could be clicking ANYwhere on the form, not just on a child control). According to the documentation for the Select event, and by default I think this applies to Forms, "For all other objects, this event is generated when the user presses the keys associated with the object's Accelerator property." The user isn't pressing an accelerator key, they're clicking on the form. So I'm not seeing that this event is similar to a Click event. Or what am I missing? Thanks again.
- Rav
- Posts: 31
- Joined: Tue Jul 25, 2023 4:41 pm
Re: How to differentiate Click from MouseDblClick?
Hi Rav,
I have an idea for this.
Why not check the ups instead of the downs?
If the last mouse event was a mousedown, we have a single click. If the last one was a mousedblclick, we have a double click.
'f' ⎕wc 'form' ('event' 'mousedown' 'repmsg') ('event' 'mousedblclick' 'repmsg') ('event' 'mouseup' 'repmsg')
f MouseDown 33.70370483 77.60416412 1 0
f MouseUp 33.70370483 77.60416412 1 0
single
f MouseDown 37.9629631 56.77083206 1 0
f MouseUp 37.9629631 56.77083206 1 0
single
f MouseDblClick 37.9629631 56.77083206 1 0
f MouseUp 37.9629631 56.77083206 1 0
double click
Regards,
Vince
I have an idea for this.
Why not check the ups instead of the downs?
If the last mouse event was a mousedown, we have a single click. If the last one was a mousedblclick, we have a double click.
- Code: Select all
⍝ Assuming ⎕io 1 and ⎕ml 1:
⎕cr 'repmsg'
repmsg W
last,←⊂W[2]
shape←⍴last
⎕←W
:If W[2]≡⊂'MouseUp'
:If (⊃last[shape-1])≡⊂'MouseDown'
⎕←'single'
:Else
⎕←'double click'
:EndIf
:EndIf
'f' ⎕wc 'form' ('event' 'mousedown' 'repmsg') ('event' 'mousedblclick' 'repmsg') ('event' 'mouseup' 'repmsg')
f MouseDown 33.70370483 77.60416412 1 0
f MouseUp 33.70370483 77.60416412 1 0
single
f MouseDown 37.9629631 56.77083206 1 0
f MouseUp 37.9629631 56.77083206 1 0
single
f MouseDblClick 37.9629631 56.77083206 1 0
f MouseUp 37.9629631 56.77083206 1 0
double click
Regards,
Vince
- Vince|Dyalog
- Posts: 440
- Joined: Wed Oct 01, 2008 9:39 am
Re: How to differentiate Click from MouseDblClick?
Thanks, Vince. By the way, there's a missing comma in your repmsg program. It should be <,⊂'MouseDown'> not just <⊂'MouseDown'>.
At any rate, if I've followed your logic correctly, while it does eventually report "double click", when you do that double-click it first reports "single". That's because when doing a double-click Dyalog APL first sees and reports MouseDown+MouseUp, then sees and reports MouseDblClick+MouseUp. So I still have the problem that my program first executes my handler for the single click, then executes my handler for the double click, when what I really want is just to handle the double click. Again, I think I would have to use a Timer to delay handling the single click until, and only if, it sees that there was no following double-click within a certain amount of time (i.e. 500 msec). Or what am I missing? Thanks! / Rav
At any rate, if I've followed your logic correctly, while it does eventually report "double click", when you do that double-click it first reports "single". That's because when doing a double-click Dyalog APL first sees and reports MouseDown+MouseUp, then sees and reports MouseDblClick+MouseUp. So I still have the problem that my program first executes my handler for the single click, then executes my handler for the double click, when what I really want is just to handle the double click. Again, I think I would have to use a Timer to delay handling the single click until, and only if, it sees that there was no following double-click within a certain amount of time (i.e. 500 msec). Or what am I missing? Thanks! / Rav
- Rav
- Posts: 31
- Joined: Tue Jul 25, 2023 4:41 pm
Re: How to differentiate Click from MouseDblClick?
It might help to remember that there is no such thing as a double-click: it's two single clicks within a (user-configurable!) space of time.
-
kai - Posts: 141
- Joined: Thu Jun 18, 2009 5:10 pm
- Location: Hillesheim / Germany
Re: How to differentiate Click from MouseDblClick?
Thanks for your reply, Rav.
I don't think you're missing anything.
We thought we might ask: what end result do you want to achieve?
What do you want your form to do for a single click and what action for a double click?
Regards,
Vince
I don't think you're missing anything.
We thought we might ask: what end result do you want to achieve?
What do you want your form to do for a single click and what action for a double click?
Regards,
Vince
- Vince|Dyalog
- Posts: 440
- Joined: Wed Oct 01, 2008 9:39 am
Re: How to differentiate Click from MouseDblClick?
Vince|Dyalog wrote: ... We thought we might ask: what end result do you want to achieve?
What do you want your form to do for a single click and what action for a double click? ...
Hi, Vince. What I'm trying to do is make my Dyalog APL Windows app accessible from things like iPhones and iPads. Since I can't develop native apps for those devices, I'm resorting to using a remote-desktop-type solution. I'm using Amazons AWS AppStream 2.0 service to host a single session of my app, which my users can connect to. The issue is that neither of those devices has a mouse (and my users won't be attaching external keyboards or mice). One section of my app displays a map of where all the residents of my community live. When running my app locally on a Windows PC, they can use their mouse to: (1) Hover over a residence, which displays a popup containing their name and a small picture, and (2) Click on a residence, which brings up a full bio and a larger picture in a separate window. But as I said iPhones and iPads don't have a mouse, so I can't detect hovering (plus, for whatever reason, when using an iPhone, AppStream fails to see the cursor position changing when the user changes their finger position). So I decided to substitute single and double clicks to accomplish (1) and (2).
For now, I'm using the technique of creating a timer when I receive a MouseDown event, and seeing if I get another MouseDown event within the duration of that timer (500 msec). If the timer fires, I know I haven't received a second MouseDown event during that time so I interpret that as a single click and perform my single-click action. If I get a second MouseDown event before the timer fires, I interpret that as a double click, so I cancel the timer (erase it) and perform my double-click action. This technique is working.
I hope that makes sense. / Rav
- Rav
- Posts: 31
- Joined: Tue Jul 25, 2023 4:41 pm
Re: How to differentiate Click from MouseDblClick?
Hi Rav,
Thanks for your explanation of what you're doing.
I will let my colleagues know about what you have achieved.
I am glad that your workaround is working for you.
Regards,
Vince
Thanks for your explanation of what you're doing.
I will let my colleagues know about what you have achieved.
I am glad that your workaround is working for you.
Regards,
Vince
- Vince|Dyalog
- Posts: 440
- Joined: Wed Oct 01, 2008 9:39 am
9 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group