C# - Get user keyboard type (QWERTY/AZERTY)

1

I'm trying since 2 days to get the user's keyboard type (QWERTY or AZERTY) in C#. I thought about doing it with CultureInfo (localization), but that's definitely not a great workaround.

Any idea?

Adrien Neveu

Posted 2013-10-17T19:23:29.393

Reputation: 442

possible duplicate of Keyboard Type (Qwerty or Dvorak) detection

– sab669 – 2013-10-17T19:59:24.983

Why would you want to do this? – David Arno – 2013-10-17T20:44:27.747

@DavidArno Perhaps to set different default controls for a PC game? Might want to use different keys for different layouts? – sab669 – 2016-06-01T19:49:56.143

It was for a PC game indeed :) – Adrien Neveu – 2016-06-01T21:11:04.403

Answers

1

There's a GetKeyboardLayout method you can use;

 public class Program
   {
     const int KL_NAMELENGTH = 9;

     [DllImport("user32.dll")]
     private static extern long GetKeyboardLayoutName(
           System.Text.StringBuilder pwszKLID); 

     static void Main(string[] args)
     {
       StringBuilder name = new StringBuilder(KL_NAMELENGTH);

       GetKeyboardLayoutName(name);

       Console.WriteLine(name);

     }
   }

Source; Keyboard Type (Qwerty or Dvorak) detection

MSDN; http://msdn.microsoft.com/en-us/library/windows/desktop/ms646298(v=vs.85).aspx

sab669

Posted 2013-10-17T19:23:29.393

Reputation: 2 325