Skip to content

Commit

Permalink
Fix wrong virtual key value when calling WinAPI.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinyfish committed Jun 23, 2024
1 parent ba4d48d commit 04a531c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void SetHotkeyGroup()
if (stratagem == null)
continue;

hotkeys[_keys[i]] = (_, _) =>
hotkeys[_keys[i]] = (_, e) =>
{
if (Settings.PlayVoice)
PlayStratagemVoice(stratagem.Name);
Expand Down
11 changes: 7 additions & 4 deletions Tools/SendKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,24 @@ public static class SendKey

public static void Down(Key key)
{
keybd_event((byte)key, 0, KEYEVENTF_KEYDOWN, 0);
var vk = KeyInterop.VirtualKeyFromKey(key);
keybd_event((byte)vk, 0, KEYEVENTF_KEYDOWN, 0);
Thread.Sleep(50);
}

public static void Up(Key key)
{
keybd_event((byte)key, 0, KEYEVENTF_KEYUP, 0);
var vk = KeyInterop.VirtualKeyFromKey(key);
keybd_event((byte)vk, 0, KEYEVENTF_KEYUP, 0);
Thread.Sleep(40);
}

public static void Press(Key key)
{
keybd_event((byte)key, 0, KEYEVENTF_KEYDOWN, 0);
var vk = KeyInterop.VirtualKeyFromKey(key);
keybd_event((byte)vk, 0, KEYEVENTF_KEYDOWN, 0);
Thread.Sleep(30);
keybd_event((byte)key, 0, KEYEVENTF_KEYUP, 0);
keybd_event((byte)vk, 0, KEYEVENTF_KEYUP, 0);
Thread.Sleep(40);
}
}

0 comments on commit 04a531c

Please sign in to comment.