forked from aly/qstbak
37 lines
942 B
C#
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);
|
|
}
|
|
}
|