Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
905 views
in Technique[技术] by (71.8m points)

macos - How can I override the 3-finger tap behavior in a NSTextView?

On Mac OS X, doing a 3-finger tap on a word pops up a window with a definition of the word.

Image showing a pop up window showing a word definition.

This idiom is also used in Xcode, where doing a 3-finger tap over a symbol shows its documentation, much like if it had been alt+clicked.

Image showing a pop up window showing symbol documentation.

I would like to do something similar to that and display definitions when users of my application do a 3-finger tap on certain tokens in a NSTextView. However, I can't find how to detect that a tap has been done with 3 fingers. Could someone help me with that?

EDIT If this reminds anything to anyone, three events (caught by overriding [NSApplication sendEvent:]) are triggered when you do this kind of tap:

NSEvent: type=SysDefined loc=(270.918,250.488) time=417954.6 flags=0x100 win=0x0 winNum=28293 ctxt=0x0 subtype=6 data1=1818981744 data2=1818981744
NSEvent: type=SysDefined loc=(270.918,250.488) time=417954.6 flags=0x100 win=0x0 winNum=28293 ctxt=0x0 subtype=9 data1=1818981744 data2=1818981744
NSEvent: type=Kitdefined loc=(0,263) time=417954.8 flags=0x100 win=0x0 winNum=28306 ctxt=0x0 subtype=4 data1=1135411200 data2=1132691456
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Reacting on a triple tap in a NSTextView can most easily be done by overriding quickLookWithEvent:.

-(void)quickLookWithEvent:(NSEvent *)event
{
    NSLog(@"Look at me! %@", event);
}

It also taught me that you can triple tap anything to invoke Quick Look on it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...