public static void MouseButtonsInput(SimulatedGamePadState controller) { MouseState state = mouse.GetCurrentState(); TRIGGER_LEFT_PRESSED = state.IsPressed(0); TRIGGER_RIGHT_PRESSED = state.IsPressed(1); if (state.IsPressed(0)) { controller.RightTrigger = 255; } else { if (!TranslateKeyboard.TRIGGER_RIGHT_PRESSED) { controller.RightTrigger = 0; } } if (state.IsPressed(1)) { controller.LeftTrigger = 255; } else { if (!TranslateKeyboard.TRIGGER_LEFT_PRESSED) { controller.LeftTrigger = 0; } } }
private void ControllerPreview_Load(object sender, EventArgs e) { state = SimGamePad.Instance.State[0]; axisLeft.DrawAxisDot = true; axisRight.DrawAxisDot = true; t.Interval = 1; t.Tick += T_Tick; t.Start(); }
private static void Init() { simPad = SimGamePad.Instance; try { simPad.Initialize(); simPad.PlugIn(); state = simPad.State[0]; } catch { ShutDown(); MessageBox.Show("Could not initialize SimGamePad / ScpBus. Shutting down."); Application.Exit(); } TranslateMouse.InitMouse(); }
private static void Debug_TimeTracer(SimulatedGamePadState Controller) { // Get the start time var watch = System.Diagnostics.Stopwatch.StartNew(); // Call the key input KeyInput(Controller); // Get the end time watch.Stop(); string time = watch.ElapsedMilliseconds + " MS"; if (time != "0 MS") { // Display the time Logger.appendLogLine("KeyboardInput", $"Timed @ {time}", Logger.Type.Debug); } }
private static void KeyInput(SimulatedGamePadState controller) { List <bool> btnStatus = new List <bool>(); //bool tLeft = false; //bool tRight = false; try { btnStatus.Clear(); bool mouseDisabled = Program.ActiveConfig.Mouse_Eng_Type == 4; // ------------------------------------------------------------------------------- // LEFT STICK, AXIS - X // ------------------------------------------------------------------------------- btnStatus.Clear(); foreach (KeyValuePair <Key, short> entry in mapLeftStickX) { if (entry.Key == Key.None) { continue; } bool v; if (entry.Key == Key.Escape) { v = Hooks.LowLevelKeyboardHook.EscapePressed; } else { v = Keyboard.IsKeyDown(entry.Key); } if (v) { controller.LeftStickX = entry.Value; } btnStatus.Add(v); } if (!btnStatus.Contains(true) && (mouseDisabled || Program.ActiveConfig.Mouse_Is_RightStick)) { controller.LeftStickX = 0; } // ------------------------------------------------------------------------------- // LEFT STICK, AXIS - Y // ------------------------------------------------------------------------------- btnStatus.Clear(); foreach (KeyValuePair <Key, short> entry in mapLeftStickY) { bool v; if (entry.Key == Key.Escape) { v = Hooks.LowLevelKeyboardHook.EscapePressed; } else { v = Keyboard.IsKeyDown(entry.Key); } if (v) { controller.LeftStickY = entry.Value; } btnStatus.Add(v); } if (!btnStatus.Contains(true) && (mouseDisabled || Program.ActiveConfig.Mouse_Is_RightStick)) { controller.LeftStickY = 0; } // ------------------------------------------------------------------------------- // RIGHT STICK, AXIS - X // ------------------------------------------------------------------------------- foreach (KeyValuePair <Key, short> entry in mapRightStickX) { bool v; if (entry.Key == Key.Escape) { v = Hooks.LowLevelKeyboardHook.EscapePressed; } else { v = Keyboard.IsKeyDown(entry.Key); } if (v) { controller.RightStickX = entry.Value; } btnStatus.Add(v); } if (!btnStatus.Contains(true) && (mouseDisabled || !Program.ActiveConfig.Mouse_Is_RightStick)) { controller.RightStickX = 0; } // ------------------------------------------------------------------------------- // RIGHT STICK, AXIS - Y // ------------------------------------------------------------------------------- foreach (KeyValuePair <Key, short> entry in mapRightStickY) { bool v; if (entry.Key == Key.Escape) { v = Hooks.LowLevelKeyboardHook.EscapePressed; } else { v = Keyboard.IsKeyDown(entry.Key); } if (v) { controller.RightStickY = entry.Value; } btnStatus.Add(v); } if (!btnStatus.Contains(true) && (mouseDisabled || !Program.ActiveConfig.Mouse_Is_RightStick)) { controller.RightStickY = 0; } // ------------------------------------------------------------------------------- // MISC BUTTONS // ------------------------------------------------------------------------------- foreach (KeyValuePair <Key, GamePadControl> entry in buttons) { if (entry.Key == Key.None) { continue; } bool v; if (entry.Key == Key.Escape) { v = Hooks.LowLevelKeyboardHook.EscapePressed; } else { v = Keyboard.IsKeyDown(entry.Key); } if (v) { controller.Buttons |= entry.Value; } else { controller.Buttons &= ~entry.Value; } } // ------------------------------------------------------------------------------- // TRIGGERS // ------------------------------------------------------------------------------- foreach (KeyValuePair <Key, TriggerType> entry in triggers) { if (entry.Key == Key.None) { continue; } bool v; if (entry.Key == Key.Escape) { v = Hooks.LowLevelKeyboardHook.EscapePressed; } else { v = Keyboard.IsKeyDown(entry.Key); } bool ir = entry.Value == TriggerType.RightTrigger; if (v) { if (ir) { controller.RightTrigger = 255; } else { controller.LeftTrigger = 255; } } else { if (!TranslateKeyboard.TRIGGER_RIGHT_PRESSED && ir) { controller.RightTrigger = 0; } else if (!TranslateKeyboard.TRIGGER_LEFT_PRESSED && ir) { controller.LeftTrigger = 0; } } } //if (!tLeft) controller.LeftTrigger = 0; //else if (!tRight) controller.RightTrigger = 0; } catch (Exception) { /* This occures when changing presets */ } }
public static void KeyboardInput(SimulatedGamePadState controller) => #if (DEBUG) // Only enable if you have timing issues AKA Latency on // the keyboard inputs Debug_TimeTracer(controller);
private static void KeyInput(SimulatedGamePadState controller) { List <bool> btnStatus = new List <bool>(); try { btnStatus.Clear(); bool mouseDisabled = Program.ActiveConfig.Mouse_Eng_Type == MouseTranslationMode.NONE; // ------------------------------------------------------------------------------- // STICKS // ------------------------------------------------------------------------------- if (mouseDisabled || Program.ActiveConfig.Mouse_Is_RightStick) { controller.LeftStickX = StickValueFromKeyboardState(mapLeftStickX); controller.LeftStickY = StickValueFromKeyboardState(mapLeftStickY); } if (mouseDisabled || !Program.ActiveConfig.Mouse_Is_RightStick) { controller.RightStickX = StickValueFromKeyboardState(mapRightStickX); controller.RightStickY = StickValueFromKeyboardState(mapRightStickY); } // ------------------------------------------------------------------------------- // BUTTONS // ------------------------------------------------------------------------------- foreach (var control in GamePadControls.BinaryControls) { // Explicitly set the state of every binary button we care about: If it's in our map // and the key is currently pressed, set the button to pressed, else set it to unpressed. if (AnyKeyIsPressedForControl(buttons, control)) { controller.Buttons |= control; } else { controller.Buttons &= ~control; } } // ------------------------------------------------------------------------------- // TRIGGERS // ------------------------------------------------------------------------------- foreach (KeyValuePair <Key, TriggerType> entry in triggers) { if (entry.Key == Key.None) { continue; } bool v = Keyboard.IsKeyDown(entry.Key); bool ir = entry.Value == TriggerType.RightTrigger; if (v) { if (ir) { controller.RightTrigger = 255; } else { controller.LeftTrigger = 255; } } else { if (!TranslateKeyboard.TRIGGER_RIGHT_PRESSED && ir) { controller.RightTrigger = 0; } else if (!TranslateKeyboard.TRIGGER_LEFT_PRESSED && ir) { controller.LeftTrigger = 0; } } } // ------------------------------------------------------------------------------- // CALIBRATION / RUNTIME OPTIONS // ------------------------------------------------------------------------------- // Calibration / runtime options will detect the first key-down state for their associated button, but // will ignore further iterations where the button is still being held. This can be used to advance // through calibration states, or have ways to swap configurations on the fly, etc. foreach (var option in mapRunTimeOptions.Values) { if (option.Key != Key.None && Keyboard.IsKeyDown(option.Key)) { if (!option.Ran) { option.Run(); option.Ran = true; } } else { option.Ran = false; } } } catch (Exception) { /* This occures when changing presets */ } }