public SEBInputLanguageToolStripButton() { this.Alignment = ToolStripItemAlignment.Right; this.ForeColor = Color.Black; this.Font = new Font("Arial", (float)this.FontSize, FontStyle.Bold); try { this.currentIndex = InputLanguage.InstalledInputLanguages.IndexOf(InputLanguage.CurrentInputLanguage); if (InputLanguage.InstalledInputLanguages.Count < 2) { throw new NotSupportedException("There is only one keyboard layout available"); } SEBWindowHandler.ForegroundWatchDog.OnForegroundWindowChanged += (ForegroundWatchDog.ForegroundWindowChangedEventHandler)(handle => this.SetKeyboardLayoutAccordingToIndex()); this.languages = new IntPtr[InputLanguage.InstalledInputLanguages.Count]; for (int index = 0; index < InputLanguage.InstalledInputLanguages.Count; ++index) { this.languages[index] = SEBInputLanguageToolStripButton.LoadKeyboardLayout(InputLanguage.InstalledInputLanguages[index].Culture.KeyboardLayoutId.ToString("X8"), 1U); } this.timer = new Timer(); this.timer.Tick += (EventHandler)((x, y) => this.UpdateDisplayText()); this.timer.Interval = 1000; this.timer.Start(); } catch (Exception ex) { this.Enabled = false; this.UpdateDisplayText(); } }
private void SetKeyboardLayoutAccordingToIndex() { try { InputLanguage.CurrentInputLanguage = InputLanguage.InstalledInputLanguages[this.currentIndex]; if ((long)this.languages[this.currentIndex].ToInt32() != (long)SEBInputLanguageToolStripButton.GetKeyboardLayout(SEBInputLanguageToolStripButton.GetWindowThreadProcessId(SEBWindowHandler.GetForegroundWindow(), IntPtr.Zero))) { SEBInputLanguageToolStripButton.PostMessage(SEBWindowHandler.GetForegroundWindow(), 80U, IntPtr.Zero, this.languages[this.currentIndex]); } } catch (Exception ex) { Logger.AddError("Could not change InputLanguage", (object)this, ex, (string)null); } this.UpdateDisplayText(); }