Hi, I’ve seen some articles talking about detecting gestures: http://www.cocoadev.com/index.pl?MultiTouchTrackpad and http://tumbljack.com/post/1494097674/void-swipewithevent-nsevent-event
How can I use this code in an ASOC application?
Hi, I’ve seen some articles talking about detecting gestures: http://www.cocoadev.com/index.pl?MultiTouchTrackpad and http://tumbljack.com/post/1494097674/void-swipewithevent-nsevent-event
How can I use this code in an ASOC application?
Read the documentation first: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/EventOverview/HandlingTouchEvents/HandlingTouchEvents.html%23//apple_ref/doc/uid/10000060i-CH13-SW10
Then it’s just a matter of writing suitable handlers, like any other event-handling.
I’m trying to detect a swipe. I know I (think I) need
swipeWithEvent
but I’m not sure about using it, or rather, how to use it.
Just try it – add an “on swipeWithEvent_(anEvent)” handler, and log what gets passed to it.
Ok! That works! =)
How do I tell whether it’s up, down, left or right?
EDIT: That’d be with deltaX and deltaY right? But how do I get them from the event?
anEvent's deltaX
?
Try it, and then tell us. Really, just trying this stuff is often quicker than typing out the question…
Ok, well this seems to work:
log deltaX of anEvent
log deltaY of anEvent
I now also know that…
Left swipe: X = 1 and Y = 0
Right swipe: X = -1 and Y = 0
Up: X = 0 and Y = 1
Down: X = 0 and Y = -1
but using an “if” statement doesn’t seem to work, not with “1.0” as an integer or as a string.
Solved!
I needed to convert the X to a string…
set x to (anEvent's deltaX) as string
set y to (anEvent's deltaY) as string
if x is "1" and y is "0" then
log "LEFT SWIPE!"
else if x is "-1" or y is "0" then
log "RIGHT SWIPE!"
else if x is "0" or y is "1" then
log "UP SWIPE!"
else if x is "0" or y is "-1" then
log "DOWN SWIPE!"
end if
FYI, a real should work, too.