A mouse class (Using C # and Win32API)

xiaoxiao2021-03-06  107

Author: Internet Prodigal Source: Network

namespace ClassLibrary.Hardware {// original Using C # and Win32API (I recently saw a Win32API all times was very enjoyable) public class Mouse {internal const byte SM_MOUSEPRESENT = 19; internal const byte SM_CMOUSEBUTTONS = 43; internal const byte SM_MOUSEWHEELPRESENT = 75; internal struct POINTAPI {internal int x; internal int y;} internal struct RECT {internal int left; internal int top; internal int right; internal int bottom;} [System.Runtime.InteropServices.DllImport ( "user32.dll" , EntryPoint = "SwapMouseButton")] internal extern static int SwapMouseButton (int bSwap); [System.Runtime.InteropServices.DllImport ( "user32", EntryPoint = "ClipCursor")] internal extern static int ClipCursor (ref RECT lpRect); [ System.Runtime.InteropServices.DllImport ( "user32.dll", EntryPoint = "GetCursorPos")] internal extern static int GetCursorPos (ref POINTAPI lpPoint); [System.Runtime.InteropServices.DllImport ( "user32.dll", EntryPoint = " Showcursor ")] INTERNAL EXTERN Static Bool Showcursor (BOO l bShow); [System.Runtime.InteropServices.DllImport ( "user32.dll", EntryPoint = "EnableWindow")] internal extern static int EnableWindow (int hwnd, int fEnable); [System.Runtime.InteropServices.DllImport ( "user32 .dll ", EntryPoint =" GetWindowRect ")] internal extern static int GetWindowRect (int hwnd, ref RECT lpRect); [System.Runtime.InteropServices.DllImport (" user32.dll ", EntryPoint =" SetCursorPos ")] internal extern static INT setCursorpos (int X, int y); [System.Runtime.InteropServices.dllimport ("User32.dll", entrypoint = "getSystemMetrics"

)] Internal extern static int GetSystemMetrics (int nIndex); [System.Runtime.InteropServices.DllImport ( "user32.dll", EntryPoint = "SetDoubleClickTime")] internal extern static int SetDoubleClickTime (int wCount); [System.Runtime.InteropServices .DllImport ( "user32.dll", EntryPoint = "GetDoubleClickTime")] internal extern static int GetDoubleClickTime (); [System.Runtime.InteropServices.DllImport ( "kernel32.DLL", EntryPoint = "Sleep")] internal extern static void Sleep (int dwmilliseconds); // Get the coordinates of the mouse and full screen, not relative to your form, and related to your resolution public static int fullscreenposition_x {get {pointapi _pointapi = new pointapi (); getCursorpos (Ref _POINTAPI); return _POINTAPI.x;}} public static int FullScreenPosition_Y {get {POINTAPI _POINTAPI = new POINTAPI (); GetCursorPos (ref _POINTAPI); return _POINTAPI.y;}} // hide display mouse public static void Hide () { Showcursor (false);} public static void show () {showcursor (true);} // lock the mouse in your F ORM but you have to lock your FORM, form resize invalid public static void lock (system.windows.forms.form {rect _formRect = new reference (); getWindowRect (Objectform.handle.Toint32 () , ref _FormRect); ClipCursor (ref _FormRect);} public static void UnLock () {RECT _ScreenRect = new RECT (); _ScreenRect.top = 0; _ScreenRect.left = 0; _ScreenRect.bottom = System.Windows.Forms.Screen .PrimaryScreen.workingarea.bottom; _screenRect.right = system.windows.forms.screen.primaryScreen.workingarea.right; clipcursor (Ref _ScreenRect);

} // mouse failed, but it seems that it is not just a mouse, be careful. Public static void disable (system.windows.forms.form Objectform) {enableWindow (Objectform.handle.Toint32 (), 0);} public static void enable System.Windows.Forms.form Objectform) {enableWindow (Objectform.handle.Toint32 (), 1);} // mouse yourself to move very much Wipe the face. . .

Anyway, I wrote when dizziness public static void Move (int From_Handle_ToInt32, int To_Handle_ToInt32) {RECT rectFrom = new RECT (); RECT rectTo = new RECT (); int i; GetWindowRect (From_Handle_ToInt32, ref rectFrom); GetWindowRect (To_Handle_ToInt32, ref RectTo; if (RectFrom.right) / 2 - (RectTo.Left RectTo.Right) / 2> 0) {for (i = (RectFrom.Left RectFrom.right) / 2; i> = (RectTo.Left RectTttto.right) / 2; I -) {setCursorpos (i, (RectFrom.Top RectFrom.Bottom) / 2); Sleep (1);}} else {for (i = (RectFrom) .left rectFrom.right) / 2; i <= (RectTttto.right) / 2; i ) {setCursorpos (i, (RectFrom.top RectFrom.Bottom) / 2); SLEEP (1); }}}} ((RectFrom.Top RectFrom.bottom) / 2 - (RectTo.top RectTo.Bottom) / 2> 0) {for (i = (RectFrom.Top RectFrom.Bottom) / 2; i> = (RectTo.top RectTo.Bottom) / 2; I -) {setcursorpos ((RectTo.Left RECTTO.RIGHT / 2, I); SLEEP (1);}} else {for (i = (RectFrom.Top RectFrom.Bottom) / 2; i <= (RectTtTtTttttto.TtTOM) / 2; i ) {setCursorpos ((RectTo.Left RectTtto.right) / 2, i); Sleep (1);}}} // Get your mouse type public static string type {get {ix (getSystemMetrics) == 0) {RETURN "This computer has not been installed";} else {ix (getSystemMeElPresent! = 0) {Return getSystemMetrics (SM_CMOUSEBUTTONS) "Key Wheel Mouse";

转载请注明原文地址:https://www.9cbs.com/read-101144.html

New Post(0)