AppKitFocusOverlay

一个简单的包,用于显示 AppKit 窗口当前焦点 (nextKeyView) 的目标路径。

支持 Swift 和 Objective-C 项目。

为什么需要它?

应用程序具有键盘可导航性,并且标签页路径对用户来说有意义,这一点非常重要。最近有很多关于 iOS 上键盘导航的讨论,重点介绍了 Xcode 中 iOS 应用程序的 -UIFocusLoopDebuggerEnabled YES 启动参数选项。有人问这是否也适用于 AppKit,简短的答案是不适用。

几年前,我构建了此原型,供我自己的应用程序使用。它不像添加启动参数那样无缝,但添加起来也足够简单。鉴于它对我来说非常有用,我想把它干净地打包并公开。

演示

单击此处观看演示视频,了解焦点叠加层添加到出色的“ControlRoom”应用程序中的效果。

Demo 子文件夹中还有非常基本的 AppKit 示例应用程序(使用 Swift 和 Objective-C),您可以进行尝试。

简单的设置

import AppKitFocusOverlay
let _globalFocusOverlay = AppKitFocusOverlay()

func applicationDidFinishLaunching(_ aNotification: Notification) {
   // Force the focus overlay instance to init.
   _ = _globalFocusOverlay
   ...
}

特点

自定义热键

您可以在实例的初始化程序中定义要使用的热键。 默认情况下,这些热键是 command-option-[command-option-],但您可以将它们更改为 f13f14(例如)。

请注意,从 macOS 15.0 Sequoia 开始,快捷方式必须包含一个不是 shift 或 option 的修饰键

这是 macOS Sequoia 中的一项有意更改,旨在限制键盘记录恶意软件观察其他应用程序中的按键的能力。关注的问题是,shift+option 可以用来生成密码中的备用字符,例如 Ø (shift-option-O)。

没有解决方法;macOS Sequoia 现在要求热键注册至少使用一个不是 shift 或 option 的修饰键。

示例

import AppKitFocusOverlay
import HotKey               // Available due to AppKitFocusOverlay dependency 

let _globalFocusOverlay: AppKitFocusOverlay(
   windowHotKey: HotKey(key: .f13, modifiers: []),
   viewHotKey: HotKey(key: .f14, modifiers: [])
)

func applicationDidFinishLaunching(_ aNotification: Notification) {
   // Force the focus overlay instance to init.
   _ = _globalFocusOverlay
   ...
}

Objective-C 支持

您可以轻松地将 AppKitFocusOverlay 添加到您的 Objective-C 项目。

@import AppKitFocusOverlay;

@interface AppDelegate ()
/// Define an instance of the focus overlay
@property (nonatomic, strong) AppKitFocusOverlay* focusOverlay;
@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
   /// Create the overlay and attach
   AppKitFocusOverlay* focus = [[AppKitFocusOverlay alloc] init];
   [self setFocusOverlay: focus];
}

@end

注意

截图

感谢!

使用 HotKey 定义和检测热键按下。

许可

AppKitFocusOverlay

MIT License

Copyright (c) 2024 Darren Ford

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

HotKey

Copyright (c) 2017–2019 Sam Soffes, http://soff.es

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.