GetKeyboardLayout() private method

private GetKeyboardLayout ( uint idThread ) : IntPtr
idThread uint
return System.IntPtr
Example #1
0
        public static void CheckForChanges()
        {
            // Detect keyboard layout changes by querying the foreground window
            // for its layout, and apply the same layout to WinCompose itself.
            Window.Hwnd = NativeMethods.GetForegroundWindow();

            var tid           = NativeMethods.GetWindowThreadProcessId(Window.Hwnd, out var pid);
            var active_layout = NativeMethods.GetKeyboardLayout(tid);

            if (active_layout != m_current_layout)
            {
                m_transformed_hkl = m_current_layout = active_layout;

                Log.Debug("Active window layout tid:{0} handle:0x{1:X} lang:0x{2:X}",
                          tid, (uint)active_layout >> 16, (uint)active_layout & 0xffff);

                if (active_layout != (IntPtr)0)
                {
                    NativeMethods.ActivateKeyboardLayout(active_layout, 0);
                }

                tid           = NativeMethods.GetCurrentThreadId();
                active_layout = NativeMethods.GetKeyboardLayout(tid);

                Log.Debug("WinCompose process layout tid:{0} handle:0x{1:X} lang:0x{2:X}",
                          tid, (uint)active_layout >> 16, (uint)active_layout & 0xffff);

                // We need to rebuild the list of dead keys
                AnalyzeLayout();
            }
        }
Example #2
0
        private static void CheckKeyboardLayout()
        {
            // Detect keyboard layout changes by querying the foreground window,
            // and apply the same layout to WinCompose itself.
            IntPtr hwnd = NativeMethods.GetForegroundWindow();
            uint   pid, tid = NativeMethods.GetWindowThreadProcessId(hwnd, out pid);
            IntPtr active_layout = NativeMethods.GetKeyboardLayout(tid);

            m_window_is_gtk           = false;
            m_window_is_office        = false;
            m_window_is_other_desktop = false;

            const int     len = 256;
            StringBuilder buf = new StringBuilder(len);

            if (NativeMethods.GetClassName(hwnd, buf, len) > 0)
            {
                string wclass = buf.ToString();

                if (wclass == "gdkWindowToplevel" || wclass == "xchatWindowToplevel" ||
                    wclass == "hexchatWindowToplevel")
                {
                    m_window_is_gtk = true;
                }

                if (wclass == "rctrl_renwnd32" || wclass == "OpusApp")
                {
                    m_window_is_office = true;
                }

                if (Regex.Match(wclass, "^(SynergyDesk|cygwin/x.*)$").Success)
                {
                    m_window_is_other_desktop = true;
                }
            }

            if (active_layout != m_current_layout)
            {
                m_current_layout = active_layout;

                Log.Debug("Active window layout tid:{0} handle:0x{1:X} lang:0x{2:X}",
                          tid, (uint)active_layout >> 16, (uint)active_layout & 0xffff);

                if (active_layout != (IntPtr)0)
                {
                    NativeMethods.ActivateKeyboardLayout(active_layout, 0);
                }

                tid           = NativeMethods.GetCurrentThreadId();
                active_layout = NativeMethods.GetKeyboardLayout(tid);

                Log.Debug("WinCompose process layout tid:{0} handle:0x{1:X} lang:0x{2:X}",
                          tid, (uint)active_layout >> 16, (uint)active_layout & 0xffff);

                // We need to rebuild the list of dead keys
                AnalyzeKeyboardLayout();
            }
        }
Example #3
0
        // FIXME: this is useless for now
        private static void CheckKeyboardLayout()
        {
            // FIXME: the foreground window doesn't seem to notice keyboard
            // layout changes caused by the Win+Space combination.
            IntPtr hwnd = NativeMethods.GetForegroundWindow();
            uint   pid, tid = NativeMethods.GetWindowThreadProcessId(hwnd, out pid);
            IntPtr active_layout = NativeMethods.GetKeyboardLayout(tid);

            //Console.WriteLine("Active layout is {0:X}", (int)active_layout);

            tid = NativeMethods.GetCurrentThreadId();
            IntPtr my_layout = NativeMethods.GetKeyboardLayout(tid);
            //Console.WriteLine("WinCompose layout is {0:X}", (int)my_layout);
        }
Example #4
0
        // FIXME: this is useless for now
        private static void CheckKeyboardLayout()
        {
            // FIXME: the foreground window doesn't seem to notice keyboard
            // layout changes caused by the Win+Space combination.
            IntPtr hwnd = NativeMethods.GetForegroundWindow();
            uint   pid, tid = NativeMethods.GetWindowThreadProcessId(hwnd, out pid);
            IntPtr active_layout = NativeMethods.GetKeyboardLayout(tid);

            Log.Debug("Active window layout handle:0x{0:X} lang:0x{0:X}",
                      (uint)active_layout >> 16, (uint)active_layout & 0xffff);

            tid = NativeMethods.GetCurrentThreadId();
            IntPtr my_layout = NativeMethods.GetKeyboardLayout(tid);

            Log.Debug("WinCompose process layout handle:0x{0:X} lang:0x{0:X}",
                      (uint)my_layout >> 16, (uint)my_layout & 0xffff);
        }
Example #5
0
        public static void CheckForChanges()
        {
            // Detect keyboard layout changes by querying the foreground window,
            // and apply the same layout to WinCompose itself.
            IntPtr hwnd = NativeMethods.GetForegroundWindow();
            uint   pid, tid = NativeMethods.GetWindowThreadProcessId(hwnd, out pid);
            IntPtr active_layout = NativeMethods.GetKeyboardLayout(tid);

            if (hwnd != m_current_hwnd)
            {
                Window.IsGtk          = false;
                Window.IsNPPOrLO      = false;
                Window.IsOffice       = false;
                Window.IsOtherDesktop = false;

                const int     len = 256;
                StringBuilder buf = new StringBuilder(len);
                if (NativeMethods.GetClassName(hwnd, buf, len) > 0)
                {
                    string wclass = buf.ToString();
                    Log.Debug($"Window {hwnd} ({wclass}) got focus");

                    if (wclass == "gdkWindowToplevel" || wclass == "xchatWindowToplevel" ||
                        wclass == "hexchatWindowToplevel")
                    {
                        Window.IsGtk = true;
                    }

                    /* Notepad++ or LibreOffice */
                    if (wclass == "Notepad++" || wclass == "SALFRAME")
                    {
                        Window.IsNPPOrLO = true;
                    }

                    if (wclass == "rctrl_renwnd32" || wclass == "OpusApp")
                    {
                        Window.IsOffice = true;
                    }

                    if (Regex.Match(wclass, "^(SynergyDesk|cygwin/x.*)$").Success)
                    {
                        Window.IsOtherDesktop = true;
                    }
                }

                m_current_hwnd = hwnd;
            }

            if (active_layout != m_current_layout)
            {
                m_current_layout = active_layout;

                Log.Debug("Active window layout tid:{0} handle:0x{1:X} lang:0x{2:X}",
                          tid, (uint)active_layout >> 16, (uint)active_layout & 0xffff);

                if (active_layout != (IntPtr)0)
                {
                    NativeMethods.ActivateKeyboardLayout(active_layout, 0);
                }

                tid           = NativeMethods.GetCurrentThreadId();
                active_layout = NativeMethods.GetKeyboardLayout(tid);

                Log.Debug("WinCompose process layout tid:{0} handle:0x{1:X} lang:0x{2:X}",
                          tid, (uint)active_layout >> 16, (uint)active_layout & 0xffff);

                // We need to rebuild the list of dead keys
                AnalyzeLayout();
            }
        }