diff --git a/Hyperbar.Desktop.Contextual/ContextualCommandView.xaml b/Hyperbar.Desktop.Contextual/ContextualCommandView.xaml
index cd71865..1c78ee6 100644
--- a/Hyperbar.Desktop.Contextual/ContextualCommandView.xaml
+++ b/Hyperbar.Desktop.Contextual/ContextualCommandView.xaml
@@ -10,6 +10,6 @@
mc:Ignorable="d">
-
+
diff --git a/Hyperbar.Desktop.Contextual/ContextualCommandView.xaml.cs b/Hyperbar.Desktop.Contextual/ContextualCommandView.xaml.cs
index 7a86f81..7f3fc5e 100644
--- a/Hyperbar.Desktop.Contextual/ContextualCommandView.xaml.cs
+++ b/Hyperbar.Desktop.Contextual/ContextualCommandView.xaml.cs
@@ -1,8 +1,15 @@
+using Hyperbar.Desktop.Win32;
using Microsoft.UI.Xaml.Controls;
+using Windows.System;
namespace Hyperbar.Desktop.Contextual;
public sealed partial class ContextualCommandView : Page
{
public ContextualCommandView() => InitializeComponent();
+
+ private void Button_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
+ {
+ KeyIntrop.Type((VirtualKey)186, VirtualKey.LeftWindows);
+ }
}
diff --git a/Hyperbar.Desktop.Contextual/Hyperbar.Desktop.Contextual.csproj b/Hyperbar.Desktop.Contextual/Hyperbar.Desktop.Contextual.csproj
index 613c60d..0059503 100644
--- a/Hyperbar.Desktop.Contextual/Hyperbar.Desktop.Contextual.csproj
+++ b/Hyperbar.Desktop.Contextual/Hyperbar.Desktop.Contextual.csproj
@@ -18,6 +18,7 @@
+
diff --git a/Hyperbar.Desktop.Win32/KeyIntrop.cs b/Hyperbar.Desktop.Win32/KeyIntrop.cs
new file mode 100644
index 0000000..0a28250
--- /dev/null
+++ b/Hyperbar.Desktop.Win32/KeyIntrop.cs
@@ -0,0 +1,84 @@
+using System;
+using System.Linq;
+using System.Runtime.InteropServices;
+using Windows.System;
+using Windows.Win32;
+using Windows.Win32.UI.KeyboardAndMouseInput;
+
+namespace Hyperbar.Desktop.Win32;
+
+public class KeyIntrop
+{
+ private static readonly VirtualKey[] ExtendedKeys = [
+ VirtualKey.Menu,
+ VirtualKey.Menu,
+ VirtualKey.NumberKeyLock,
+ VirtualKey.Insert,
+ VirtualKey.Delete,
+ VirtualKey.Home,
+ VirtualKey.End,
+ VirtualKey.Up,
+ VirtualKey.Down,
+ VirtualKey.Left,
+ VirtualKey.Right,
+ VirtualKey.Application,
+ VirtualKey.RightWindows,
+ VirtualKey.LeftWindows ];
+
+ public static void Press(VirtualKey key) => SendKey(key, true);
+
+ public static void Release(VirtualKey key) => SendKey(key, false);
+
+
+ public static unsafe void Type(VirtualKey key,
+ params VirtualKey[] modifierKeys)
+ {
+ foreach (VirtualKey modiferKey in modifierKeys)
+ {
+ Press(modiferKey);
+ }
+
+ Press(key);
+ Release(key);
+
+ foreach (VirtualKey modifierKey in modifierKeys.Reverse())
+ {
+ Release(modifierKey);
+ }
+ }
+
+ private static unsafe void SendKey(VirtualKey key,
+ bool pressed)
+ {
+ INPUT input = new()
+ {
+ type = INPUT_TYPE.INPUT_KEYBOARD
+ };
+
+ input.Anonymous.ki.wVk = (ushort)key;
+ input.Anonymous.ki.wScan = (ushort)PInvoke.MapVirtualKey(input.Anonymous.ki.wVk, 0);
+
+ KEYBD_EVENT_FLAGS flags = 0;
+
+ if (input.Anonymous.ki.wScan > 0)
+ {
+ flags |= KEYBD_EVENT_FLAGS.KEYEVENTF_SCANCODE;
+ }
+
+ if (!pressed)
+ {
+ flags |= KEYBD_EVENT_FLAGS.KEYEVENTF_KEYUP;
+ }
+
+ if (ExtendedKeys.Contains(key))
+ {
+ flags |= KEYBD_EVENT_FLAGS.KEYEVENTF_EXTENDEDKEY;
+ }
+
+ input.Anonymous.ki.dwFlags = flags;
+ input.Anonymous.ki.time = 0;
+ input.Anonymous.ki.dwExtraInfo = new nuint();
+
+ PInvoke.SendInput(new Span(ref input), Marshal.SizeOf(input));
+ }
+}
diff --git a/Hyperbar.Desktop.Win32/NativeMethods.txt b/Hyperbar.Desktop.Win32/NativeMethods.txt
index c2b8722..95b59b0 100644
--- a/Hyperbar.Desktop.Win32/NativeMethods.txt
+++ b/Hyperbar.Desktop.Win32/NativeMethods.txt
@@ -54,4 +54,6 @@ DwmExtendFrameIntoClientArea
CreateRectRgn
CreateSolidBrush
FillRect
-GetDC
\ No newline at end of file
+GetDC
+SendInput
+MapVirtualKey
\ No newline at end of file
diff --git a/Hyperbar.Desktop/Views/CommandView.xaml.cs b/Hyperbar.Desktop/Views/CommandView.xaml.cs
index 36bc9e2..f80310c 100644
--- a/Hyperbar.Desktop/Views/CommandView.xaml.cs
+++ b/Hyperbar.Desktop/Views/CommandView.xaml.cs
@@ -1,8 +1,14 @@
using Microsoft.UI.Xaml.Controls;
+using Microsoft.UI.Xaml.Input;
namespace Hyperbar.Desktop;
public sealed partial class CommandView : Page
{
public CommandView() => InitializeComponent();
+
+ protected override void OnKeyDown(KeyRoutedEventArgs e)
+ {
+ base.OnKeyDown(e);
+ }
}