static void Main(string[] args) { // Check if we are debugging // if so then attach the console #if (DEBUG) int conPtr = AllocConsole(); AttachConsole(conPtr); Logger.appendLogLine("State", "Console Attached!", Logger.Type.Info); #endif ReadConfiguration(); ActiveConfig = Data.Load(ActiveConfigFile); ReloadActiveConfig(); ReloadControlScheme(); Thread tApplicationRun = new Thread(ApplicationRun); tApplicationRun.SetApartmentState(ApartmentState.STA); tApplicationRun.Start(); while (MainForm == null) { Thread.Sleep(100); } Thread tPause = new Thread(Pause); tPause.SetApartmentState(ApartmentState.STA); tPause.IsBackground = true; tPause.Start(); Thread tActivateKM = new Thread(() => { Activate.ActivateKeyboardAndMouse(); }); tActivateKM.SetApartmentState(ApartmentState.STA); tActivateKM.IsBackground = true; tActivateKM.Start(); }
static void Main(string[] args) { // Check if we are debugging // if so then attach the console #if (DEBUG) int conPtr = AllocConsole(); AttachConsole(conPtr); Logger.appendLogLine("State", "Console Attached!", Logger.Type.Info); #endif ReadConfiguration(); ActiveConfig = Data.Load(ActiveConfigFile); ReloadActiveConfig(); ReloadControlScheme(); TranslateKeyboard.LoadKeymap(); Thread tApplicationRun = new Thread(ApplicationRun); tApplicationRun.SetApartmentState(ApartmentState.STA); tApplicationRun.Start(); //XboxKeyboardMouse.Hooks.HIDHook.getInfo(); //XboxKeyboardMouse.Hooks.InterceptKeys.init(); while (MainForm == null) { Thread.Sleep(100); } MainForm.FormClosing += (sender, e) => { Activate.ShutDown(); }; Thread tPause = new Thread(Pause); tPause.SetApartmentState(ApartmentState.STA); tPause.IsBackground = true; tPause.Start(); Thread tActivateKM = new Thread(() => { Activate.ActivateKeyboardAndMouse(); }); tActivateKM.SetApartmentState(ApartmentState.STA); tActivateKM.IsBackground = true; tActivateKM.Start(); }
private static void Pause() { while (true) { var useModifier = (ActiveConfig.Controls_KB_Detach_MOD != (int)Key.None); bool detachKey = (useModifier ? Keyboard.IsKeyDown((Key)ActiveConfig.Controls_KB_Detach_MOD) && Keyboard.IsKeyDown((Key)ActiveConfig.Controls_KB_Detach_KEY) : Keyboard.IsKeyDown((Key)ActiveConfig.Controls_KB_Detach_KEY)); if (detachKey || ToggleStatusState) { if (ToggleStatusState) { ToggleStatusState = false; } bool inputDead = !Activate.tKMInput.IsAlive; bool streamDead = !Activate.tXboxStream.IsAlive; #if (DEBUG) Logger.appendLogLine("Threads", $"Threads Status: Input - {!inputDead}, Stream - {!streamDead}", Logger.Type.Debug); #endif if (!inputDead && !streamDead) { #if (DEBUG) Logger.appendLogLine("Threads", "Aborting all threads!", Logger.Type.Info); #endif try { Activate.tXboxStream.Abort(); } catch (Exception) { } try { Activate.tKMInput.Abort(); } catch (Exception) { } try { XboxStream.tMouseMovement.Abort(); } catch (Exception) { } CursorView.CursorShow(); /* * if (Activate.tKMInput.IsAlive == true && Activate.tXboxStream.IsAlive == true) { * // TODO: Handle failed threads * MessageBox.Show("Error: Threads failed to abort"); * } //*/ // Reset the controller Activate.ResetController(); MainForm.StatusStopped(); } else { // && Activate.tXboxStream.IsAlive == false if (inputDead || streamDead) { // Start the required threads Thread tActivateKM = new Thread(() => { Activate.ActivateKeyboardAndMouse(streamDead, inputDead); }); tActivateKM.SetApartmentState(ApartmentState.STA); tActivateKM.IsBackground = true; tActivateKM.Start(); } } } Thread.Sleep(100); } }