Skip to content

Documentation

JMVRy edited this page Nov 21, 2023 · 4 revisions

Documentation

This is the documentation on the methods within the MouseOperations class and the InputOperations class. Both are static classes, so there's no need to instantiate them to do the cool things.

The formatting of the methods goes like the following: MethodName( [Paramaters, if there exists any] ) -> [Return type, or void if none]. If you wish to get more information about a specific method, click on the linked part to see more information.

MouseOperations

MouseOperations contains the following data types:

Data Types

Data Types

  • Enum
    • MouseEventFlags (bit field)
      • Move = 0x0001
      • LeftDown = 0x0002
      • LeftUp = 0x0004
      • RightDown = 0x0008
      • RightUp = 0x0010
      • MiddleDown = 0x0020
      • MiddleUp = 0x0040
      • Absolute = 0x8000
  • Struct
    • MousePoint
      • X (int)
      • Y (int)
    • Color
      • R (byte)
      • G (byte)
      • B (byte)
      • A (byte)
        • Note: Win32 always sets this value to 0, so any other value means an error occurred.

MouseOperations contains the following public methods:

Public Methods

Public Methods

FindWindowByCaption( string caption ) -> IntPtr

Finds a window using it's caption.

string caption: The caption of the Window you need

Returns: A pointer to the window handle you want

GetPixelColor( MouseOperations.MousePoint mousePoint ) -> MouseOperations.Color

Gets the pixel data on screen with the specified coordinate

MouseOperations.MousePoint mousePoint: The coordinate for the pixel

Returns: The pixel's data at the given coordinate. If outside the clipping region, returns an error value of 0xFFFFFFFF

GetPixelColor( IntPtr hWnd, MouseOperations.MousePoint mousePoint ) -> MouseOperations.Color

Gets the pixel data on the given window handle with the specified coordinate

IntPtr hWnd: A handle to the window whose DC is to be retrieved. If this value is IntPtr.Zero, GetPixelColor is absolute. Otherwise, it is relative to the window.

MouseOperations.MousePoint mousePoint: The relative coordinate for the pixel, depending on the value of hWnd

Returns: The pixel's data at the given coordinate. If outside the clipping region, returns an error value of 0xFFFFFFFF

GetPixelColor( int x, int y ) -> MouseOperations.Color

Gets the pixel data on screen with the specified coordinate

int x: The x coordinate of the pixel

int y: The y coordinate of the pixel

Returns: The pixel's data at the given coordinate. If outside the clipping region, returns an error value of 0xFFFFFFFF

GetPixelColor( IntPtr hWnd, int x, int y ) -> MouseOperations.Color

Gets the pixel data on the given window handle with the specified coordinate

IntPtr hWnd: A handle to the window whose DC is to be retrieved. If this value is IntPtr.Zero, GetPixelColor is absolute. Otherwise, it is relative to the window.

int x: The relative x coordinate of the pixel, depending on the value of hWnd

int y: The relative y coordinate of the pixel, depending on the value of hWnd

Returns: The pixel's data at the given coordinate. If outside the clipping region, returns an error value of 0xFFFFFFFF

SetCursorPosition( int x, int y ) -> void

Sets the user's cursor position to the specified coordinate

int x: The x coordinate to move the cursor to

int y: The y coordinate to move the cursor to

SetCursorPosition( MouseOperations.MousePoint point ) -> void

Sets the user's cursor position to the specified coordinate

MouseOperations.MousePoint point: The coordinate to move the cursor to

GetCursorPosition( ) -> MouseOperations.MousePoint

Gets the user's current cursor position

Returns: The coordinate of the mouse position

MouseEvent( MouseOperations.MouseEventFlags value ) -> void

Sends the specified mouse input events at the current mouse position

MouseOperations.MouseEventFlags value: The mouse events that need to be sent. To combine multiple events (e.g. LeftDown + LeftUp), just use bitwise or (|). For example:

using JMVR;

MouseOperations.MouseEvent( MouseOperations.MouseEventFlags.LeftDown | MouseOperations.MouseEventFlags.LeftUp );

InputOperations

InputOperations contains the following data types:

Data Types

Data Types

  • Enum
    • ClipboardFormat
    • InputType
      • INPUT_MOUSE for mouse input
      • INPUT_KEYBOARD for keyboard events
      • INPUT_HARDWARE for miscellaneous hardware events, only use if you know exactly what should be sent
    • KEYEVENTF (bit field)
      • EXTENDEDKEY = 0x1 for use with Enhanced 101/102-key keyboards
      • KEYUP = 0x2 to release the key
      • UNICODE = 0x4 to send specific Unicode characters. INPUT.U.ki.wVk must be set to 0, and INPUT.U.ki.wScan should contain the Unicode character you want to send. It's easier to just use InputOperators.SendUnicode for this purpose.
      • SCANCODE = 0x8 to use ScanCode for keys instead of VirtualKey
    • ScanCode
    • VirtualKey
    • MOUSEEVENTF (bit field)
      • MOVE = 0x0001
      • LEFTDOWN = 0x0002
      • LEFTUP = 0x0004
      • RIGHTDOWN = 0x0008
      • RIGHTUP = 0x0010
      • MIDDLEDOWN = 0x0020
      • MIDDLEUP = 0x0040
      • XDOWN = 0x0080
      • XUP = 0x0100
      • WHEEL = 0x0800
      • HWHEEL = 0x1000
      • MOVE_NOCOALESCE = 0x2000
      • VIRTUALDESK = 0x4000
      • ABSOLUTE = 0x8000
  • Struct
    • INPUT
      • type (InputType) for which input type to use
      • U (InputUnion) for different inputs' data
      • Size (static readonly int) for the size of the INPUT struct (necessary for Win32's SendInput)
    • InputUnion
      • mi (MOUSEINPUT)
      • ki (KEYBDINPUT)
      • hi (HARDWAREINPUT)
    • MOUSEINPUT
      • dx (int) for position change (relative or absolute depending on if dwFlags has MOUSEEVENTF.ABSOLUTE set)
      • dy (int) for position change (relative or absolute depending on if dwFlags has MOUSEEVENTF.ABSOLUTE set)
      • mouseData (int) for extra data:
        • If MOUSEEVENTF.WHEEL (supports Windows XP/2000) or MOUSEEVENTF.HWHEEL (doesn't) is set, scrolls the mouse wheel. One click == 120
        • If MOUSEEVENTF.XDOWN or MOUSEEVENTF.XUP is set, changes which XButton is affected (1 == XBUTTON1, 2 == XBUTTON2)
      • dwFlags (MOUSEEVENTF)
      • time (uint) for a time stamp of the event. If 0, the system provides the time.
      • dwExtraInfo (UIntPtr) for additional info. Use InputOperations.GetExtraInfo to obtain the info, then cast to UIntPtr.
    • KEYBDINPUT
      • wVk (VirtualKey) for virtual key codes to send. Needs to be 0 if KEYEVENTF.UNICODE is set.
      • wScan (ScanCode) for hardware scan codes to send. Only needed if KEYEVENTF.SCANCODE is set.
      • dwFlags (KEYEVENTF) for specific events. Refer to KEYEVENTF above for more info.
      • time (uint) for a time stamp of the event. If 0, the system provides the time.
      • dwExtraInfo (UIntPtr) for additional info. Use InputOperations.GetExtraInfo to obtain the info, then cast to UIntPtr.
    • HARDWAREINPUT
      • uMsg (int) for the message generated by the hardware.
      • wParamL (short) for the low-order word (short) of the lParam parameter for uMsg.
      • wParamR (short) for the high-order word (short) of the lParam parameter for uMsg.

InputOperations contains the following public methods:

Public Methods

Public Methods

GetLastError( ) -> int

Gets the last error produced by Win32.

Returns: An integer representation of various error values. See this website for all error codes possible.

GetExtraInfo( ) -> IntPtr

Gets extra info about the input, required by SendInput when using KEYBDINPUT or MOUSEINPUT.

Returns: A pointer containing the extra information, which is device specific.

GetClipboardText( ) -> string

Gets text data from the clipboard.

Returns: A string containing the text information on the clipboard.

InputEvent( INPUT[] inputs ) -> uint

Sends any input events.

INPUT[] inputs: An array of inputs to be sent.

Returns: The number of successful inputs. If 0, another thread has blocked the input. If blocked by UIPI, neither GetLastError nor the return value will indicate such.

SendUnicode( string s, uint millisecondDelay = 0 ) -> uint

Sends a string of Unicode characters as input

string s: The string you wish to input

uint millisecondDelay: The delay between key press and release. This is not a delay between individual keys.

Returns: The number of successful inputs. If 0, another thread has blocked the input. If blocked by UIPI, neither GetLastError nor the return value will indicate such.

SendUnicode( char c, uint millisecondDelay = 0 ) -> uint

Sends a single Unicode character as input

char c: The character you wish to input

uint millisecondDelay: The delay between key press and release. This is not a delay between individual keys.

Returns: The number of successful inputs. If 0, another thread has blocked the input. If blocked by UIPI, neither GetLastError nor the return value will indicate such.

SendUnicode( char[] chars, uint millisecondDelay = 0 ) -> uint

Sends an array of Unicode characters as input

char[] chars: The array of characters you wish to input

uint millisecondDelay: The delay between key press and release. This is not a delay between individual keys.

Returns: The number of successful inputs. If 0, another thread has blocked the input. If blocked by UIPI, neither GetLastError nor the return value will indicate such.

SendKeypress( VirtualKey vk, uint millisecondDelay = 0 ) -> uint

Sends a virtual key as input

VirtualKey vk: The virtual key you wish to input

uint millisecondDelay: The delay between key press and release. This is not a delay between individual keys.

Returns: The number of successful inputs. If 0, another thread has blocked the input. If blocked by UIPI, neither GetLastError nor the return value will indicate such.

SendKeypress( VirtualKey[] virtualKeys, uint millisecondDelay = 0 ) -> uint

Sends an array of virtual keys as input

VirtualKey[] virtualKeys: The array of virtual keys you wish to input

uint millisecondDelay: The delay between key press and release. This is not a delay between individual keys.

Returns: The number of successful inputs. If 0, another thread has blocked the input. If blocked by UIPI, neither GetLastError nor the return value will indicate such.