3
我想用直接輸入鍵發送鍵。我能夠發送鍵按下。但是我不知道如何發送鍵釋放,以避免保持按鍵。如何使用directInput發送發行密鑰?
這裏是我的代碼:
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,我無法使它工作
請不要在有人花時間爲您回答問題後刪除問題。 –
我是誰回答它,第一個答案是無益的:) –
啊好吧,這是公平的。我以前沒有注意到你的答案。 –