Remapped interrupt to CTRL + ALT + C. Added reboot keycombo by pressing CTRL + ALT + INS

This commit is contained in:
Alessandro Proto 2023-01-16 18:27:33 +01:00
parent 5f8f946c29
commit a652992861
2 changed files with 53 additions and 7 deletions

View file

@ -3,6 +3,8 @@ using Capy64.Eventing;
using Capy64.Eventing.Events; using Capy64.Eventing.Events;
using Capy64.LuaRuntime; using Capy64.LuaRuntime;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using System.Linq;
using static Capy64.Eventing.InputManager;
namespace Capy64.BIOS; namespace Capy64.BIOS;
@ -10,6 +12,8 @@ internal class RuntimeInputEvents
{ {
private EventEmitter _eventEmitter; private EventEmitter _eventEmitter;
private Runtime _runtime; private Runtime _runtime;
private const int rebootDelay = 30;
private int heldReboot = 0;
public RuntimeInputEvents(EventEmitter eventEmitter, Runtime runtime) public RuntimeInputEvents(EventEmitter eventEmitter, Runtime runtime)
{ {
@ -27,6 +31,8 @@ internal class RuntimeInputEvents
_eventEmitter.OnKeyUp += OnKeyUp; _eventEmitter.OnKeyUp += OnKeyUp;
_eventEmitter.OnKeyDown += OnKeyDown; _eventEmitter.OnKeyDown += OnKeyDown;
_eventEmitter.OnChar += OnChar; _eventEmitter.OnChar += OnChar;
_eventEmitter.OnTick += OnTick;
} }
public void Unregister() public void Unregister()
@ -39,6 +45,37 @@ internal class RuntimeInputEvents
_eventEmitter.OnKeyUp -= OnKeyUp; _eventEmitter.OnKeyUp -= OnKeyUp;
_eventEmitter.OnKeyDown -= OnKeyDown; _eventEmitter.OnKeyDown -= OnKeyDown;
_eventEmitter.OnChar -= OnChar; _eventEmitter.OnChar -= OnChar;
_eventEmitter.OnTick -= OnTick;
}
private static Keys[] rebootKeys = new[]
{
Keys.Insert,
Keys.LeftAlt, Keys.RightAlt,
Keys.LeftControl, Keys.RightControl,
};
private void OnTick(object sender, TickEvent e)
{
var keyState = Keyboard.GetState();
var pressedKeys = keyState.GetPressedKeys();
if ((pressedKeys.Contains(Keys.LeftControl) || pressedKeys.Contains(Keys.RightControl))
&& (pressedKeys.Contains(Keys.LeftAlt) || pressedKeys.Contains(Keys.RightAlt))
&& pressedKeys.Contains(Keys.Insert))
{
heldReboot++;
}
else
{
heldReboot = 0;
}
if (heldReboot >= rebootDelay)
{
heldReboot = 0;
Bios.Reboot();
}
} }
private void OnMouseUp(object sender, MouseButtonEvent e) private void OnMouseUp(object sender, MouseButtonEvent e)
@ -99,7 +136,9 @@ internal class RuntimeInputEvents
e.IsHeld, e.IsHeld,
}); });
if (e.Mods.HasFlag(InputManager.Modifiers.LCtrl) || (e.Mods.HasFlag(InputManager.Modifiers.RCtrl) && !e.IsHeld)) if ((e.Mods & Modifiers.Ctrl) != Modifiers.None && !e.IsHeld)
{
if ((e.Mods & Modifiers.Alt) != Modifiers.None)
{ {
if (e.Key == Keys.C) if (e.Key == Keys.C)
{ {
@ -110,6 +149,7 @@ internal class RuntimeInputEvents
BypassFilter = true, BypassFilter = true,
}); });
} }
}
else if (e.Key == Keys.V) else if (e.Key == Keys.V)
{ {
if (SDL.HasClipboardText()) if (SDL.HasClipboardText())

View file

@ -21,6 +21,8 @@ public class InputManager
[Flags] [Flags]
public enum Modifiers public enum Modifiers
{ {
None = 0,
LShift = 1, LShift = 1,
RShift = 2, RShift = 2,
@ -29,6 +31,10 @@ public class InputManager
LCtrl = 16, LCtrl = 16,
RCtrl = 32, RCtrl = 32,
Shift = LShift | RShift,
Alt = LAlt | RAlt,
Ctrl = LCtrl | RCtrl,
} }
private static Keys[] IgnoredTextInputKeys = private static Keys[] IgnoredTextInputKeys =