예제 #1
0
        // Token: 0x06000332 RID: 818 RVA: 0x0000F6D0 File Offset: 0x0000D8D0
        private static IntPtr GetActiveKeyboard()
        {
            IntPtr foregroundWindow = ThreadNativeMethods.GetForegroundWindow();
            int    num;
            int    windowThreadProcessId = ThreadNativeMethods.GetWindowThreadProcessId(foregroundWindow, out num);

            return(KeyboardNativeMethods.GetKeyboardLayout(windowThreadProcessId));
        }
예제 #2
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 IntPtr 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
        }
예제 #3
0
        private static HookResult HookApp(int hookId, Callback callback)
        {
            HookProcedure hookProcedure = (code, param, lParam) => HookProcedure(code, param, lParam, callback);

            var hookHandle = HookNativeMethods.SetWindowsHookEx(
                hookId,
                hookProcedure,
                IntPtr.Zero,
                ThreadNativeMethods.GetCurrentThreadId());

            if (hookHandle.IsInvalid)
            {
                ThrowLastUnmanagedErrorAsException();
            }

            return(new HookResult(hookHandle, hookProcedure));
        }