View Code [DllImport ("user32.dll", EntryPoint = "mouse_event", SetLastError = true)]
Private static extern int mouse_event (int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo );
Const int MOUSEEVENTF_MOVE = 0x0001; // move the mouse
Const int MOUSEEVENTF_LEFTDOWN = 0x0002; // simulate the left mouse button to press
Const int MOUSEEVENTF_LEFTUP = 0x0004; // simulate left mouse button lifting
Const int MOUSEEVENTF_RIGHTDOWN = 0x0008; // right-click the mouse and press
Const int MOUSEEVENTF_RIGHTUP = 0x0010; // right-click the mouse to raise the mouse
Const int MOUSEEVENTF_MIDDLEDOWN = 0x0020; // simulate the mouse key and press
Const int MOUSEEVENTF_MIDDLEUP = 0x0040; // simulate middle mouse button lifting
Const int MOUSEEVENTF_ABSOLUTE = 0x8000; // indicates whether absolute coordinates are used
Static void Main (string [] args)
{
// Move the mouse
Mouse_event (MOUSEEVENTF_MOVE, 400, 0, 0, 0 );
// Right-click
Mouse_event (MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 410, 0, 0 );
Console. ReadLine ();
}
You can perform secondary encapsulation on the system API during the call.
Public Static Void MouseRightClick ()
{
// Right-click
Mouse_event (MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 410, 0, 0 );
}
Applicable scenarios: If you want to use LinkButton to pop up a right-Click menu, you can use the Click Event API to simulate a right-Click event.