本文整理汇总了C#中INPUT类的典型用法代码示例。如果您正苦于以下问题:C# INPUT类的具体用法?C# INPUT怎么用?C# INPUT使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
INPUT类属于命名空间,在下文中一共展示了INPUT类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HardwareKeyPress
/// <summary>
/// Calls the Win32 SendInput method with a KeyDown and KeyUp message in the same input sequence in order to simulate a Key PRESS.
/// </summary>
/// <param name="keyCode">The HardwareKeyCode to press</param>
public static void HardwareKeyPress(ScanCode keyCode)
{
var down = new INPUT();
down.Type = (UInt32)InputType.KEYBOARD;
down.Data.Keyboard = new KEYBDINPUT();
down.Data.Keyboard.Vk = 0;
down.Data.Keyboard.Scan = (UInt16)keyCode;
down.Data.Keyboard.Flags = KeyboardFlag.SCANCODE;
down.Data.Keyboard.Time = 0;
down.Data.Keyboard.ExtraInfo = IntPtr.Zero;
var up = new INPUT();
up.Type = (UInt32)InputType.KEYBOARD;
up.Data.Keyboard = new KEYBDINPUT();
up.Data.Keyboard.Vk = 0;
up.Data.Keyboard.Scan = (UInt16)keyCode;
up.Data.Keyboard.Flags = KeyboardFlag.SCANCODE | KeyboardFlag.KEYUP;
up.Data.Keyboard.Time = 0;
up.Data.Keyboard.ExtraInfo = IntPtr.Zero;
if (((int)keyCode & 0xFF00) == 0xE000)
{ // extended key?
down.Data.Keyboard.Flags |= KeyboardFlag.EXTENDEDKEY;
up.Data.Keyboard.Flags |= KeyboardFlag.EXTENDEDKEY;
}
INPUT[] inputList = new INPUT[2];
inputList[0] = down;
inputList[1] = up;
var numberOfSuccessfulSimulatedInputs = SendInput(2, inputList, Marshal.SizeOf(typeof(INPUT)));
if (numberOfSuccessfulSimulatedInputs == 0) throw new Exception(string.Format("The key press simulation for {0} was not successful.", keyCode));
}
示例2: DispatchInput
public unsafe void DispatchInput(INPUT* inputs, uint count)
{
var successful = NativeMethods.SendInput(count, inputs, Marshal.SizeOf(typeof(INPUT)));
if (successful != count)
throw new Exception("Some simulated input commands were not sent successfully. The most common reason for this happening are the security features of Windows including User Interface Privacy Isolation (UIPI). Your application can only send commands to applications of the same or lower elevation. Similarly certain commands are restricted to Accessibility/UIAutomation applications. Refer to the project home page and the code samples for more information.");
}
示例3: Jiggle
public static void Jiggle(int dx, int dy)
{
INPUT[] inputs = new INPUT[]
{
new INPUT
{
type = INPUT_MOUSE,
u = new InputUnion
{
mi = new MOUSEINPUT
{
dx=dx,
dy= dy,
mouseData = 0,
dwFlags = MOUSEEVENTF_MOVE,
dwExtraInfo=(IntPtr) 0,
time=0
}
}
}
};
if (SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT))) != 1)
{
throw new Win32Exception();
}
}
示例4: SendEscape
public static void SendEscape(IntPtr target)
{
if(target != IntPtr.Zero)
{
int processId;
int inputThread = Win32Declarations.GetWindowThreadProcessId(target, out processId);
Assert.Check(inputThread == Win32Declarations.GetCurrentThreadId());
}
INPUT[] input = new INPUT[2];
input[0].type = input[1].type = Win32Declarations.INPUT_KEYBOARD;
input[0].ki.wScan = input[1].ki.wScan = 0;
input[0].ki.time = input[1].ki.time = 0;
input[1].ki.dwFlags = Win32Declarations.KEYEVENTF_KEYUP;
input[0].ki.dwExtraInfo = input[1].ki.dwExtraInfo = GetMessageExtraInfo();
input[0].ki.wVk = input[1].ki.wVk = 0x1B; // escape
uint ret = Win32Declarations.SendInput(input);
if(ret != 2)
{
throw new Win32Exception("Unexpected error " + Win32Declarations.GetLastError());
}
// TODO use SetForegroundWindow ?
}
示例5: SendString
public static void SendString(string toSend)
{
INPUT input = new INPUT();
input.type = 1;
input.mkhi.ki.dwFlags |= KEYEVENTF_SCANCODE;
foreach (char c in toSend)
{
ushort code;
bool shift;
MapToCode(c, out code, out shift);
if (code == 0)
continue;
if (shift)
{
input.mkhi.ki.wScan = 0x2A;
SendInput(1, ref input, Marshal.SizeOf(typeof(INPUT)));
}
input.mkhi.ki.wScan = code;
SendInput(1, ref input, Marshal.SizeOf(typeof(INPUT)));
input.mkhi.ki.dwFlags |= KEYEVENTF_KEYUP;
SendInput(1, ref input, Marshal.SizeOf(typeof(INPUT)));
if (shift)
{
input.mkhi.ki.wScan = 0x2A;
SendInput(1, ref input, Marshal.SizeOf(typeof(INPUT)));
}
input.mkhi.ki.dwFlags &= ~KEYEVENTF_KEYUP;
}
}
示例6: DoClickMouse
public static void DoClickMouse(ClickRecordType clickType)
{
INPUT mouseInput = new INPUT()
{
type = 0, // Mouse input
mi = new MOUSEINPUT()
};
switch(clickType)
{
case ClickRecordType.LeftClick:
mouseInput.mi.dwFlags = MouseEventFlags.LeftDown;
SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
System.Threading.Thread.Sleep(150);
mouseInput.mi.dwFlags = MouseEventFlags.LeftUp;
SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
break;
case ClickRecordType.RightClick:
mouseInput.mi.dwFlags = MouseEventFlags.RightDown;
SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
System.Threading.Thread.Sleep(150);
mouseInput.mi.dwFlags = MouseEventFlags.RightUp;
SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
break;
case ClickRecordType.MiddleClick:
mouseInput.mi.dwFlags = MouseEventFlags.MiddleDown;
SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
System.Threading.Thread.Sleep(150);
mouseInput.mi.dwFlags = MouseEventFlags.MiddleUp;
SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
break;
}
}
示例7: MouseSend
public static void MouseSend(int x, int y, Input.MouseFlag flag, int data)
{
INPUT[] input = new INPUT[1];
int value = (int)flag;
if (flag == Input.MouseFlag.MoveTo)
{
value = ((int)(MOUSEEVENTF_ABSOLUTE) | (int)(MOUSEEVENTF_MOVE));
x = 65536 * x / W;
y = 65536 * y / H;
}
if (flag == Input.MouseFlag.AddTo)
{
x = 65536 * x / W;
y = 65536 * y / H;
}
input[0] = new INPUT();
input[0].mi.dx = x;
input[0].mi.dy = y;
input[0].mi.dwExtraInfo = (IntPtr)0;
input[0].mi.time = 0;
input[0].mi.mouseData = data;
input[0].mi.dwFlags = value;
input[0].type = INPUT_MOUSE;
SendInput(1, input, Marshal.SizeOf(input[0]));
}
示例8: DoClickMouse
private static void DoClickMouse(ClickNodeSubType clickType)
{
INPUT mouseInput = new INPUT()
{
type = 0, // Mouse input
mi = new MOUSEINPUT()
};
switch(clickType)
{
case ClickNodeSubType.LeftClick:
mouseInput.mi.dwFlags = MouseEventFlags.LeftDown;
SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
mouseInput.mi.dwFlags = MouseEventFlags.LeftUp;
SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
break;
case ClickNodeSubType.RightClick:
mouseInput.mi.dwFlags = MouseEventFlags.RightDown;
SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
mouseInput.mi.dwFlags = MouseEventFlags.RightUp;
SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
break;
case ClickNodeSubType.MiddleClick:
mouseInput.mi.dwFlags = MouseEventFlags.MiddleDown;
SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
mouseInput.mi.dwFlags = MouseEventFlags.MiddleUp;
SendInput(1, ref mouseInput, Marshal.SizeOf(new INPUT()));
break;
}
}
示例9: LeftMouseButtonUp
public static void LeftMouseButtonUp()
{
INPUT mouseUpInput = new INPUT();
mouseUpInput.type = SendInputEventType.InputMouse;
mouseUpInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_LEFTUP;
SendInput(1, ref mouseUpInput, Marshal.SizeOf(new INPUT()));
}
示例10: Click
/// <summary>
/// Clicks target point relative to window set.
/// </summary>
/// <param name="point"></param>
/// <param name="mouse_button">Mouse button (MouseButtons.Left or MouseButtons.Right)</param>
public static void Click(Point point, MouseButton mouse_button)
{
SetPosition(point);
INPUT[] InputData = new INPUT[3];
Point screen_point = ToScreen(point);
InputData[0].mi.dx = screen_point.X;
InputData[0].mi.dy = screen_point.Y;
InputData[0].mi.dwFlags = (int)(Flags.MOUSEEVENTF_ABSOLUTE | Flags.MOUSEEVENTF_MOVE);
if ((mouse_button & MouseButton.Left) == MouseButton.Left)
{
InputData[1].mi.dwFlags = (int)Flags.MOUSEEVENTF_LEFTDOWN;
InputData[2].mi.dwFlags = (int)Flags.MOUSEEVENTF_LEFTUP;
}
else if ((mouse_button & MouseButton.Right) == MouseButton.Right)
{
InputData[1].mi.dwFlags = (int)Flags.MOUSEEVENTF_RIGHTDOWN;
InputData[2].mi.dwFlags = (int)Flags.MOUSEEVENTF_RIGHTUP;
}
else
{
Console.WriteLine("unknown mouse button");
return;
}
if (SendInput(3, InputData, Marshal.SizeOf(InputData[0])) == 0)
{
Console.WriteLine("SendInput mouse error");
}
}
示例11: pressKey
public static void pressKey(ushort key)
{
INPUT[] InputList = new INPUT[2];
InputList[0] = new INPUT();
InputList[0].type = 1;
//Keys virtualKeycode = (Keys)0x15;
InputList[0].ki.wVk = key;
InputList[0].ki.wScan = 0;
InputList[0].ki.time = 0;
InputList[0].ki.dwFlags = 0;
InputList[0].ki.dwExtraInfo = (uint)IntPtr.Zero;
InputList[1] = new INPUT();
InputList[1].type = 1;
//Keys virtualKeycode = (Keys)0x15;
InputList[1].ki.wVk = key;
InputList[1].ki.wScan = 0;
InputList[1].ki.time = 0;
InputList[1].ki.dwFlags = 2;
InputList[1].ki.dwExtraInfo = (uint)IntPtr.Zero;
// keyInput.ki.dwFlags = (int)KeyEvent.KeyUp;
// InputList[1] = keyInput;
uint stat = SendInput((uint)2, InputList, Marshal.SizeOf(InputList[0]));
Console.WriteLine("\nresult {0} , ", stat);
}
示例12: SendKey
static void SendKey(short keycode)
{
KEYBDINPUT ki = new KEYBDINPUT()
{
time = 0,
wScan = 0,
dwExtraInfo = (IntPtr)0,
wVk = keycode,
dwFlags = 0
};
if (IntPtr.Size > 4)
{
// 64-bit environment
INPUT64 ip = new INPUT64();
ip.type = 1; // Indicates a keyboard event
ip.ki = ki;
SendInput(1, new INPUT64[] { ip }, Marshal.SizeOf(ip));
ip.ki.dwFlags = 2;
SendInput(1, new INPUT64[] { ip }, Marshal.SizeOf(ip));
}
else
{
// 32-bit environment
INPUT ip = new INPUT();
ip.type = 1; // Indicates a keyboard event
ip.ki = ki;
// Press..
SendInput(1, new INPUT[] { ip }, Marshal.SizeOf(ip));
ip.ki.dwFlags = 2;
// And let go.
SendInput(1, new INPUT[] { ip }, Marshal.SizeOf(ip));
}
}
示例13: Wheel
public static void Wheel(int amount)
{
var inputs = new INPUT[1];
inputs[0].mi.dwFlags = MouseEvent.WHEEL | MouseEvent.ABSOLUTE;
inputs[0].mi.mouseData = - amount * WHEEL_DELTA;
SendInput(1, inputs, Marshal.SizeOf(inputs[0]));
}
示例14: RightClick
public static void RightClick()
{
var inputs = new INPUT[2];
inputs[0].mi.dwFlags = MouseEvent.RIGHTDOWN;
inputs[1].mi.dwFlags = MouseEvent.RIGHTUP;
SendInput(2, inputs, Marshal.SizeOf(inputs[0]));
}
示例15: sendInput
// And a wrapper for it
static bool sendInput(INPUT input)
{
INPUT[] inputList = new INPUT[1];
inputList[0] = input;
var numberOfSuccessfulSimulatedInputs = NativeMethods.SendInput(1, inputList, Marshal.SizeOf(typeof(INPUT)));
return numberOfSuccessfulSimulatedInputs > 0;
}