0

I'm currently working on a custom key binding mod for Minecraft. Although irrelevant, it gives some context. I'm planning to show a UI with all the buttons on their keyboard where they can click to assign macros to said key, although I don't want to be biased towards one particular keyboard button layout.

Looking at a website called switchandclick they show the differences between ISO and ANSI. ISO which I'm using has a key between left shift and Z, as well as having the return/enter key 2 keys tall rather than 1, with the missing key moved above right shift.

Here is the image from said site: ansi vs iso image

However, even if ISO is the layout used in Sweden where I live, I'm aware some users may be from different parts of the world, and ANSI is probably more common in America, so I don't want to show an ISO keyboard for ANSI users and vice versa.

I've looked around at various sources, but all I can find when looking for a solution is websites showing the differences between the layouts, rather than showing how to detect them.

So how would I go about detecting if the user has an ANSI or ISO keyboard? Pure Java is preferred but LWJGL 3 is the graphics api in use if that helps with finding a solution. I'm also running Java 17 in case that makes it easier.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Dennis Rönn
  • 101
  • 10
  • 3
    Did you see this SO question? [Get Physical Keyboard Layout Programmatically](https://stackoverflow.com/questions/4719488/get-physical-keyboard-layout-programmatically) – Abra Jun 17 '22 at 08:13
  • I know that difference as 104 key vs 105 key keyboards. And I'm not very optimistic that even the OS actually knows the physical configuration of the keyboard. At best you could query the mapping from scancodes to keypresses and use an educated guess (or a big database) to distinguish the two. – Joachim Sauer Jun 17 '22 at 08:15
  • I have never before heard those keyboard layouts referred to as ANSI or ISO – Mark Rotteveel Jun 17 '22 at 08:17
  • Oh that's unfortunate. I guess I'll have to make an option for it then or somehow guess it in a different way. I'm guessing there's also no way to check if the keyboard has 104 or 105 scan codes either then? – Dennis Rönn Jun 17 '22 at 08:20
  • @MarkRotteveel you don't frequent enough mechanical keyboards forums then :) See https://en.wikipedia.org/wiki/Keyboard_layout#Physical,_visual,_and_functional_layouts – Federico klez Culloca Jun 17 '22 at 08:23
  • A laptop could even have a second external keyboard, and for impaired users there also exist emulated touchscreen keyboards. And then there are the locales (QWERTY/AZERTY). So I would go with a common keyboard borrowed from the emulations, and not offer those special keys at all for customization. Also Alt Gr keys are cumbersome. – Joop Eggen Jun 17 '22 at 08:30
  • 2
    In any case, in the '80s and '90s if games (or other programs) were interested in distinguishing between these keyboard layouts, they prompted the user to hit the key next to the left-shift. – Mark Rotteveel Jun 17 '22 at 08:40

1 Answers1

0

As mentioned by @Abra in a comment to the question, there's no way to do that programmatically as there's no protocol between the keyboard controller and the keyboard driver that helps distinguish the layout of the keyboard.

Only option here is to either guess/predict the layout, let the user choose the layout, or simply use the same layout assumed by Windows in osk.exe.

Original answer on this post

Dennis Rönn
  • 101
  • 10