-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace AutoHook.Utils; | ||
|
||
internal static class InputUtil | ||
{ | ||
private const uint WM_KEYUP = 0x101; | ||
private const uint WM_KEYDOWN = 0x100; | ||
|
||
[DllImport("user32.dll", CharSet = CharSet.Unicode)] | ||
private static extern IntPtr FindWindowEx(IntPtr hWndParent, IntPtr hWndChildAfter, string lpszClass, string? lpszWindow); | ||
|
||
[DllImport("user32.dll")] | ||
private static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId); | ||
|
||
[DllImport("user32.dll")] | ||
private static extern IntPtr SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam); | ||
|
||
public static bool TryFindGameWindow(out IntPtr hwnd) | ||
{ | ||
hwnd = IntPtr.Zero; | ||
while (true) | ||
{ | ||
hwnd = FindWindowEx(IntPtr.Zero, hwnd, "FFXIVGAME", null); | ||
if (hwnd == IntPtr.Zero) break; | ||
GetWindowThreadProcessId(hwnd, out var pid); | ||
if (pid == Process.GetCurrentProcess().Id) break; | ||
} | ||
return hwnd != IntPtr.Zero; | ||
} | ||
|
||
public static void SendKeycode(IntPtr hwnd, int keycode) | ||
{ | ||
SendMessage(hwnd, WM_KEYDOWN, (IntPtr)keycode, (IntPtr)0); | ||
SendMessage(hwnd, WM_KEYUP, (IntPtr)keycode, (IntPtr)0); | ||
} | ||
} |