using System; using System.Runtime.InteropServices; namespace Vanara.PInvoke { public static partial class User32 { /// The resolution desired. [PInvokeData("winuser.h", MSDNShortId = "")] public enum GMMP { /// Retrieves the points using the display resolution. GMMP_USE_DISPLAY_POINTS = 1, /// /// Retrieves high resolution points. Points can range from zero to 65,535 (0xFFFF) in both x- and y-coordinates. This is the /// resolution provided by absolute coordinate pointing devices such as drawing tablets. /// GMMP_USE_HIGH_RESOLUTION_POINTS = 2, } /// Controls various aspects of mouse motion and button clicking. [PInvokeData("winuser.h", MSDNShortId = "")] [Flags] public enum MOUSEEVENTF { /// /// The dx and dy parameters contain normalized absolute coordinates. If not set, those parameters contain relative data: the /// change in position since the last reported position. This flag can be set, or not set, regardless of what kind of mouse or /// mouse-like device, if any, is connected to the system. For further information about relative mouse motion, see the following /// Remarks section. /// MOUSEEVENTF_ABSOLUTE = 0x8000, /// The left button is down. MOUSEEVENTF_LEFTDOWN = 0x0002, /// The left button is up. MOUSEEVENTF_LEFTUP = 0x0004, /// The middle button is down. MOUSEEVENTF_MIDDLEDOWN = 0x0020, /// The middle button is up. MOUSEEVENTF_MIDDLEUP = 0x0040, /// Movement occurred. MOUSEEVENTF_MOVE = 0x0001, /// The right button is down. MOUSEEVENTF_RIGHTDOWN = 0x0008, /// The right button is up. MOUSEEVENTF_RIGHTUP = 0x0010, /// The wheel has been moved, if the mouse has a wheel. The amount of movement is specified in dwData MOUSEEVENTF_WHEEL = 0x0800, /// An X button was pressed. MOUSEEVENTF_XDOWN = 0x0080, /// An X button was released. MOUSEEVENTF_XUP = 0x0100, /// The wheel button is tilted. MOUSEEVENTF_HWHEEL = 0x01000, /// Do not coalesce mouse moves. MOUSEEVENTF_MOVE_NOCOALESCE = 0x2000, /// Map to entire virtual desktop MOUSEEVENTF_VIRTUALDESK = 0x4000, } /// The services requested in a structure. [Flags] public enum TME : uint { /// /// The caller wants to cancel a prior tracking request. The caller should also specify the type of tracking that it wants to /// cancel. For example, to cancel hover tracking, the caller must pass the TME_CANCEL and TME_HOVER flags. /// TME_CANCEL = 0x80000000, /// /// The caller wants hover notification. Notification is delivered as a WM_MOUSEHOVER message. /// If the caller requests hover tracking while hover tracking is already active, the hover timer will be reset. /// This flag is ignored if the mouse pointer is not over the specified window or area. /// TME_HOVER = 0x00000001, /// /// The caller wants leave notification. Notification is delivered as a WM_MOUSELEAVE message. If the mouse is not over the /// specified window or area, a leave notification is generated immediately and no further tracking is performed. /// TME_LEAVE = 0x00000002, /// /// The caller wants hover and leave notification for the nonclient areas. Notification is delivered as WM_NCMOUSEHOVER and /// WM_NCMOUSELEAVE messages. /// TME_NONCLIENT = 0x00000010, /// /// The function fills in the structure instead of treating it as a tracking request. The structure is filled such that had that /// structure been passed to TrackMouseEvent, it would generate the current tracking. The only anomaly is that the hover time-out /// returned is always the actual time-out and not HOVER_DEFAULT, if HOVER_DEFAULT was specified during the original /// TrackMouseEvent request. /// TME_QUERY = 0x40000000, } /// /// Retrieves the current double-click time for the mouse. A double-click is a series of two clicks of the mouse button, the second /// occurring within a specified time after the first. The double-click time is the maximum number of milliseconds that may occur /// between the first and second click of a double-click. The maximum double-click time is 5000 milliseconds. /// /// /// Type: UINT /// The return value specifies the current double-click time, in milliseconds. The maximum return value is 5000 milliseconds. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getdoubleclicktime UINT GetDoubleClickTime( ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "")] public static extern uint GetDoubleClickTime(); /// Retrieves a history of up to 64 previous coordinates of the mouse or pen. /// /// Type: UINT /// The size, in bytes, of the MOUSEMOVEPOINT structure. /// /// /// Type: LPMOUSEMOVEPOINT /// /// A pointer to a MOUSEMOVEPOINT structure containing valid mouse coordinates (in screen coordinates). It may also contain a time stamp. /// /// /// The GetMouseMovePointsEx function searches for the point in the mouse coordinates history. If the function finds the /// point, it returns the last nBufPoints prior to and including the supplied point. /// /// /// If your application supplies a time stamp, the GetMouseMovePointsEx function will use it to differentiate between two /// equal points that were recorded at different times. /// /// /// An application should call this function using the mouse coordinates received from the WM_MOUSEMOVE message and convert them to /// screen coordinates. /// /// /// /// Type: LPMOUSEMOVEPOINT /// A pointer to a buffer that will receive the points. It should be at least cbSize* nBufPoints in size. /// /// /// Type: int /// The number of points to be retrieved. /// /// /// Type: DWORD /// The resolution desired. This parameter can be one of the following values. /// /// /// Value /// Meaning /// /// /// GMMP_USE_DISPLAY_POINTS 1 /// Retrieves the points using the display resolution. /// /// /// GMMP_USE_HIGH_RESOLUTION_POINTS 2 /// /// Retrieves high resolution points. Points can range from zero to 65,535 (0xFFFF) in both x- and y-coordinates. This is the /// resolution provided by absolute coordinate pointing devices such as drawing tablets. /// /// /// /// /// /// Type: int /// /// If the function succeeds, the return value is the number of points in the buffer. Otherwise, the function returns –1. For /// extended error information, your application can call GetLastError. /// /// /// /// /// The system retains the last 64 mouse coordinates and their time stamps. If your application supplies a mouse coordinate to /// GetMouseMovePointsEx and the coordinate exists in the system's mouse coordinate history, the function retrieves the /// specified number of coordinates from the systems' history. You can also supply a time stamp, which will be used to differentiate /// between identical points in the history. /// /// /// The GetMouseMovePointsEx function will return points that eventually were dispatched not only to the calling thread but /// also to other threads. /// /// GetMouseMovePointsEx may fail or return erroneous values in the following cases: /// /// /// If negative coordinates are passed in the MOUSEMOVEPOINT structure. /// /// /// If GetMouseMovePointsEx retrieves a coordinate with a negative value. /// /// /// /// These situations can occur if multiple monitors are present. To correct this, first call GetSystemMetrics to get the following values: /// /// /// /// SM_XVIRTUALSCREEN, /// /// /// SM_YVIRTUALSCREEN, /// /// /// SM_CXVIRTUALSCREEN, and /// /// /// SM_CYVIRTUALSCREEN. /// /// /// Then, for each point that is returned from GetMouseMovePointsEx, perform the following transform: /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getmousemovepointsex int GetMouseMovePointsEx( UINT // cbSize, LPMOUSEMOVEPOINT lppt, LPMOUSEMOVEPOINT lpptBuf, int nBufPoints, DWORD resolution ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "")] public static extern int GetMouseMovePointsEx(uint cbSize, in MOUSEMOVEPOINT lppt, [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] MOUSEMOVEPOINT[] lpptBuf, int nBufPoints, GMMP resolution); /// /// The mouse_event function synthesizes mouse motion and button clicks. /// Note This function has been superseded. Use SendInput instead. /// /// /// Type: DWORD /// /// Controls various aspects of mouse motion and button clicking. This parameter can be certain combinations of the following values. /// /// /// /// Value /// Meaning /// /// /// MOUSEEVENTF_ABSOLUTE 0x8000 /// /// The dx and dy parameters contain normalized absolute coordinates. If not set, those parameters contain relative data: the change /// in position since the last reported position. This flag can be set, or not set, regardless of what kind of mouse or mouse-like /// device, if any, is connected to the system. For further information about relative mouse motion, see the following Remarks section. /// /// /// /// MOUSEEVENTF_LEFTDOWN 0x0002 /// The left button is down. /// /// /// MOUSEEVENTF_LEFTUP 0x0004 /// The left button is up. /// /// /// MOUSEEVENTF_MIDDLEDOWN 0x0020 /// The middle button is down. /// /// /// MOUSEEVENTF_MIDDLEUP 0x0040 /// The middle button is up. /// /// /// MOUSEEVENTF_MOVE 0x0001 /// Movement occurred. /// /// /// MOUSEEVENTF_RIGHTDOWN 0x0008 /// The right button is down. /// /// /// MOUSEEVENTF_RIGHTUP 0x0010 /// The right button is up. /// /// /// MOUSEEVENTF_WHEEL 0x0800 /// The wheel has been moved, if the mouse has a wheel. The amount of movement is specified in dwData /// /// /// MOUSEEVENTF_XDOWN 0x0080 /// An X button was pressed. /// /// /// MOUSEEVENTF_XUP 0x0100 /// An X button was released. /// /// /// MOUSEEVENTF_WHEEL 0x0800 /// The wheel button is rotated. /// /// /// MOUSEEVENTF_HWHEEL 0x01000 /// The wheel button is tilted. /// /// /// /// The values that specify mouse button status are set to indicate changes in status, not ongoing conditions. For example, if the /// left mouse button is pressed and held down, MOUSEEVENTF_LEFTDOWN is set when the left button is first pressed, but not for /// subsequent motions. Similarly, MOUSEEVENTF_LEFTUP is set only when the button is first released. /// /// /// You cannot specify both MOUSEEVENTF_WHEEL and either MOUSEEVENTF_XDOWN or MOUSEEVENTF_XUP simultaneously in /// the dwFlags parameter, because they both require use of the dwData field. /// /// /// /// Type: DWORD /// /// The mouse's absolute position along the x-axis or its amount of motion since the last mouse event was generated, depending on the /// setting of MOUSEEVENTF_ABSOLUTE. Absolute data is specified as the mouse's actual x-coordinate; relative data is specified /// as the number of mickeys moved. A mickey is the amount that a mouse has to move for it to report that it has moved. /// /// /// /// Type: DWORD /// /// The mouse's absolute position along the y-axis or its amount of motion since the last mouse event was generated, depending on the /// setting of MOUSEEVENTF_ABSOLUTE. Absolute data is specified as the mouse's actual y-coordinate; relative data is specified /// as the number of mickeys moved. /// /// /// /// Type: DWORD /// /// If dwFlags contains MOUSEEVENTF_WHEEL, then dwData specifies the amount of wheel movement. A positive value indicates that /// the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the /// user. One wheel click is defined as WHEEL_DELTA, which is 120. /// /// /// If dwFlags contains MOUSEEVENTF_HWHEEL, then dwData specifies the amount of wheel movement. A positive value indicates /// that the wheel was tilted to the right; a negative value indicates that the wheel was tilted to the left. /// /// /// If dwFlags contains MOUSEEVENTF_XDOWN or MOUSEEVENTF_XUP, then dwData specifies which X buttons were pressed or /// released. This value may be any combination of the following flags. /// /// /// If dwFlags is not MOUSEEVENTF_WHEEL, MOUSEEVENTF_XDOWN, or MOUSEEVENTF_XUP, then dwData should be zero. /// /// /// /// Value /// Meaning /// /// /// XBUTTON1 0x0001 /// Set if the first X button was pressed or released. /// /// /// XBUTTON2 0x0002 /// Set if the second X button was pressed or released. /// /// /// /// /// Type: ULONG_PTR /// An additional value associated with the mouse event. An application calls GetMessageExtraInfo to obtain this extra information. /// /// /// /// If the mouse has moved, indicated by MOUSEEVENTF_MOVE being set, dx and dy hold information about that motion. The /// information is specified as absolute or relative integer values. /// /// /// If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute coordinates between 0 and 65,535. The /// event procedure maps these coordinates onto the display surface. Coordinate (0,0) maps onto the upper-left corner of the display /// surface, (65535,65535) maps onto the lower-right corner. /// /// /// If the MOUSEEVENTF_ABSOLUTE value is not specified, dx and dy specify relative motions from when the last mouse event was /// generated (the last reported position). Positive values mean the mouse moved right (or down); negative values mean the mouse /// moved left (or up). /// /// /// Relative mouse motion is subject to the settings for mouse speed and acceleration level. An end user sets these values using the /// Mouse application in Control Panel. An application obtains and sets these values with the SystemParametersInfo function. /// /// /// The system applies two tests to the specified relative mouse motion when applying acceleration. If the specified distance along /// either the x or y axis is greater than the first mouse threshold value, and the mouse acceleration level is not zero, the /// operating system doubles the distance. If the specified distance along either the x- or y-axis is greater than the second mouse /// threshold value, and the mouse acceleration level is equal to two, the operating system doubles the distance that resulted from /// applying the first threshold test. It is thus possible for the operating system to multiply relatively-specified mouse motion /// along the x- or y-axis by up to four times. /// /// /// Once acceleration has been applied, the system scales the resultant value by the desired mouse speed. Mouse speed can range from /// 1 (slowest) to 20 (fastest) and represents how much the pointer moves based on the distance the mouse moves. The default value is /// 10, which results in no additional modification to the mouse motion. /// /// /// The mouse_event function is used to synthesize mouse events by applications that need to do so. It is also used by /// applications that need to obtain more information from the mouse than its position and button state. For example, if a tablet /// manufacturer wants to pass pen-based information to its own applications, it can write a DLL that communicates directly to the /// tablet hardware, obtains the extra information, and saves it in a queue. The DLL then calls mouse_event with the standard /// button and x/y position data, along with, in the dwExtraInfo parameter, some pointer or index to the queued extra information. /// When the application needs the extra information, it calls the DLL with the pointer or index stored in dwExtraInfo, and the DLL /// returns the extra information. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-mouse_event void mouse_event( DWORD dwFlags, DWORD dx, // DWORD dy, DWORD dwData, ULONG_PTR dwExtraInfo ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "")] public static extern void mouse_event(MOUSEEVENTF dwFlags, int dx, int dy, int dwData, IntPtr dwExtraInfo); /// /// Sets the double-click time for the mouse. A double-click is a series of two clicks of a mouse button, the second occurring within /// a specified time after the first. The double-click time is the maximum number of milliseconds that may occur between the first /// and second clicks of a double-click. /// /// /// Type: UINT /// /// The number of milliseconds that may occur between the first and second clicks of a double-click. If this parameter is set to 0, /// the system uses the default double-click time of 500 milliseconds. If this parameter value is greater than 5000 milliseconds, the /// system sets the value to 5000 milliseconds. /// /// /// /// Type: BOOL /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// The SetDoubleClickTime function alters the double-click time for all windows in the system. // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setdoubleclicktime BOOL SetDoubleClickTime( UINT Arg1 ); [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetDoubleClickTime(uint Arg1); /// Reverses or restores the meaning of the left and right mouse buttons. /// /// Type: BOOL /// /// If this parameter is TRUE, the left button generates right-button messages and the right button generates left-button /// messages. If this parameter is FALSE, the buttons are restored to their original meanings. /// /// /// /// Type: BOOL /// If the meaning of the mouse buttons was reversed previously, before the function was called, the return value is nonzero. /// If the meaning of the mouse buttons was not reversed, the return value is zero. /// /// /// Button swapping is provided as a convenience to people who use the mouse with their left hands. The SwapMouseButton /// function is usually called by Control Panel only. Although an application is free to call the function, the mouse is a shared /// resource and reversing the meaning of its buttons affects all applications. /// // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-swapmousebutton BOOL SwapMouseButton( BOOL fSwap ); [DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winuser.h", MSDNShortId = "")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SwapMouseButton([MarshalAs(UnmanagedType.Bool)] bool fSwap); /// Posts messages when the mouse pointer leaves a window or hovers over a window for a specified amount of time. /// /// Type: LPTRACKMOUSEEVENT /// A pointer to a TRACKMOUSEEVENT structure that contains tracking information. /// /// /// Type: BOOL /// If the function succeeds, the return value is nonzero . /// If the function fails, return value is zero. To get extended error information, call GetLastError. /// // BOOL WINAPI TrackMouseEvent( _Inout_ LPTRACKMOUSEEVENT lpEventTrack); https://msdn.microsoft.com/en-us/library/windows/desktop/ms646265(v=vs.85).aspx [DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)] [PInvokeData("Winuser.h", MSDNShortId = "ms646265")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool TrackMouseEvent(ref TRACKMOUSEEVENT lpEventTrack); /// Contains information about the mouse's location in screen coordinates. // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-tagmousemovepoint typedef struct tagMOUSEMOVEPOINT { int // x; int y; DWORD time; ULONG_PTR dwExtraInfo; } MOUSEMOVEPOINT, *PMOUSEMOVEPOINT, *LPMOUSEMOVEPOINT; [PInvokeData("winuser.h", MSDNShortId = "")] [StructLayout(LayoutKind.Sequential)] public struct MOUSEMOVEPOINT { /// /// Type: int /// The x-coordinate of the mouse. /// public int x; /// /// Type: int /// The y-coordinate of the mouse. /// public int y; /// /// Type: DWORD /// The time stamp of the mouse coordinate. /// public uint time; /// /// Type: ULONG_PTR /// Additional information associated with this coordinate. /// public IntPtr dwExtraInfo; } /// /// Used by the TrackMouseEvent function to track when the mouse pointer leaves a window or hovers over a window for a specified /// amount of time. /// [PInvokeData("Winuser.h", MSDNShortId = "ms645604")] [StructLayout(LayoutKind.Sequential)] public struct TRACKMOUSEEVENT { /// The size of the TRACKMOUSEEVENT structure, in bytes. public uint cbSize; /// The services requested public TME dwFlags; /// A handle to the window to track. public HWND hwndTrack; /// /// The hover time-out (if TME_HOVER was specified in dwFlags), in milliseconds. Can be HOVER_DEFAULT, which means to use the /// system default hover time-out. /// public uint dwHoverTime; } } }