0

I'm currently working on a heatmap implementation in certain app. The keycodes are stored independently of their characters (since I want this heatmap to be keyboard layout agnostic). Ill be rendering the heatmap itself on the given view collection:

keyboard image

Question is: how do I correctly link a keyCode, say 5 for G on a typical US style Qwerty keyboard, to the correct Unicode character. I can keep this blank but I want it to render the user's current keyboard layout on the heatmap itself.

I've looked at the file AppleKeyboardLayouts-L.dat which seems to contain the data I need; but it's hard to interpret. I've so far been able to find out that the header contains the location of the keyboard layout data itself, the location of the PNG icons they use system wide and some other metadata. While this was a fun reversing past (waste of?) time there is probably a lower level framework e.g. CoreServices or maybe CoreText that could do this for me.

Some sniffing around lead me to this specific structure in CoreServices, which might be on the right track but honestly this is far deeper than I've ever dug in any of the string related API's in macOS. UCKeyboardLayout Apple Developer documentation

Antwan van Houdt
  • 6,989
  • 1
  • 29
  • 52
  • "how do I correctly link a keyCode, say 5 for G on a typical US style Qwerty keyboard" You don't. The system does it according to a speficifiation (ASCII). – El Tomato Sep 14 '21 at 23:05
  • When you navigate one level up from `UCKeyboardLayout` to Unicode Utilities then you'll find `UCKeyTranslate`. – Willeke Sep 15 '21 at 07:25
  • @ElTomato What does ASCII have to do with keyboard layouts? Do you mean ANSI? – Willeke Sep 15 '21 at 07:27
  • @Willeke Actually, I didn't mean anything. After making two comments, I was going to delete them. I subsequently returned here and deleted one. But I guess I forgot to delete the first one. I'm sorry about that. – El Tomato Sep 15 '21 at 08:03
  • @Willeke The linked question (and the suggested UCKeyTranslate docs) was indeed the correct information I was looking for. Thanks a lot! Some new terms here, "Virtual key code" is not something I used before but does seem to more accurately pin in search engines on what I was actually trying to accomplish here. – Antwan van Houdt Sep 15 '21 at 09:11

0 Answers0