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.
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:
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:
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:
I'd recommend going with a similar approach instead.