private async void RawInputHandler(object sender, RawKeyPressEventArgs e) { if (IsSettingKeyboard && e.KeyState == KeyPressState.Up) { Data.Types.Keyboard kbd = new Data.Types.Keyboard(); var kbdInfo = Helper.GetKeyboardInfo(e.Keyboard.HWID); kbd.Description = kbdInfo.Item1; kbd.HWID = e.Keyboard.HWID; kbd.Name = e.Keyboard.Name; kbd.Layout = kbdInfo.Item2; Variables.Config.TargetKeyboard = kbd; selectKeyboardBtn.Content = "Select"; selectKeyboardBtn.IsHitTestVisible = true; //enable button click handler currentKeyboardLbl.Content = "Keyboard: " + e.Keyboard.Name; currentKeyboardLbl.Foreground = Helper.GetFromResources <SolidColorBrush>("PrimaryForegroundAccent"); kbdInfoBtn.IsEnabled = true; IsSettingKeyboard = false; await NEHSubprocess.KillAllProcesses(); _ = StartSubprocesses(kbd); ConfigManager.StoreObject(Variables.Config, Constants.ConfigPath); } }
private async void EnabledCb_Toggled(object sender, RoutedEventArgs e) { try { trayIcon.IsHookEnabled = EnabledCb.IsChecked.Value; if (EnabledCb.IsChecked.Value) { if (string.IsNullOrEmpty(Variables.Config.TargetKeyboard.HWID)) { return; } await NEHSubprocess.KillAllProcesses(); UserSubprocess = new NEHSubprocess(false, Variables.Config.TargetKeyboard.HWID, PIPENAME); if (IsStartedAsAdmin) { AdminSubprocess = new NEHSubprocess(true, Variables.Config.TargetKeyboard.HWID, PIPENAME_ADMIN); AdminSubprocess.KeyEventRecieved += new NEHSubprocess.KeyEventRecievedHandler(KeyPressRecieved); _ = AdminSubprocess.StartProcess(); } UserSubprocess.KeyEventRecieved += new NEHSubprocess.KeyEventRecievedHandler(KeyPressRecieved); _ = UserSubprocess.StartProcess(); } else { if (UserSubprocess != null) { await UserSubprocess.StopProcess(); } if (AdminSubprocess != null) { await AdminSubprocess.StopProcess(); } UserSubprocess = null; AdminSubprocess = null; } } catch { } }