Skip to content

Commit

Permalink
actually send keycodes for arrow/function/etc keys
Browse files Browse the repository at this point in the history
  • Loading branch information
doubleyewdee committed Nov 24, 2018
1 parent 2b70797 commit 7397d78
Showing 1 changed file with 110 additions and 2 deletions.
112 changes: 110 additions & 2 deletions src/condo/KeyHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace condo
namespace condo
{
using ConsoleBuffer;
using System.Text;
Expand Down Expand Up @@ -42,7 +42,115 @@ public void OnTextInput(object sender, TextCompositionEventArgs e)

public void OnKeyDown(object sender, KeyEventArgs e)
{
// XXX: codeme.
// XXX: need to figure out how to handle DECKP*M rebinds. too lazy atm.
// XXX2: might need to pass alt state for various function/etc keys?
e.Handled = true;
switch (e.Key)
{
case Key.Up:
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
{
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[1;5A"), false, true);
}
else
{
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[A"), false, false);
}
break;
case Key.Down:
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
{
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[1;5B"), false, true);
}
else
{
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[B"), false, false);
}
break;
case Key.Right:
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
{
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[1;5C"), false, true);
}
else
{
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[C"), false, false);
}
break;
case Key.Left:
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
{
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[1;5D"), false, true);
}
else
{
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[D"), false, false);
}
break;
case Key.Home:
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[H"), false, false);
break;
case Key.End:
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[F"), false, false);
break;
case Key.Back:
this.console.SendText(new byte[] { 0x7f }, false, false);
break;
case Key.Escape:
this.console.SendText(new byte[] { 0x1b }, false, false);
break;
case Key.Insert:
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[2~"), false, false);
break;
case Key.Delete:
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[3~"), false, false);
break;
case Key.PageUp:
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[5~"), false, false);
break;
case Key.PageDown:
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[6~"), false, false);
break;
case Key.F1:
this.console.SendText(Encoding.UTF8.GetBytes("\x1bOP"), false, false);
break;
case Key.F2:
this.console.SendText(Encoding.UTF8.GetBytes("\x1bOQ"), false, false);
break;
case Key.F3:
this.console.SendText(Encoding.UTF8.GetBytes("\x1bOR"), false, false);
break;
case Key.F4:
this.console.SendText(Encoding.UTF8.GetBytes("\x1bOS"), false, false);
break;
case Key.F5:
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[15~"), false, false);
break;
case Key.F6:
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[17~"), false, false);
break;
case Key.F7:
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[18~"), false, false);
break;
case Key.F8:
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[19~"), false, false);
break;
case Key.F9:
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[20~"), false, false);
break;
case Key.F10:
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[21~"), false, false);
break;
case Key.F11:
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[23~"), false, false);
break;
case Key.F12:
this.console.SendText(Encoding.UTF8.GetBytes("\x1b[24~"), false, false);
break;
default:
e.Handled = false; // just kidding 🙃
break;
}
}
}
}

0 comments on commit 7397d78

Please sign in to comment.