检测活动键盘是否在Swift中具有物理`fn`键

发布于 2025-01-27 03:24:12 字数 270 浏览 2 评论 0 原文

我想使用 fn 修改器密钥(如果有),如果没有,请为用户提供其他修饰符。但是,仅将其提供给没有 fn 密钥的用户。某些外部键盘没有 fn 键。

有什么方法可以检测活动键盘是否具有物理 fn 键?

(我不问如何检测 fn 钥匙按)

我正在寻找Swift中的解决方案,该解决方案在沙盒应用程序中起作用。

I want to use the Fn modifier key if available, and if not, offer the user a different modifier. But only offer it to users without a Fn key. Some external keyboard do not have a Fn key.

Is there any way to detect whether the active keyboard has a physical Fn key?

(I am not asking how to detect a Fn key press)

I'm looking for a solution in Swift that works within a sandboxed app.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以畏孤独 2025-02-03 03:24:12

要回答这个问题,我将解释该策略,但是即使有办法,也可能不值得这样做。

有些情况要考虑:

  1. 可能是MacBook,
  2. 它可能是一本MacBook,其中包含多个键盘,
  3. 我们可能正在处理一个没有FN键的A1048,
  4. 可能会有一个带有无头的Mac Mini,其中带有屏幕上的键盘,确实有一个FN键,但是在按下时不会发射可检测的事件,
  5. 可能会附上一个第三方蓝牙键盘(不是Apple),该键盘具有FN键,但是将使用该修饰符应用的笔触,因此不会是可检测

到我们没有任何API可悲地检查物理按钮的存在,但是我们确实有:

显然考虑到这些API在沙盒环境中可用,我们可以制作一个详尽的数据库。我们还可以将列表限制在流行模型中以使其更小。


从UX的角度来看,这就是一个例子。过去,在Windows键盘上,我们曾经有此键:

“

但并非所有键盘都具有它,因此要补偿, shift + f10 相同的。仍然在Windows 11中做。

或者,如果您为用户写了通知,则显示替代方案非常常见:

”

我建议我建议采用类似的方法去。

To answer the question I'll explain the strategy but even if there is a way, it's probably not worth going for it.

Some cases to consider:

  1. It might be a MacBook
  2. It might be a MacBook with more than one keyboard attached
  3. We might be dealing with an A1048 which doesn't have an Fn key
  4. There might be a headless Mac Mini with an on-screen keyboard which does have an Fn key, but doesn't fire detectable events when pressed
  5. There might be a 3rd party bluetooth keyboard attached (not Apple) which has an Fn key, but the strokes applied with that modifier will be emulated, so it will not be detectable

Across the board we don't have any APIs to check for physical button presence sadly, but we do have:

Obviously considering that these APIs are available in a sandboxed environment, we can make an exhaustive database. We can also limit the list to popular models to make it smaller.


From a UX perspective though, here is an example. On Windows keyboards in the past we used to have this key:

windows menu key

But not all keyboards had it, so to compensate, Shift+F10 does the same. Still does in Windows 11.

Or if you're writing a notification for the user, it's very common to show the alternatives:

chrome devtools zooming shortcuts

I'd recommend going with a similar approach instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文