Detecting the layout of an internal Apple hardware keyboard

Is there an API or a method for detecting which of the three main keyboard layouts – ANSIISO, or Japanese – a Mac notebook uses?

After fairly extensive research, I could not find any information about this.

Answered by DTS Engineer in 695774022

The Old School™ way of doing this is to call LMGetKbdType to get the type of the last key press and then KBGetLayoutType to map it to a layout type. I just tested this (on macOS 11.6.1) and it still works just fine.

I don’t know if there’s a better way to do this. I added the AppKit tag to your post to see if someone with more recent UI programming experience might chime in.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

The Old School™ way of doing this is to call LMGetKbdType to get the type of the last key press and then KBGetLayoutType to map it to a layout type. I just tested this (on macOS 11.6.1) and it still works just fine.

I don’t know if there’s a better way to do this. I added the AppKit tag to your post to see if someone with more recent UI programming experience might chime in.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

is it okay to use them for Mac App Store distribution?

Yes.

Well, technically, the only folks who can give you definitive answers about what is or isn’t allowed on the store is App Review, and I don’t work for App Review. However, you’re using an API declared in the public macOS SDK for its intended purpose, so I wouldn’t be worried about this.

although not yet deprecated

[This isn’t relevant here because, as you say, the APIs in question are not deprecated. However, I want to be clear about this for folks reading along at home.]

In most cases App Review does not care about folks using deprecated APIs. Such exceptions that do exist, like UIWebView, are specifically called out. So, using a deprecated API isn’t an App Review pitfall.

However, it can be a long-term compatibility pitfall. Indeed, App Review calls this out in the App Store Review Guidelines:

Keep your apps up-to-date and make sure you phase out any deprecated features, frameworks or technologies that will no longer be supported in future versions of an OS.

The suggestion to “phase out” deprecated APIs is sound technical advice.

Coming back to your specific case, I’ll reiterate that I’m not sure whether there’s a more modern alternative to the approach I suggested. If you want a definitive answer about that, I recommend that you open a DTS tech support incident and talk to DTS’s keyboard expert.

Note DTS is officially closed this week for the US Thanksgiving holiday. If you open an incident now, we won’t get to it until next week.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Detecting the layout of an internal Apple hardware keyboard
 
 
Q