/// <summary> /// Initialize this module. /// </summary> public override void Initialize() { base.Initialize(); HardwareInput = Host.Platform.GetInput(Host.Window); HardwareInput.Initialize(); HardwareInput.JoypadConnection += (obj, e) => { if (!InputStates.ContainsKey(e.Joypad)) { InputStates.Add(e.Joypad, new InputState()); } if (e.Connected) { Joypads.Add(new VirtualJoypad(InputStates?[e.Joypad], e.Joypad.Index, e.Joypad.Name)); } else { Joypads.RemoveAt(Joypads.FindIndex(x => x.Index == e.Joypad.Index)); } JoypadConnection?.Invoke(obj, e); }; InputStates.Add(HardwareKeyboard, new InputState()); InputStates.Add(HardwareMouse, new InputState()); HardwareKeyboard.OnTypeWithMods += HardwareKeyboard_OnTypeWithMods; HardwareKeyboard.OnKeyEvent += HardwareKeyboard_OnKeyEvent; HardwareKeyboard.OnType += HardwareKeyboard_OnType; HardwareMouse.OnButtonEvent += HardwareMouse_OnButtonEvent; HardwareMouse.OnScroll += HardwareMouse_OnScroll; HardwareMouse.OnMove += HardwareMouse_OnMove; foreach (var j in HardwareJoypads) { Joypads.Add(new VirtualJoypad(null, j.Index, j.Name)); } }
public override void Initialize() { base.Initialize(); JoypadConnection += (obj, e) => { if (e.Connected) { Joypads.Add(new VirtualJoypad(currentInputState?[e.Joypad], e.Joypad.Index, e.Joypad.Name)); } else { Joypads.RemoveAt(Joypads.FindIndex(x => x.Index == e.Joypad.Index)); } }; RunningLoop.Scheduler.AddDelayed(() => { while (inputHistory.Count > 0) { currentInputHistory.Clear(); inputHistory.TryDequeue(out DeviceStates state); Mouse.UpdateCurrentState(state?[Module.HardwareMouse]); Keyboard.UpdateCurrentState(state?[Module.HardwareKeyboard]); Mouse.Update(RunningLoop.Clock); Keyboard.Update(RunningLoop.Clock); foreach (var j in Joypads) { j.UpdateCurrentState(state?[Module.HardwareJoypads.Where(x => x.Index == j.Index).FirstOrDefault()]); j.Update(RunningLoop.Clock); } currentInputHistory.Add(state); } }, 0, true); }