Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keyboard Type (Qwerty or Dvorak) detection

Tags:

c#

I was asked this question by a friend, and it piqued my curiosity, and I've been unable to find a solution to it yet, so I'm hoping someone will know.

Is there any way to programatically detect what type of keyboard a user is using? My understanding of the keyboard is that the signal sent to the computer for 'A' on a DVORAK keyboard is the same as the signal sent to the computer for an 'A' in a QUERTY keyboard. However, I've read about ways to switch to/from dvorak, that highlight registry tweaking, but I'm hoping there is a machine setting or some other thing that I can query.

Any ideas?

like image 443
Drew McGhie Avatar asked May 15 '09 16:05

Drew McGhie


3 Answers

You can do this by calling the GetKeyboardLayoutName() Win32 API method. Dvorak keyboards have specific names. For example, the U.S. Dvorak layout has a name of 00010409.

Code snippet:

  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);

    }
  }
like image 167
Magnus Johansson Avatar answered Oct 03 '22 06:10

Magnus Johansson


that probably depends on the OS. I'm sure that there is an operatingsystem setting somewhere that registers the nationality of the keyboard. (Dvorak is considered a nationality because French keyboards are different from US keyboards are different from ...)

Also, just a side note: 'A' was a bad example, as 'A' happens to be the same key in dvorak and qwerty... B-)

like image 44
Brian Postow Avatar answered Oct 03 '22 06:10

Brian Postow


You might be able to do it via DirectInput, or whatever the current DirectX-equivalent is. I type on a Dvorak keyboard, and about 50% of the games I buy detect my keyboard and reconfigure the default keymappings to support it (using ,aoe instead of wasd, for instance)

And yes, as Brian mentioned, 'A' is the same on both keyboards.

like image 32
Aric TenEyck Avatar answered Oct 03 '22 05:10

Aric TenEyck