Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Win API Mouse Output

Status
Not open for further replies.

olie

Programmer
Aug 21, 2002
9
US
I am working on special Artificial Intelligence program that interfaces with other programs. In order to do so, I need the program to control the mouse, which can easily be done with setcursorpos() and the other cursor functions. However, i do not know how to make the program left click and right click on other windows as you would normally with a mouse. If anyone knows how to perform this action with Win API or even with C++, please drop the message.
 
To simulate a click you can post 2 messages: WM_LBUTTONDOWN, WM_LBUTTONUP to a window's message queue. It can look something like this:
Code:
  PostMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(xPos, yPos));
  PostMessage(hwnd, WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(xPos, yPos));
xPos, yPos are coordinates in your window.

--- markus
 
Hey thanks a lot. I figured it out. However, I used a different approach. I used the SendInput function to send a mouse simulated input to the window. Now, however, I face a new problem. The SendInput function also works with keyboard simulations, but I tried many times and it doesn't work. There must be a flaw in the code somwhere. Here is a copy of my code which involves the keyboard input simulation.



typedef struct tagKEYBDINPUT {
WORD wVk;
WORD wScan;
DWORD dwFlags;
DWORD time;
ULONG_PTR dwExtraInfo;
} KEYBDINPUT, *PKEYBDINPUT;
KEYBDINPUT kinp;
kinp.wVk = 0x1B;
kinp.dwFlags = NULL;
kinp.wScan = 27;
kinp.time = 0;
kinp.dwExtraInfo = NULL;
typedef struct tagINPUT {
DWORD type;
KEYBDINPUT kinp;
}INPUT, *PINPUT;
INPUT inp;
inp.type = INPUT_KEYBOARD;
UINT send=SendInput( 1,
(LPINPUT(&inp)),
sizeof(inp)
);


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top