gpt4 book ai didi

c# - 如何使用 directInput 发送释放 key ?

转载 作者:行者123 更新时间:2023-11-30 17:09:31 25 4
gpt4 key购买 nike

<分区>

我想使用直接输入发送按键。我能够发送按键。但是我不知道如何发送按键释放以避免一直按下按键。

这是我的代码:

struct INPUT
{
public UInt32 type;
public ushort wVk;
public ushort wScan;
public UInt32 dwFlags;
public UInt32 time;
public UIntPtr dwExtraInfo;
public UInt32 uMsg;
public ushort wParamL;
public ushort wParamH;

}

enum SendInputFlags
{
KEYEVENTF_EXTENDEDKEY = 0x0001,
KEYEVENTF_KEYUP = 0x0002,
KEYEVENTF_UNICODE = 0x0004,
KEYEVENTF_SCANCODE = 0x0008,
}

[DllImport("user32.dll")]
static extern UInt32 SendInput(UInt32 nInputs,
[MarshalAs(UnmanagedType.LPArray, SizeConst = 1)] INPUT[] pInputs,
Int32 cbSize);

public static void StrokeW()
{
INPUT[] InputData = new INPUT[1];
ushort ScanCode = 0x11;
InputData[0].type = 1;
InputData[0].wScan = (ushort)ScanCode;
InputData[0].dwFlags = (uint)SendInputFlags.KEYEVENTF_SCANCODE;
SendInput(1, InputData, Marshal.SizeOf(InputData[0]));
}

注意:我试过这个 Simulating Keyboard with SendInput API in DirectInput applications而且我无法让它工作

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com