简体   繁体   中英

Mouse click on a background window without moving mouse c++

I need to know if there is a code in c++ that allows to simulate a click, on a background window (if that's impossible, a foreground window will do fine), without moving the mouse.

I also need to click on specific coordinates, and drag an item to some other position (always without moving the mouse).

Example:
my mouse pointer is at (500,700),
but i need to left click at (100,150),
and drag to (700,300).

I need to be able to move my mouse pointer without affecting the program, and the program must run correctly without moving, or locking, the mouse pointer.

If this action is impossible in c++, a VB code will be apreciated.

From a C++ Windows application, you can call Windows API directly by first finding the window using FindWindow that will give you the window handle you want, then finding the area within this window that you want to click. You can use API like GetWindowRect for this. Finally, you can send this window, or an area within it, mouse messages using mouse_event function to cause the mouse to move, click, drag and let go at a new location.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM