/// <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
        }
Ejemplo n.º 2
0
        internal override int Subscribe(int hookId, HookCallback hookCallback)
        {
            int hookHandle = HookNativeMethods.SetWindowsHookEx(
                hookId,
                hookCallback,
                IntPtr.Zero,
                ThreadNativeMethods.GetCurrentThreadId());

            if (hookHandle == 0)
            {
                ThrowLastUnmanagedErrorAsException();
            }

            return(hookHandle);
        }