How can I implement DoubleTap event and SingleTap event separately in webOS ?
In your handler for Mojo.Event.tap, look at the event's count field. That will be 2 for a double-tap, 1 for a single-tap. Note that you'll always get the single tap first, so make sure you don't do anything destructive on that.
Related
I'm having a trouble right now.
I have a matrix of objects. Each object is an image and has an event listener that is triggered when i tap the object.
the event changes the picture, using display.newImage() property.
at some point i want to remove the event listener. I found out that the removing isn't working on the images i tapped on. I can't really understand why, because clearly the event still exists after i tap one time on the image (i know that because i can tap and change the image more the once)... so I really don't know what the problem is.
thanks!
Make sure you are only registering the touch event ONCE for each image.
Also remember that the touch event is propagating (It will continue to trigger touch events for images that are underneath the first image) In order to prevent the touch event from propagating you need to return true at the end of your touch handler.
I would recommend adding print("Registered Touch Event") statements to check and make sure things are happening the way you want them.
Is there a way to detect a click and hold within a NSView? I want to trigger an event after holding the mouse button down for 0.5 sec - similar to a longPressGesture in iOS.
I don't know of a specific selector for this, which is what it sounds like you're asking for, but you could, quite easily, handle this yourself.
Start a timer when the mouse down event occurs and when the amount of time has passed, react to it if the mouse up event did not occur before the specified elapsed time.
Inside an Event Tap I need to distinguish the scroll event that comes from a magic mouse to that which comes from a TrackPad.
Does anyone have a solution to this problem? Is there a way to get the product ID of the generating device from the CGEvent? Can IOkit help me here?
I have a problem: how can I create gesture event by code, (rotate, magnify or swipe...), I don't want to use it to zoom or rotate a specific image or something like that, I want to create gesture event like scroll event create by CGEventRef cgEvent = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitLine, wheelCount, yScroll, xScroll);
CGEventPost(kCGHIDEventTap, cgEvent);
Thanks
Not all events have "shortcut" creation functions (like CGEventCreateScrollWheelEvent, CGEventCreateMouseEvent, and CGEventCreateKeyboardEvent), so you have to create an empty event and then set the fields manually using the CGEventSet* functions.
The gesture-related events only have public constants for the Cocoa API level. For example, while NSLeftMouseDragged == kCGEventLeftMouseDragged == NX_LMOUSEDRAGGED == 6, NSEventTypeMagnify == 30 doesn't have any equivalent kCGEventMagnify or NX_MAGNIFY.
Also, the way gesture events work is a bit tricky; if you don't send the proper sequence of mouse/trackpad events, gesture, gesture begin/end, and specific-gesture events, it won't work.
There's not much documentation on which fields each event type needs; the easiest way to find out is to first create an event tap that logs everything, then generate the events you want and see what gets logged. In fact, you probably want to also log an NSEvent global monitor (log both the NSEvent itself and its underlying cgEvent).
Is there a way to register for global mouse moved events in Cocoa? I was able to register for the events using Carbon's InstallEventHandler(), but would prefer a Cocoa equivalent. I have looked for NSNotificationCenter events, but there doesn't seem to be any public event names (are there private ones?)
Alternatively, is there a way to use NSTrackingArea for views with a clearColor background?
The app is Snow Leopard only.
In SnowLeopard there is a new class method on NSEvent which does exactly what you want: + (id)addGlobalMonitorForEventsMatchingMask:(NSEventMask)mask handler:(void (^)(NSEvent*))block. You’ll want mask = NSMouseMovedMask.
A similar question was already asked on StackOverflow:
How to make a transparent NSView subclass handle mouse events?
To summarize, the tansparent view method didn't work. Quartz Event Taps seem to be the best answer.
Here are some hints on working with taps:
Create the tap with CGEventTapCreate.
a) For the location (first) parameter you'll probably want to use kCGSessionEventTap.
b) For the placement (second) parameter you'll probably want kCGHeadInsertEventTap.
c) For the event mask parameter, try (1 << kCGEventMouseMoved).
Create a run loop source with CFMachPortCreateRunLoopSource, passing the event tap as the second parameter.
Add the run loop source to your run loop. Assuming you want it added to the main run loop, do:
CFRunLoopAddSource(CFRunLoopGetMain(), sourceFromStep2, kCFRunLoopDefaultMode);
Enable the event tap with CGEventTapEnable
If you want to track the mouse no matter where it is, you want a CGEventTap. There is no Cocoa equivalent. If you just want to track it in your application then you should explain why you're finding yourself unable to do so a little more thoroughly.