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(); }
private static void MouseMovement_Raw_S() { Point mouse = Control.MousePosition; short joyX = 0; short joyY = 0; double x = Program.ActiveConfig.Mouse_Invert_X ? centered.X - mouse.X : mouse.X - centered.X; double y = Program.ActiveConfig.Mouse_Invert_Y ? mouse.Y - centered.Y : centered.Y - mouse.Y; x = x * Program.ActiveConfig.Mouse_Sensitivity_X; y = y * Program.ActiveConfig.Mouse_Sensitivity_Y; if (x > short.MaxValue) { x = short.MaxValue; } else if (x < short.MinValue) { x = short.MinValue; } if (y > short.MaxValue) { y = short.MaxValue; } else if (y < short.MinValue) { y = short.MinValue; } // Lets just first time apply raw values // to the sticks joyX = (short)x; joyY = (short)y; #if (DEBUG) PrintVals(joyX, joyY); #endif Activate.Controller.RightStickX = joyX; Activate.Controller.RightStickY = joyY; Activate.SendtoController(Activate.Controller); Cursor.Position = centered; }
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 SetAxis(short x, short y) { #if (DEBUG) //Logger.appendLogLine("Mouse", $"Mouse (X, Y) = ({x.ToString().PadRight(6, ' ')}, {y.ToString().PadRight(6, ' ')})", Logger.Type.Controller); #endif if (Program.ActiveConfig.Mouse_Is_RightStick) { Activate.Controller.RightStickX = x; Activate.Controller.RightStickY = y; } else { Activate.Controller.LeftStickX = x; Activate.Controller.LeftStickY = y; } Activate.SendtoController(Activate.Controller); }
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); } }
private static void MouseMovement_Default() { Point mouse = Control.MousePosition; short joyX; short joyY; // // I need to find a way to make this // more efficent. // // How it works, its a simple concept that // killed my brain because i suck at maths // somehow? // // We want to get the percentage of the mouse // from the center and we use that value to // get the value of (mouse)% in Short.MaxValue, // this gives us a relative value for the joysticks // // So in kinda laymans code terms: // let Percentage = % of Mouse from Center // - This is the % of the mouse from the center // of the screen, this allows us to make it // relative to the joystick // Percentage = Percentage + (Percentage * Sensitivity) // let JoystickAXI = Calculate Value of (% of Max Short) // set Xbox.Joysticks.AXI = JoystickAXI // // How it works past that, not even i know. // How well it works? Try it for your self its not perfect but it'll do. /* Calculate Joystick X */ { double x; if (Program.ActiveConfig.Mouse_Invert_X) { x = centered.X - mouse.X; } else { x = mouse.X - centered.X; } double max = (Screen.PrimaryScreen.Bounds.Width / 4) * 1.5; double current = x + (x * Program.ActiveConfig.Mouse_Sensitivity_X); double percentage = (current / max) * Program.ActiveConfig.Mouse_FinalMod; double number = iMax; double final = number * percentage / 100; if (final >= iMax && final > 0) { final = iMax; } else if (final <= iMin && final < 0) { final = iMin; } joyX = Convert.ToInt16(final); } /* Calculate Joystick Y */ { double y; if (Program.ActiveConfig.Mouse_Invert_Y) { y = mouse.Y - centered.Y; } else { y = centered.Y - mouse.Y; } double max = Screen.PrimaryScreen.Bounds.Height / 2; double current = y + (y * Program.ActiveConfig.Mouse_Sensitivity_Y); double percentage = (current / max) * Program.ActiveConfig.Mouse_FinalMod; double number = iMax; double final = number * percentage / 100; if (final >= iMax && final > 0) { final = iMax; } else if (final <= iMin && final < 0) { final = iMin; } joyY = Convert.ToInt16(final); } //PrintVals(joyX, joyY); Activate.Controller.RightStickX = joyX; Activate.Controller.RightStickY = joyY; Activate.SendtoController(Activate.Controller); Cursor.Position = centered; }
private static void MouseMovement_Relative() { Point mouse = Control.MousePosition; short joyX = Activate.Controller.RightStickX; short joyY = Activate.Controller.RightStickY; /* * The idea is to do this * just increment the current JOY X and Y by using * translated values from the mouse's X and Y new positions * same as above/default but instead we are incrementing position * and decrementing rather than just setting */ /* Calculate Joystick X */ { double x; if (Program.ActiveConfig.Mouse_Invert_X) { x = centered.X - mouse.X; } else { x = mouse.X - centered.X; } double max = (Screen.PrimaryScreen.Bounds.Width / 4) * 1.5; double current = x + (x * Program.ActiveConfig.Mouse_Sensitivity_X); double percentage = (current / max) * Program.ActiveConfig.Mouse_FinalMod; double number = iMax; double final = number * percentage / 100; if (final >= iMax && final > 0) { final = iMax; } else if (final <= iMin && final < 0) { final = iMin; } short tJoyX = Convert.ToInt16(final); joyX += tJoyX; } /* Calculate Joystick Y */ { double y; if (Program.ActiveConfig.Mouse_Invert_Y) { y = mouse.Y - centered.Y; } else { y = centered.Y - mouse.Y; } double max = Screen.PrimaryScreen.Bounds.Height / 2; double current = y + (y * Program.ActiveConfig.Mouse_Sensitivity_Y); double percentage = (current / max) * Program.ActiveConfig.Mouse_FinalMod; double number = iMax; double final = number * percentage / 100; if (final >= iMax && final > 0) { final = iMax; } else if (final <= iMin && final < 0) { final = iMin; } short TJoyY = Convert.ToInt16(final); joyY += TJoyY; } Activate.Controller.RightStickX = joyX; Activate.Controller.RightStickY = joyY; Activate.SendtoController(Activate.Controller); Cursor.Position = centered; }