使OSX应用程序响应第一次鼠标单击时不聚焦 [英] Make OSX application respond to first mouse click when not focused

查看:218
本文介绍了使OSX应用程序响应第一次鼠标单击时不聚焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正常的OSX应用程序在没有聚焦时首先单击鼠标,首次聚焦应用程序。然后,未来的点击由应用程序处理。 iTunes播放/暂停按钮和Finder的行为不同,即使没有聚焦,第一次点击也会被执行。我正在寻找一种强制现有应用程序(远程桌面Connection.app)在第一次点击而不只是对焦的方式。

解决方案

检查NSView的acceptsFirstMouse,它可能是你正在寻找。



acceptsFirstMouse:
被子类覆盖返回YES,如果接收者应该发送一个mouseDown:消息来初始化鼠标按下事件,否则返回NO。 / p>


  • (BOOL)acceptsFirstMouse:(NSEvent *)theEvent


$ b b

参数
theEvent
初始鼠标按下事件,它必须在窗口中的接收者之上。



讨论
接收器可以无条件地返回值,也可以使用事件的位置来确定它是否需要事件。默认实现忽略事件并返回NO。



在子类中重写此方法,以允许实例响应点击。这允许用户点击非活动窗口中的视图,用一次点击激活视图,而不是首先点击以使窗口活动,然后点击视图。大多数视图对象拒绝点击尝试,因此事件只激活窗口。然而,许多控制对象(如NSButton和NSSlider的实例)都接受它们,因此用户可以立即操作控件,而不必释放鼠标按钮。


Normal OSX applications eat the first mouse click when not focused to first focus the application. Then future clicks are processed by the application. iTunes play/pause button and Finder behave differently, the first click is acted on even when not focused. I am looking for a way to force an existing application (Remote Desktop Connection.app) to act on the first click and not just focus.

解决方案

Check NSView's acceptsFirstMouse, it may be what you're looking for.

acceptsFirstMouse: Overridden by subclasses to return YES if the receiver should be sent a mouseDown: message for an initial mouse-down event, NO if not.

  • (BOOL)acceptsFirstMouse:(NSEvent *)theEvent

Parameters theEvent The initial mouse-down event, which must be over the receiver in its window.

Discussion The receiver can either return a value unconditionally or use the location of theEvent to determine whether or not it wants the event. The default implementation ignores theEvent and returns NO.

Override this method in a subclass to allow instances to respond to click-through. This allows the user to click on a view in an inactive window, activating the view with one click, instead of clicking first to make the window active and then clicking the view. Most view objects refuse a click-through attempt, so the event simply activates the window. Many control objects, however, such as instances of NSButton and NSSlider, do accept them, so the user can immediately manipulate the control without having to release the mouse button.

这篇关于使OSX应用程序响应第一次鼠标单击时不聚焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆