Console key detection

This commit is contained in:
Matt Thorson 2020-06-16 22:18:28 -07:00
parent ae377c7117
commit 3af854f3f0
2 changed files with 77 additions and 5 deletions

View File

@ -45,9 +45,11 @@ namespace Strawberry
}
}
static public bool Ctrl => KeyCheck(.LCtrl) || KeyCheck(.RCtrl);
static public bool Alt => KeyCheck(.LAlt) || KeyCheck(.RAlt);
static public bool Shift => KeyCheck(.LShift) || KeyCheck(.RShift);
static public bool Ctrl => SDL.GetModState() & .CTRL > 0;
static public bool Alt => SDL.GetModState() & .ALT > 0;
static public bool Shift => SDL.GetModState() & .SHIFT > 0;
static public bool CapsLock => SDL.GetModState() & .Caps > 0;
static public bool NumLock => SDL.GetModState() & .Num > 0;
static public bool KeyCheck(SDL.Scancode key)
{

View File

@ -55,20 +55,90 @@ namespace Strawberry
{
if (key >= .A && key <= .Z)
{
char8 c = 'a' + (int)(key - .A);
char8 c;
if (Input.Shift || Input.CapsLock)
c = 'A' + (int)(key - .A);
else
c = 'a' + (int)(key - .A);
entry.Append(c);
}
else if (key >= .Key1 && key <= .Key9 && !Input.Shift)
{
char8 c = '1' + (int)(key - .Key1);
entry.Append(c);
}
else
{
switch (key)
{
case .Key1 when Input.Shift:
entry.Append('!');
case .Key2 when Input.Shift:
entry.Append('@');
case .Key3 when Input.Shift:
entry.Append('#');
case .Key4 when Input.Shift:
entry.Append('$');
case .Key5 when Input.Shift:
entry.Append('%');
case .Key6 when Input.Shift:
entry.Append('^');
case .Key7 when Input.Shift:
entry.Append('&');
case .Key8 when Input.Shift:
entry.Append('*');
case .Key9 when Input.Shift:
entry.Append('(');
case .Key0 when Input.Shift:
entry.Append(')');
case .Key0:
entry.Append('0');
case .Space:
entry.Append(' ');
case .Minus when Input.Shift:
entry.Append('_');
case .Minus:
entry.Append('-');
case .Equals when Input.Shift:
entry.Append('+');
case .Equals:
entry.Append('=');
case .LeftBracket when Input.Shift:
entry.Append('{');
case .LeftBracket:
entry.Append('[');
case .RightBracket when Input.Shift:
entry.Append('}');
case .RightBracket:
entry.Append(']');
case .BackSlash when Input.Shift:
entry.Append('|');
case .BackSlash:
entry.Append('\\');
case .Semicolon when Input.Shift:
entry.Append(':');
case .Semicolon:
entry.Append(';');
case .Apostrophe when Input.Shift:
entry.Append('"');
case .Apostrophe:
entry.Append('\'');
case .Comma when Input.Shift:
entry.Append('<');
case .Comma:
entry.Append(',');
case .Period when Input.Shift:
entry.Append('>');
case .Period:
entry.Append('.');
case .Slash when Input.Shift:
entry.Append('?');
case .Slash:
entry.Append('/');
case .BackSpace:
if (entry.Length > 0)
entry.RemoveFromEnd(1);
case .Delete:
entry.Clear();