C# Class ManagedWin32.WindowsInputBuilder

A helper class for building a list of INPUT messages ready to be sent to the native Windows API.
ファイルを表示 Open project: MathewSachin/ManagedWin32

Public Methods

Method Description
AddAbsoluteMouseMovement ( int absoluteX, int absoluteY ) : void

Move the mouse to an absolute position.

AddAbsoluteMouseMovementOnVirtualDesktop ( int absoluteX, int absoluteY ) : void

Move the mouse to the absolute position on the virtual desktop.

AddCharacter ( char character ) : void

Adds the character to the list of INPUT messages.

AddCharacters ( ) : void

Adds the characters in the specified string.

AddCharacters ( IEnumerable characters ) : void

Adds all of the characters in the specified IEnumerable{T} of char.

AddKeyDown ( KeyCode keyCode ) : void

Adds a key down to the list of INPUT messages.

AddKeyPress ( KeyCode keyCode ) : void

Adds a key press to the list of INPUT messages which is equivalent to a key down followed by a key up.

AddKeyUp ( KeyCode keyCode ) : void

Adds a key up to the list of INPUT messages.

AddMouseButtonClick ( MouseButton button ) : void

Adds a single click of the specified button.

AddMouseButtonDoubleClick ( MouseButton button ) : void

Adds a double click of the specified button.

AddMouseButtonDown ( MouseButton button ) : void

Adds a mouse button down for the specified button.

AddMouseButtonUp ( MouseButton button ) : void

Adds a mouse button up for the specified button.

AddMouseHorizontalWheelScroll ( int scrollAmount ) : void

Scroll the horizontal mouse wheel by the specified amount.

AddMouseVerticalWheelScroll ( int scrollAmount ) : void

Scroll the vertical mouse wheel by the specified amount.

AddMouseXButtonClick ( int xButtonId ) : void

Adds a single click of the specified button.

AddMouseXButtonDoubleClick ( int xButtonId ) : void

Adds a double click of the specified button.

AddMouseXButtonDown ( int xButtonId ) : void

Adds a mouse button down for the specified button.

AddMouseXButtonUp ( int xButtonId ) : void

Adds a mouse button up for the specified button.

AddRelativeMouseMovement ( int x, int y ) : void

Moves the mouse relative to its current position.

Clear ( ) : void
IsExtendedKey ( KeyCode keyCode ) : bool

Determines if the KeyCode is an ExtendedKey

The extended keys consist of the ALT and CTRL keys on the right-hand side of the keyboard; the INS, DEL, HOME, END, PAGE UP, PAGE DOWN, and arrow keys in the clusters to the left of the numeric keypad; the NUM LOCK key; the BREAK (CTRL+PAUSE) key; the PRINT SCRN key; and the divide (/) and ENTER keys in the numeric keypad. See http://msdn.microsoft.com/en-us/library/ms646267(v=vs.85).aspx Section "Extended-Key Flag"

IsHardwareKeyDown ( KeyCode keyCode ) : bool

Determines whether the physical key is up or down at the time the function is called regardless of whether the application thread has read the keyboard event from the message pump by calling the User32.GetAsyncKeyState function. (See: http://msdn.microsoft.com/en-us/library/ms646293(VS.85).aspx)

The GetAsyncKeyState function works with mouse buttons. However, it checks on the state of the physical mouse buttons, not on the logical mouse buttons that the physical buttons are mapped to. For example, the call GetAsyncKeyState(VK_LBUTTON) always returns the state of the left physical mouse button, regardless of whether it is mapped to the left or right logical mouse button. You can determine the system's current mapping of physical mouse buttons to logical mouse buttons by calling Copy CodeGetSystemMetrics(SM_SWAPBUTTON) which returns TRUE if the mouse buttons have been swapped. Although the least significant bit of the return value indicates whether the key has been pressed since the last query, due to the pre-emptive multitasking nature of Windows, another application can call GetAsyncKeyState and receive the "recently pressed" bit instead of your application. The behavior of the least significant bit of the return value is retained strictly for compatibility with 16-bit Windows applications (which are non-preemptive) and should not be relied upon. You can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the vKey parameter. This gives the state of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. Windows NT/2000/XP: You can use the following virtual-key code constants as values for vKey to distinguish between the left and right instances of those keys. Code Meaning VK_LSHIFT Left-shift key. VK_RSHIFT Right-shift key. VK_LCONTROL Left-control key. VK_RCONTROL Right-control key. VK_LMENU Left-menu key. VK_RMENU Right-menu key. These left- and right-distinguishing constants are only available when you call the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.

IsHardwareKeyUp ( KeyCode keyCode ) : bool

Determines whether the physical key is up or down at the time the function is called regardless of whether the application thread has read the keyboard event from the message pump by calling the User32.GetAsyncKeyState function. (See: http://msdn.microsoft.com/en-us/library/ms646293(VS.85).aspx)

The GetAsyncKeyState function works with mouse buttons. However, it checks on the state of the physical mouse buttons, not on the logical mouse buttons that the physical buttons are mapped to. For example, the call GetAsyncKeyState(VK_LBUTTON) always returns the state of the left physical mouse button, regardless of whether it is mapped to the left or right logical mouse button. You can determine the system's current mapping of physical mouse buttons to logical mouse buttons by calling Copy CodeGetSystemMetrics(SM_SWAPBUTTON) which returns TRUE if the mouse buttons have been swapped. Although the least significant bit of the return value indicates whether the key has been pressed since the last query, due to the pre-emptive multitasking nature of Windows, another application can call GetAsyncKeyState and receive the "recently pressed" bit instead of your application. The behavior of the least significant bit of the return value is retained strictly for compatibility with 16-bit Windows applications (which are non-preemptive) and should not be relied upon. You can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the vKey parameter. This gives the state of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. Windows NT/2000/XP: You can use the following virtual-key code constants as values for vKey to distinguish between the left and right instances of those keys. Code Meaning VK_LSHIFT Left-shift key. VK_RSHIFT Right-shift key. VK_LCONTROL Left-control key. VK_RCONTROL Right-control key. VK_LMENU Left-menu key. VK_RMENU Right-menu key. These left- and right-distinguishing constants are only available when you call the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.

IsKeyDown ( KeyCode keyCode ) : bool

Determines whether the specified key is up or down by calling the GetKeyState function. (See: http://msdn.microsoft.com/en-us/library/ms646301(VS.85).aspx)

The key status returned from this function changes as a thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information. An application calls GetKeyState in response to a keyboard-input message. This function retrieves the state of the key when the input message was generated. To retrieve state information for all the virtual keys, use the GetKeyboardState function. An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for Bthe nVirtKey parameter. This gives the status of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. An application can also use the following virtual-key code constants as values for nVirtKey to distinguish between the left and right instances of those keys. VK_LSHIFT VK_RSHIFT VK_LCONTROL VK_RCONTROL VK_LMENU VK_RMENU These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.

IsKeyUp ( KeyCode keyCode ) : bool

Determines whether the specified key is up or downby calling the User32.GetKeyState function. (See: http://msdn.microsoft.com/en-us/library/ms646301(VS.85).aspx)

The key status returned from this function changes as a thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information. An application calls GetKeyState in response to a keyboard-input message. This function retrieves the state of the key when the input message was generated. To retrieve state information for all the virtual keys, use the GetKeyboardState function. An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for Bthe nVirtKey parameter. This gives the status of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. An application can also use the following virtual-key code constants as values for nVirtKey to distinguish between the left and right instances of those keys. VK_LSHIFT VK_RSHIFT VK_LCONTROL VK_RCONTROL VK_LMENU VK_RMENU These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.

IsTogglingKeyInEffect ( KeyCode keyCode ) : bool

Determines whether the toggling key is toggled on (in-effect) or not by calling the User32.GetKeyState function. (See: http://msdn.microsoft.com/en-us/library/ms646301(VS.85).aspx)

The key status returned from this function changes as a thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information. An application calls GetKeyState in response to a keyboard-input message. This function retrieves the state of the key when the input message was generated. To retrieve state information for all the virtual keys, use the GetKeyboardState function. An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the nVirtKey parameter. This gives the status of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. An application can also use the following virtual-key code constants as values for nVirtKey to distinguish between the left and right instances of those keys. VK_LSHIFT VK_RSHIFT VK_LCONTROL VK_RCONTROL VK_LMENU VK_RMENU These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.

KeysPress ( IEnumerable keyCodes ) : void
ModifiedKeyStroke ( IEnumerable modifierKeyCodes, IEnumerable keyCodes ) : void

Simulates a modified keystroke where there are multiple modifiers and multiple keys like CTRL-ALT-K-C where CTRL and ALT are the modifierKeys and K and C are the keys. The flow is Modifiers KeyDown in order, Keys Press in order, Modifiers KeyUp in reverse order.

Simulate ( bool ClearAfterSimulation = true ) : bool

Method Details

AddAbsoluteMouseMovement() public method

Move the mouse to an absolute position.
public AddAbsoluteMouseMovement ( int absoluteX, int absoluteY ) : void
absoluteX int
absoluteY int
return void

AddAbsoluteMouseMovementOnVirtualDesktop() public method

Move the mouse to the absolute position on the virtual desktop.
public AddAbsoluteMouseMovementOnVirtualDesktop ( int absoluteX, int absoluteY ) : void
absoluteX int
absoluteY int
return void

AddCharacter() public method

Adds the character to the list of INPUT messages.
public AddCharacter ( char character ) : void
character char The to be added to the list of messages.
return void

AddCharacters() public method

Adds the characters in the specified string.
public AddCharacters ( ) : void
return void

AddCharacters() public method

Adds all of the characters in the specified IEnumerable{T} of char.
public AddCharacters ( IEnumerable characters ) : void
characters IEnumerable The characters to add.
return void

AddKeyDown() public method

Adds a key down to the list of INPUT messages.
public AddKeyDown ( KeyCode keyCode ) : void
keyCode KeyCode The .
return void

AddKeyPress() public method

Adds a key press to the list of INPUT messages which is equivalent to a key down followed by a key up.
public AddKeyPress ( KeyCode keyCode ) : void
keyCode KeyCode The .
return void

AddKeyUp() public method

Adds a key up to the list of INPUT messages.
public AddKeyUp ( KeyCode keyCode ) : void
keyCode KeyCode The .
return void

AddMouseButtonClick() public method

Adds a single click of the specified button.
public AddMouseButtonClick ( MouseButton button ) : void
button MouseButton
return void

AddMouseButtonDoubleClick() public method

Adds a double click of the specified button.
public AddMouseButtonDoubleClick ( MouseButton button ) : void
button MouseButton
return void

AddMouseButtonDown() public method

Adds a mouse button down for the specified button.
public AddMouseButtonDown ( MouseButton button ) : void
button MouseButton
return void

AddMouseButtonUp() public method

Adds a mouse button up for the specified button.
public AddMouseButtonUp ( MouseButton button ) : void
button MouseButton
return void

AddMouseHorizontalWheelScroll() public method

Scroll the horizontal mouse wheel by the specified amount.
public AddMouseHorizontalWheelScroll ( int scrollAmount ) : void
scrollAmount int
return void

AddMouseVerticalWheelScroll() public method

Scroll the vertical mouse wheel by the specified amount.
public AddMouseVerticalWheelScroll ( int scrollAmount ) : void
scrollAmount int
return void

AddMouseXButtonClick() public method

Adds a single click of the specified button.
public AddMouseXButtonClick ( int xButtonId ) : void
xButtonId int
return void

AddMouseXButtonDoubleClick() public method

Adds a double click of the specified button.
public AddMouseXButtonDoubleClick ( int xButtonId ) : void
xButtonId int
return void

AddMouseXButtonDown() public method

Adds a mouse button down for the specified button.
public AddMouseXButtonDown ( int xButtonId ) : void
xButtonId int
return void

AddMouseXButtonUp() public method

Adds a mouse button up for the specified button.
public AddMouseXButtonUp ( int xButtonId ) : void
xButtonId int
return void

AddRelativeMouseMovement() public method

Moves the mouse relative to its current position.
public AddRelativeMouseMovement ( int x, int y ) : void
x int
y int
return void

Clear() public method

public Clear ( ) : void
return void

IsExtendedKey() public static method

Determines if the KeyCode is an ExtendedKey
The extended keys consist of the ALT and CTRL keys on the right-hand side of the keyboard; the INS, DEL, HOME, END, PAGE UP, PAGE DOWN, and arrow keys in the clusters to the left of the numeric keypad; the NUM LOCK key; the BREAK (CTRL+PAUSE) key; the PRINT SCRN key; and the divide (/) and ENTER keys in the numeric keypad. See http://msdn.microsoft.com/en-us/library/ms646267(v=vs.85).aspx Section "Extended-Key Flag"
public static IsExtendedKey ( KeyCode keyCode ) : bool
keyCode KeyCode The key code.
return bool

IsHardwareKeyDown() public static method

Determines whether the physical key is up or down at the time the function is called regardless of whether the application thread has read the keyboard event from the message pump by calling the User32.GetAsyncKeyState function. (See: http://msdn.microsoft.com/en-us/library/ms646293(VS.85).aspx)
The GetAsyncKeyState function works with mouse buttons. However, it checks on the state of the physical mouse buttons, not on the logical mouse buttons that the physical buttons are mapped to. For example, the call GetAsyncKeyState(VK_LBUTTON) always returns the state of the left physical mouse button, regardless of whether it is mapped to the left or right logical mouse button. You can determine the system's current mapping of physical mouse buttons to logical mouse buttons by calling Copy CodeGetSystemMetrics(SM_SWAPBUTTON) which returns TRUE if the mouse buttons have been swapped. Although the least significant bit of the return value indicates whether the key has been pressed since the last query, due to the pre-emptive multitasking nature of Windows, another application can call GetAsyncKeyState and receive the "recently pressed" bit instead of your application. The behavior of the least significant bit of the return value is retained strictly for compatibility with 16-bit Windows applications (which are non-preemptive) and should not be relied upon. You can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the vKey parameter. This gives the state of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. Windows NT/2000/XP: You can use the following virtual-key code constants as values for vKey to distinguish between the left and right instances of those keys. Code Meaning VK_LSHIFT Left-shift key. VK_RSHIFT Right-shift key. VK_LCONTROL Left-control key. VK_RCONTROL Right-control key. VK_LMENU Left-menu key. VK_RMENU Right-menu key. These left- and right-distinguishing constants are only available when you call the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.
public static IsHardwareKeyDown ( KeyCode keyCode ) : bool
keyCode KeyCode The for the key.
return bool

IsHardwareKeyUp() public static method

Determines whether the physical key is up or down at the time the function is called regardless of whether the application thread has read the keyboard event from the message pump by calling the User32.GetAsyncKeyState function. (See: http://msdn.microsoft.com/en-us/library/ms646293(VS.85).aspx)
The GetAsyncKeyState function works with mouse buttons. However, it checks on the state of the physical mouse buttons, not on the logical mouse buttons that the physical buttons are mapped to. For example, the call GetAsyncKeyState(VK_LBUTTON) always returns the state of the left physical mouse button, regardless of whether it is mapped to the left or right logical mouse button. You can determine the system's current mapping of physical mouse buttons to logical mouse buttons by calling Copy CodeGetSystemMetrics(SM_SWAPBUTTON) which returns TRUE if the mouse buttons have been swapped. Although the least significant bit of the return value indicates whether the key has been pressed since the last query, due to the pre-emptive multitasking nature of Windows, another application can call GetAsyncKeyState and receive the "recently pressed" bit instead of your application. The behavior of the least significant bit of the return value is retained strictly for compatibility with 16-bit Windows applications (which are non-preemptive) and should not be relied upon. You can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the vKey parameter. This gives the state of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. Windows NT/2000/XP: You can use the following virtual-key code constants as values for vKey to distinguish between the left and right instances of those keys. Code Meaning VK_LSHIFT Left-shift key. VK_RSHIFT Right-shift key. VK_LCONTROL Left-control key. VK_RCONTROL Right-control key. VK_LMENU Left-menu key. VK_RMENU Right-menu key. These left- and right-distinguishing constants are only available when you call the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.
public static IsHardwareKeyUp ( KeyCode keyCode ) : bool
keyCode KeyCode The for the key.
return bool

IsKeyDown() public static method

Determines whether the specified key is up or down by calling the GetKeyState function. (See: http://msdn.microsoft.com/en-us/library/ms646301(VS.85).aspx)
The key status returned from this function changes as a thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information. An application calls GetKeyState in response to a keyboard-input message. This function retrieves the state of the key when the input message was generated. To retrieve state information for all the virtual keys, use the GetKeyboardState function. An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for Bthe nVirtKey parameter. This gives the status of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. An application can also use the following virtual-key code constants as values for nVirtKey to distinguish between the left and right instances of those keys. VK_LSHIFT VK_RSHIFT VK_LCONTROL VK_RCONTROL VK_LMENU VK_RMENU These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.
public static IsKeyDown ( KeyCode keyCode ) : bool
keyCode KeyCode The for the key.
return bool

IsKeyUp() public static method

Determines whether the specified key is up or downby calling the User32.GetKeyState function. (See: http://msdn.microsoft.com/en-us/library/ms646301(VS.85).aspx)
The key status returned from this function changes as a thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information. An application calls GetKeyState in response to a keyboard-input message. This function retrieves the state of the key when the input message was generated. To retrieve state information for all the virtual keys, use the GetKeyboardState function. An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for Bthe nVirtKey parameter. This gives the status of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. An application can also use the following virtual-key code constants as values for nVirtKey to distinguish between the left and right instances of those keys. VK_LSHIFT VK_RSHIFT VK_LCONTROL VK_RCONTROL VK_LMENU VK_RMENU These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.
public static IsKeyUp ( KeyCode keyCode ) : bool
keyCode KeyCode The for the key.
return bool

IsTogglingKeyInEffect() public static method

Determines whether the toggling key is toggled on (in-effect) or not by calling the User32.GetKeyState function. (See: http://msdn.microsoft.com/en-us/library/ms646301(VS.85).aspx)
The key status returned from this function changes as a thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information. An application calls GetKeyState in response to a keyboard-input message. This function retrieves the state of the key when the input message was generated. To retrieve state information for all the virtual keys, use the GetKeyboardState function. An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the nVirtKey parameter. This gives the status of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. An application can also use the following virtual-key code constants as values for nVirtKey to distinguish between the left and right instances of those keys. VK_LSHIFT VK_RSHIFT VK_LCONTROL VK_RCONTROL VK_LMENU VK_RMENU These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.
public static IsTogglingKeyInEffect ( KeyCode keyCode ) : bool
keyCode KeyCode The for the key.
return bool

KeysPress() public method

public KeysPress ( IEnumerable keyCodes ) : void
keyCodes IEnumerable
return void

ModifiedKeyStroke() public method

Simulates a modified keystroke where there are multiple modifiers and multiple keys like CTRL-ALT-K-C where CTRL and ALT are the modifierKeys and K and C are the keys. The flow is Modifiers KeyDown in order, Keys Press in order, Modifiers KeyUp in reverse order.
public ModifiedKeyStroke ( IEnumerable modifierKeyCodes, IEnumerable keyCodes ) : void
modifierKeyCodes IEnumerable The list of modifier keys
keyCodes IEnumerable The list of keys to simulate
return void

Simulate() public method

public Simulate ( bool ClearAfterSimulation = true ) : bool
ClearAfterSimulation bool
return bool