1
0
Fork 0
forked from aly/qstbak
qstbak/Questionable/Questionable.Controller.Utils/WindowsKeypress.cs
2026-01-19 08:31:23 +10:00

37 lines
942 B
C#

using System;
using System.Runtime.InteropServices;
using FFXIVClientStructs.FFXIV.Client.Graphics.Kernel;
namespace Questionable.Controller.Utils;
internal static class WindowsKeypress
{
public enum LimitedKeys
{
A = 65,
Escape = 27
}
private static class NativeMethods
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
public static extern nint SendMessage(nint hWnd, uint Msg, nint wParam, nint lParam);
}
public const uint WM_KEYUP = 257u;
public const uint WM_KEYDOWN = 256u;
public unsafe static void SendKeypress(LimitedKeys key)
{
void* hWnd = Device.Instance()->hWnd;
NativeMethods.SendMessage((nint)hWnd, 256u, (nint)key, IntPtr.Zero);
NativeMethods.SendMessage((nint)hWnd, 257u, (nint)key, IntPtr.Zero);
}
public static void SendMessage(nint hWnd, uint msg, nint key)
{
NativeMethods.SendMessage(hWnd, msg, key, IntPtr.Zero);
}
}