Here's a tip from my colleague Ed Wilson (a.k.a. The Scripting Guy at Microsoft) that shows you how to use Windows PowerShell to detect the keyboard layout.
Question: You need to be able to programmatically determine keyboard layout. How can you do this using Windows PowerShell?
Answer: Use the Get-Culture cmdlet and select the KeyboardLayoutID parameter. This command appears here:
Ed Wilson is the bestselling author of eight books about Windows Scripting, including Windows PowerShell 3.0 Step by Step, and Windows PowerShell 3.0 First Steps. He writes a daily blog about Windows PowerShell call Hey, Scripting Guy! that is hosted on the Microsoft TechNet Script Center; for more PowerTips check out the Hey, Scripting Guy! blog.