Is there any command to move/click the mouse?
And to simulate a key press?
Any other coding methods would be appreciated also.
E. Chabot
Printable View
Is there any command to move/click the mouse?
And to simulate a key press?
Any other coding methods would be appreciated also.
E. Chabot
BOOL SetCursorPos(x,y)
to move the mouse.
I don't know how to simulate a key press or click the mouse.
See SendInput in MSDN.
Hi,
use SendMessage or PostMessage API.
Regards
MJV
I figured out how to send mouse clicks and keyboard presses with SendInput():
but this code will only compile if you have (at least) these defined:Code://mouse input
INPUT input;
input.type=INPUT_MOUSE;
MOUSEINPUT mouseInput;
mouseInput.dx=0;
mouseInput.dy=0;
mouseInput.mouseData=NULL;
mouseInput.dwFlags=MOUSEEVENTF_LEFTDOWN;
mouseInput.time=0;
mouseInput.dwExtraInfo=0;
input.mi=mouseInput;
if(!::SendInput(1,&input,sizeof(input)))
{
AfxMessageBox(_T("Error sending input."));
}
//(Unicode) keyboard input
INPUT inputKey;
inputKey.type=INPUT_KEYBOARD;
KEYBDINPUT keyInput;
keyInput.wVk=0;
keyInput.wScan=_T('a');
keyInput.dwFlags=KEYEVENTF_UNICODE;
keyInput.time=0;
keyInput.dwExtraInfo=0;
inputKey.ki=keyInput;
if(!::SendInput(1,&inputKey,sizeof(inputKey)))
{
AfxMessageBox(_T("Error sending input."));
}
Looks like we took about 5 years to respond! :)Code:#define _WIN32_WINNT 0x0500 //define windows version to "Windows 2000"
#define WINVER 0x0500 //define windows version to "Windows 2000"
Yep, SendInput is an answer.
How did you get to this post and answer it in the first place?Quote:
Originally Posted by me earlier
I have not noticed OP date.
Oh man.. This sounds like a message in a bottle arriving after eons ;)
I did a search for this question because I didn't know the answer. Then I decided to post because I knew the answer to one of the questions. Yeah, the bottle has finally been found! :lol:
I know that you posted SendInput earlier JohnCz. I just think that it will be easier for someone who finds this post from a search engine to just copy and paste my code, rather than go to MSDN, learn everything about INPUT, MOUSEINPUT, and KEYBDINPUT and learn about all of their parameters and write all of that code. Next time I will write "As suggested by JohnCz, I've written the following code that employs SendInput..." :) Oops I looked at my post and sorry about the way I started off. :)
I really do not care about that. I quoted it to show that I fully agree with your post.Quote:
Originally Posted by MartyP
If I wrote a code as you did I would probably care more.