110,566
社区成员
发帖
与我相关
我的任务
分享
[StructLayout(LayoutKind.Sequential)]
public struct KEYBDINPUT
{
public Int16 wVk;
public Int16 wScan;
public Int32 dwFlags;
public Int32 time;
public IntPtr dwExtraInfo;
}
[StructLayout(LayoutKind.Sequential)]
public struct KEYBDINPUT
{
public int wVk;
public int wScan;
public Int32 dwFlags;
public Int32 time;
public IntPtr dwExtraInfo;
}
private void button1_Click_1(object sender, EventArgs e)
{
INPUT[] inDow = new INPUT[4];
int i = 0;
while (i < inDow.Length)
{
inDow[i] = new INPUT();
inDow[i++].type = INPUT_KEYBOARD;
}
inDow[0].ki.wVk = inDow[3].ki.wVk = (int)Keys.LMenu;
inDow[1].ki.wVk = inDow[2].ki.wVk = (int)Keys.E;
inDow[2].ki.dwFlags = inDow[3].ki.dwFlags = KEYEVENTF_KEYUP;
this.Text = API.SendInput(6,inDow, Marshal.SizeOf(inDow[0])).ToString();
}
[DllImport("user32.dll")]
public static extern UInt32 SendInput(UInt32 nInputs, INPUT[] pInputs, int cbSize);
[DllImport("kernel32.dll")]
public static extern int GetTickCount();
[StructLayout(LayoutKind.Explicit)]
public struct INPUT
{
[FieldOffset(0)]
public Int32 type;
[FieldOffset(4)]
public KEYBDINPUT ki;
[FieldOffset(4)]
public MOUSEINPUT mi;
[FieldOffset(4)]
public HARDWAREINPUT hi;
}
[StructLayout(LayoutKind.Sequential)]
public struct MOUSEINPUT
{
public Int32 dx;
public Int32 dy;
public Int32 mouseData;
public Int32 dwFlags;
public Int32 time;
public IntPtr dwExtraInfo;
}
[StructLayout(LayoutKind.Sequential)]
public struct KEYBDINPUT
{
public Int16 wVk;
public Int16 wScan;
public Int32 dwFlags;
public Int32 time;
public IntPtr dwExtraInfo;
}
[StructLayout(LayoutKind.Sequential)]
public struct HARDWAREINPUT
{
public Int32 uMsg;
public Int16 wParamL;
public Int16 wParamH;
}
public const int INPUT_KEYBOARD = 1;
public const int KEYEVENTF_KEYUP = 0x0002;
private void button1_Click(object sender, EventArgs e)
{
INPUT[] inDown = new INPUT[4];
inDown[0] = new INPUT();
inDown[1] = new INPUT();
inDown[2] = new INPUT();
inDown[3] = new INPUT();
inDown[0].type = inDown[1].type = inDown[2].type = inDown[3].type = INPUT_KEYBOARD;
inDown[0].ki.wVk = inDown[2].ki.wVk =(int) Keys.LWin;
inDown[1].ki.wVk = inDown[3].ki.wVk = (int)Keys.R;
inDown[2].ki.dwFlags = inDown[3].ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(4, inDown, Marshal.SizeOf(inDown[0]));
}