Keyboard Type (Qwerty or Dvorak) detection

前端 未结 4 1154
自闭症患者
自闭症患者 2020-12-10 07:59

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 a

相关标签:
4条回答
  • 2020-12-10 08:47

    Why would it matter? Depending on some special implementation of a keyboard is no good idea at all. We use barcode scanners all over the place that emulate keyboard inputs. What would your program do with these devices? :)

    PS: the mentioned registry entry arranges the keys of a regular keyboard into dvorak layout.

    0 讨论(0)
  • 2020-12-10 08:49

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

    0 讨论(0)
  • 2020-12-10 08:49

    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.

    0 讨论(0)
  • 2020-12-10 08:51

    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);
    
        }
      }
    
    0 讨论(0)
提交回复
热议问题