C # simulate window operation with the mouse | winapi

Source: Internet
Author: User

 

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.