|
-
January 19th, 2000, 12:27 PM
#1
Key Press or Mouse Click/Movement
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
-
September 1st, 2005, 08:45 PM
#2
Re: Key Press or Mouse Click/Movement
BOOL SetCursorPos(x,y)
to move the mouse.
I don't know how to simulate a key press or click the mouse.
-
September 2nd, 2005, 12:54 AM
#3
Re: Key Press or Mouse Click/Movement
There are only 10 types of people in the world:
Those who understand binary and those who do not.
-
September 2nd, 2005, 02:10 AM
#4
Re: Key Press or Mouse Click/Movement
Hi,
use SendMessage or PostMessage API.
Regards
MJV
-
September 2nd, 2005, 12:00 PM
#5
Re: Key Press or Mouse Click/Movement
I figured out how to send mouse clicks and keyboard presses with SendInput():
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."));
}
but this code will only compile if you have (at least) these defined:
Code:
#define _WIN32_WINNT 0x0500 //define windows version to "Windows 2000"
#define WINVER 0x0500 //define windows version to "Windows 2000"
Looks like we took about 5 years to respond!
-
September 2nd, 2005, 01:33 PM
#6
Re: Key Press or Mouse Click/Movement
Yep, SendInput is an answer.
 Originally Posted by me earlier
See SendInput in MSDN.
How did you get to this post and answer it in the first place?
I have not noticed OP date.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
-
September 2nd, 2005, 01:38 PM
#7
Re: Key Press or Mouse Click/Movement
Oh man.. This sounds like a message in a bottle arriving after eons
-
September 2nd, 2005, 02:45 PM
#8
Re: Key Press or Mouse Click/Movement
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!
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.
-
September 2nd, 2005, 03:37 PM
#9
Re: Key Press or Mouse Click/Movement
 Originally Posted by MartyP
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.
If I wrote a code as you did I would probably care more.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|