private static void ShowAndFreeCursor() { CursorView.CursorShow(); if (tMouseMovement != null) { tMouseMovement.Abort(); } }
private static void LockAndHideCursor() { CursorView.CursorHide(); tMouseMovement = new Thread(TranslateMouse.MouseMovementInput); tMouseMovement.SetApartmentState(ApartmentState.STA); tMouseMovement.IsBackground = true; tMouseMovement.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) { if (Activate.tKMInput.IsAlive == true && Activate.tXboxStream.IsAlive == true) { Activate.tXboxStream.Abort(); Activate.tKMInput.Abort(); 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"); //} //else { // Reset the controller Activate.ResetController(); mainform.StatusStopped(); //} } else if (Activate.tKMInput.IsAlive == false && Activate.tXboxStream.IsAlive == false) { Thread tActivateKM = new Thread(Activate.ActivateKeyboardAndMouse); tActivateKM.SetApartmentState(ApartmentState.STA); tActivateKM.IsBackground = true; tActivateKM.Start(); } } Thread.Sleep(100); } }
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); } }