示例#1
0
        /// <summary>
        /// Gets the input locale identifier for the active application's thread.  Using this combined with the ToUnicodeEx and
        /// MapVirtualKeyEx enables Windows to properly translate keys based on the keyboard layout designated for the application.
        /// </summary>
        /// <returns>HKL</returns>
        private static uint GetActiveKeyboard()
        {
            IntPtr hActiveWnd = ThreadNativeMethods.GetForegroundWindow();                                  //handle to focused window
            int    dwProcessId;
            int    hCurrentWnd = ThreadNativeMethods.GetWindowThreadProcessId(hActiveWnd, out dwProcessId); //thread of focused window

            return(GetKeyboardLayout(hCurrentWnd));                                                         //get the layout identifier for the thread whose window is focused
        }