NSButton 捕获鼠标点击事件
我有代码
#import <Cocoa/Cocoa.h>
@interface MyButton : NSButton
{
}
- (void)mouseDown:(NSEvent *)theEvent;
@end
#import "ContextMenuButton.h"
@implementation MyButton
- (void)mouseDown:(NSEvent *)theEvent;
{
// ...
}
根据 NSControl 类参考 mouseDown
通知接收者用户已按下鼠标左键。
我怎样才能捕获右键和其他鼠标按钮的点击?
I have the code
#import <Cocoa/Cocoa.h>
@interface MyButton : NSButton
{
}
- (void)mouseDown:(NSEvent *)theEvent;
@end
#import "ContextMenuButton.h"
@implementation MyButton
- (void)mouseDown:(NSEvent *)theEvent;
{
// ...
}
According to the NSControl Class Reference mouseDown
informs the receiver that the user has pressed the left mouse button.
How could I catch right and others mouse button clicks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NSControl
间接派生自NSResponder
,并且具有方法mouseDown:
、rightMouseDown:
和otherMouseDown :
,所有三个都以NSEvent*
作为参数。NSControl
derives, indirectly, fromNSResponder
, and that has methodsmouseDown:
,rightMouseDown:
andotherMouseDown:
, all three taking anNSEvent*
as parameter.NSButton
仅在左键单击时响应。无论如何,看看 NSEvent 类型。它确定了有关事件的大量信息,包括按下了哪个按钮。NSButton
responds only on the left button click. Anyway take a look at NSEvent type. It determines a lot of info about event including wich button was pressed.