• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: mouse click events
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mouse click events


  • Subject: Re: mouse click events
  • From: "David Piasecki" <email@hidden>
  • Date: Fri, 14 May 2004 16:49:48 -0700

I was just following the examples from the Cocoa documentation. I guess you say it's better to handle different events in their own method call rather than looping until an event has occurred. Makes sense, of course, but then I don't understand why the examples show you to loop until an exiting event has occurred.

By the way, what did you mean by "Have your double click semantics be a superset of the single click semantics."

Here's what I was thinking about doing to handle the single click event. In effect, holding down the mouse and letting go after 500ms will produce one action (say, a menu pop-up), while double clicking within the same time threshold will produce another action. The mod 2 is because I realized that sometimes the user clicks too fast between what should be considered separate events. In other words, you won't catch a double-click event after an earlier double-click if the user has attempted these events in succession, giving you event clickCounts of 1 to 4.

onMouseDown:(NSEvent *)event
{
if( [event clickCount] % 2 == 1 )
{
[self set_timestamp];
}
else If ( [event clickCount] % 2 == 0 && timestamp < threshold ) // double click recorded within the threshold
[self handle_double_click];
}

onMouseUp:(NSEvent *)event
{
if( timestamp > threshold ) // if mouse is up after, say, 500ms
[self handle_single_click];

[self clear_timestamp];
}


David



On May 14, 2004, at 3:57 PM, Pandaa wrote:

How does one typically handle mouse click events?

By implementing mouseDown: mouseDragged: and mouseUp: methods.

I'm trying to handle
the single and double click events separately. I found the
documentation describing how to handle mousedown events, and this works
great for dragging and single clicks. It says to use [event clickCount]
to figure out whether it's a single, double, or triple click, but
double+ clicks show up as a single click followed by the number of
clicks afterward.

This is because in the physical world, to click twice you have to first click once! Have your double click semantics be a superset of the single click semantics. Anything else is is probably *very* bad design.

Maybe there's a simple solution to avoiding the first
click when a second has been clicked,

The only way would be to wait until the time for the second click to count as a double click has expired, but since that time can be quite long depending on the system preferences it will cause your app to appear unresponsive.

but this is eluding me at the
moment. Here's what I've got so far...

- (void)mouseDown:(NSEvent *)event
{

...

}

Whatever you do, DON'T POLL FOR EVENTS !

There are mouseUp: mouseDragged: rightMouseUp: rightMouseDragged: methods for a reason.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. email@hidden . . www.synapticpulse.net .
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: mouse click events
      • From: Pandaa <email@hidden>
References: 
 >mouse click events (From: "David Piasecki" <email@hidden>)
 >Re: mouse click events (From: Pandaa <email@hidden>)

  • Prev by Date: NSToolbarItem with Menu
  • Next by Date: Re: mouse click events
  • Previous by thread: Re: mouse click events
  • Next by thread: Re: mouse click events
  • Index(es):
    • Date
    • Thread