-> Fix the KeyMap to use Windows.Form.Keys

-> Added code for key down/up
-> DRY mouse button code
master
Zaafar Ahmed 7 years ago
parent c8a82072e7
commit 06a73fc042
  1. 164
      ClickableTransparentOverlay/HookController.cs
  2. 41
      ClickableTransparentOverlay/ImGuiController.cs
  3. 14
      DriverProgram/Program.cs

@ -49,52 +49,31 @@
Enable = true;
}
private void _hook_MouseWheelExt(object sender, MouseEventExtArgs e)
{
if (!Enable)
{
return;
}
ImGuiIOPtr io = ImGui.GetIO();
if (io.WantCaptureMouse)
{
io.MouseWheel = e.Delta / SystemInformation.MouseWheelScrollDelta;
e.Handled = true;
}
}
private void _hook_MouseUpExt(object sender, MouseEventExtArgs e)
private void MouseButtonFunction(MouseEventExtArgs e, bool isDownEvent)
{
if (!Enable)
{
return;
}
ImGuiIOPtr io = ImGui.GetIO();
switch (e.Button)
{
case MouseButtons.Left:
io.MouseDown[0] = false;
break;
case MouseButtons.None:
// TODO: Find out what does this None mean
io.MouseDown[0] = isDownEvent;
break;
case MouseButtons.Right:
io.MouseDown[1] = false;
io.MouseDown[1] = isDownEvent;
break;
case MouseButtons.Middle:
io.MouseDown[2] = false;
io.MouseDown[2] = isDownEvent;
break;
case MouseButtons.XButton1:
io.MouseDown[3] = false;
io.MouseDown[3] = isDownEvent;
break;
case MouseButtons.XButton2:
io.MouseDown[4] = false;
io.MouseDown[4] = isDownEvent;
break;
case MouseButtons.None:
// TODO: Find out what does this None mean
break;
default:
// Make a Logger for the whole Overlay
// TODO: Make a Logger for the whole Overlay
break;
}
@ -104,6 +83,22 @@
}
}
private void _hook_MouseUpExt(object sender, MouseEventExtArgs e)
{
if (Enable)
{
MouseButtonFunction(e, false);
}
}
private void _hook_MouseDownExt(object sender, MouseEventExtArgs e)
{
if (Enable)
{
MouseButtonFunction(e, true);
}
}
private void _hook_MouseMove(object sender, MouseEventArgs e)
{
if (!Enable)
@ -118,7 +113,7 @@
// Window32 API ShowCursor(false)
}
private void _hook_MouseDownExt(object sender, MouseEventExtArgs e)
private void _hook_MouseWheelExt(object sender, MouseEventExtArgs e)
{
if (!Enable)
{
@ -128,33 +123,81 @@
ImGuiIOPtr io = ImGui.GetIO();
if (io.WantCaptureMouse)
{
switch (e.Button)
{
case MouseButtons.Left:
io.MouseDown[0] = true;
io.MouseWheel = e.Delta / SystemInformation.MouseWheelScrollDelta;
e.Handled = true;
}
}
private void _hook_KeyUp(object sender, KeyEventArgs e)
{
var io = ImGui.GetIO();
io.KeysDown[e.KeyValue] = false;
switch (e.KeyCode)
{
case Keys.LWin:
case Keys.RWin:
io.KeySuper = false;
break;
case MouseButtons.Right:
io.MouseDown[1] = true;
e.Handled = true;
case Keys.LControlKey:
case Keys.RControlKey:
io.KeyCtrl = false;
break;
case MouseButtons.Middle:
io.MouseDown[2] = true;
e.Handled = true;
case Keys.LMenu:
case Keys.RMenu:
io.KeyAlt = false;
break;
case MouseButtons.XButton1:
io.MouseDown[3] = true;
e.Handled = true;
case Keys.LShiftKey:
case Keys.RShiftKey:
io.KeyShift = false;
break;
case MouseButtons.XButton2:
io.MouseDown[4] = true;
default:
break;
}
}
private void _hook_KeyDown(object sender, KeyEventArgs e)
{
if (!Enable)
{
return;
}
var io = ImGui.GetIO();
if (io.WantCaptureKeyboard)
{
io.KeysDown[e.KeyValue] = true;
switch (e.KeyCode)
{
case Keys.LWin:
case Keys.RWin:
io.KeySuper = true;
break;
case Keys.LControlKey:
case Keys.RControlKey:
io.KeyCtrl = true;
e.Handled = true;
break;
case MouseButtons.None:
// TODO: Find out what does this None mean
case Keys.LMenu:
case Keys.RMenu:
io.KeyAlt = true;
break;
// Alt is LMenu/RMenu
case Keys.LShiftKey:
case Keys.RShiftKey:
io.KeyShift = true;
break;
default:
// TODO: Make a Logger for the whole Overlay
// Ignoring ALT key so we can do ALT+TAB or ALT+F4 etc.
// Not sure if ImGUI needs to use ALT+XXX key for anything.
// Ignoring Capital/NumLock key so Windows can use it
// Ignoring Win/Super key so we can do Win+D or other stuff
if (!io.KeyAlt && e.KeyCode != Keys.Capital && e.KeyCode != Keys.NumLock && !io.KeySuper)
{
e.Handled = true;
}
break;
}
}
@ -169,8 +212,13 @@
var io = ImGui.GetIO();
if (io.KeyAlt) // Ignoring ALT key so we can do ALT+TAB or ALT+F4 etc. Not sure if ImGUI uses ALT key in anyway.
// Ignoring Win/Super key so we can do Win+D or other stuff
// Ignoring ALT key so we can do ALT+TAB or ALT+F4 etc.
// Not sure if ImGUI needs to use ALT+XXX or Super+XXX key for anything.
if (io.KeySuper || io.KeyAlt)
{
return;
}
if (io.WantTextInput || io.WantCaptureKeyboard)
{
@ -179,20 +227,6 @@
}
}
private void _hook_KeyUp(object sender, KeyEventArgs e)
{
// TODO:
}
private void _hook_KeyDown(object sender, KeyEventArgs e)
{
if (!Enable)
{
return;
}
// TODO:
}
public void Dispose()
{
_hook.KeyDown -= _hook_KeyDown;

@ -325,25 +325,28 @@
private static void SetKeyMappings()
{
ImGuiIOPtr io = ImGui.GetIO();
io.KeyMap[(int)ImGuiKey.Tab] = (int)Key.Tab;
io.KeyMap[(int)ImGuiKey.LeftArrow] = (int)Key.Left;
io.KeyMap[(int)ImGuiKey.RightArrow] = (int)Key.Right;
io.KeyMap[(int)ImGuiKey.UpArrow] = (int)Key.Up;
io.KeyMap[(int)ImGuiKey.DownArrow] = (int)Key.Down;
io.KeyMap[(int)ImGuiKey.PageUp] = (int)Key.PageUp;
io.KeyMap[(int)ImGuiKey.PageDown] = (int)Key.PageDown;
io.KeyMap[(int)ImGuiKey.Home] = (int)Key.Home;
io.KeyMap[(int)ImGuiKey.End] = (int)Key.End;
io.KeyMap[(int)ImGuiKey.Delete] = (int)Key.Delete;
io.KeyMap[(int)ImGuiKey.Backspace] = (int)Key.BackSpace;
io.KeyMap[(int)ImGuiKey.Enter] = (int)Key.Enter;
io.KeyMap[(int)ImGuiKey.Escape] = (int)Key.Escape;
io.KeyMap[(int)ImGuiKey.A] = (int)Key.A;
io.KeyMap[(int)ImGuiKey.C] = (int)Key.C;
io.KeyMap[(int)ImGuiKey.V] = (int)Key.V;
io.KeyMap[(int)ImGuiKey.X] = (int)Key.X;
io.KeyMap[(int)ImGuiKey.Y] = (int)Key.Y;
io.KeyMap[(int)ImGuiKey.Z] = (int)Key.Z;
io.KeyMap[(int)ImGuiKey.Tab] = (int)System.Windows.Forms.Keys.Tab;
io.KeyMap[(int)ImGuiKey.LeftArrow] = (int)System.Windows.Forms.Keys.Left;
io.KeyMap[(int)ImGuiKey.RightArrow] = (int)System.Windows.Forms.Keys.Right;
io.KeyMap[(int)ImGuiKey.UpArrow] = (int)System.Windows.Forms.Keys.Up;
io.KeyMap[(int)ImGuiKey.DownArrow] = (int)System.Windows.Forms.Keys.Down;
io.KeyMap[(int)ImGuiKey.PageUp] = (int)System.Windows.Forms.Keys.PageUp;
io.KeyMap[(int)ImGuiKey.PageDown] = (int)System.Windows.Forms.Keys.PageDown;
io.KeyMap[(int)ImGuiKey.Home] = (int)System.Windows.Forms.Keys.Home;
io.KeyMap[(int)ImGuiKey.End] = (int)System.Windows.Forms.Keys.End;
io.KeyMap[(int)ImGuiKey.Delete] = (int)System.Windows.Forms.Keys.Delete;
io.KeyMap[(int)ImGuiKey.Backspace] = (int)System.Windows.Forms.Keys.Back;
io.KeyMap[(int)ImGuiKey.Enter] = (int)System.Windows.Forms.Keys.Enter;
io.KeyMap[(int)ImGuiKey.Escape] = (int)System.Windows.Forms.Keys.Escape;
//io.KeyMap[(int)ImGuiKey.COUNT] = (int)System.Windows.Forms.Keys.un;
io.KeyMap[(int)ImGuiKey.Insert] = (int)System.Windows.Forms.Keys.Insert;
io.KeyMap[(int)ImGuiKey.Space] = (int)System.Windows.Forms.Keys.Space;
io.KeyMap[(int)ImGuiKey.A] = (int)System.Windows.Forms.Keys.A;
io.KeyMap[(int)ImGuiKey.C] = (int)System.Windows.Forms.Keys.C;
io.KeyMap[(int)ImGuiKey.V] = (int)System.Windows.Forms.Keys.V;
io.KeyMap[(int)ImGuiKey.X] = (int)System.Windows.Forms.Keys.X;
io.KeyMap[(int)ImGuiKey.Y] = (int)System.Windows.Forms.Keys.Y;
io.KeyMap[(int)ImGuiKey.Z] = (int)System.Windows.Forms.Keys.Z;
}
private void RenderImDrawData(ImDrawDataPtr draw_data, GraphicsDevice gd, CommandList cl)

@ -29,13 +29,13 @@
public static void DistroyDemo()
{
Thread.Sleep(10000);
demo.ResizeWindow(0, 0, 2560, 1440);
Thread.Sleep(10000);
demo.HideWindow();
Thread.Sleep(10000);
demo.ShowWindow();
Thread.Sleep(10000);
Thread.Sleep(100000);
//demo.ResizeWindow(0, 0, 2560, 1440);
//Thread.Sleep(10000);
//demo.HideWindow();
//Thread.Sleep(10000);
//demo.ShowWindow();
//Thread.Sleep(10000);
demo.Dispose();
}
}

Loading…
Cancel
Save