Skip to content

Commit

Permalink
Update Kbd2Mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
nifanfa committed Apr 10, 2023
1 parent 218da02 commit be3fed5
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Kernel/Driver/PS2Keyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public static void ProcessKey(byte b)
}

Keyboard.InvokeOnKeyChanged(Keyboard.KeyInfo);

//This is for some kind of PC that have PS2 emulation but doesn't have PS2 mouse emulation
Kbd2Mouse.OnKeyChanged(Keyboard.KeyInfo);
}

private static void SetIfKeyModifier(byte scanCode, byte pressedScanCode, ConsoleModifiers modifier)
Expand Down
62 changes: 62 additions & 0 deletions Kernel/Kbd2Mouse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Diagnostics;
using System.Windows.Forms;

namespace MOOS
{
internal static class Kbd2Mouse
{
static bool up = false, down = false, left = false, right = false, f1 = false, f2 = false;

internal static void OnKeyChanged(ConsoleKeyInfo keyInfo)
{
const int ratio = 10;

if (keyInfo.Key == ConsoleKey.Up)
up = keyInfo.KeyState == ConsoleKeyState.Pressed;
if (keyInfo.Key == ConsoleKey.Down)
down = keyInfo.KeyState == ConsoleKeyState.Pressed;
if (keyInfo.Key == ConsoleKey.Left)
left = keyInfo.KeyState == ConsoleKeyState.Pressed;
if (keyInfo.Key == ConsoleKey.Right)
right = keyInfo.KeyState == ConsoleKeyState.Pressed;

//Console.WriteLine($"{up},{down},{left},{right}");

if (
keyInfo.Key == ConsoleKey.Up ||
keyInfo.Key == ConsoleKey.Down ||
keyInfo.Key == ConsoleKey.Left ||
keyInfo.Key == ConsoleKey.Right
)
{
int axisX = 0, axisY = 0;
if (left)
axisX -= ratio;
if (right)
axisX += ratio;
if (up)
axisY -= ratio;
if (down)
axisY += ratio;

Control.MousePosition.X = Math.Clamp(Control.MousePosition.X + axisX, 0, Framebuffer.Width);
Control.MousePosition.Y = Math.Clamp(Control.MousePosition.Y + axisY, 0, Framebuffer.Height);
}

if (keyInfo.Key == ConsoleKey.F1)
f1 = keyInfo.KeyState == ConsoleKeyState.Pressed;
if (keyInfo.Key == ConsoleKey.F2)
f2 = keyInfo.KeyState == ConsoleKeyState.Pressed;

if (f1)
Control.MouseButtons |= MouseButtons.Left;
else
Control.MouseButtons &= ~MouseButtons.Left;
if (f2)
Control.MouseButtons |= MouseButtons.Right;
else
Control.MouseButtons &= ~MouseButtons.Right;
}
}
}
1 change: 1 addition & 0 deletions Kernel/Kernel.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<Compile Include="$(MSBuildThisFileDirectory)FS\TarFS.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Graph\Graphics.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Graph\VMWareSVGAIIGraphics.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Kbd2Mouse.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Misc\Allocator.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Misc\ASC16.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Misc\Audio.cs" />
Expand Down

0 comments on commit be3fed5

Please sign in to comment.