Skip to main content
gamedev.net
🔒 Locked

Basic mouse manipulation in c++ help

Started by Pav Apr 4, 2005 at 1:09 PM 10 replies 2.7k views
Original Post
Pav
Pav
hey guys... i need help with something. i'm building an app in visual c++ and i need to know how to make my app actually move the mouse curson from position to position and "make" it left click. i thought to do it with sending a message to the message loop, but i wanted to check with you guys as to how to do it, just to be sure. thanx.
Evil Steve
Evil Steve
You can move the mouse with the SetCursorPos function. I'm not sure about how you'd make it click. If this is for your own app, I can't see any harm in posting a message in the message loop. If it's for another, you might have some issues, but you can still give it a go.
Jingo
Jingo
SendInput can be used to generate mouse clicks.
Pav
Pav
ok, thanx a lot guys :)

1 more little question. how do i star another program and set the focus to it from within c++?

like if i want to execute c:\something.exe from within my app, and make it be in focus so i can use the mouse conrol on it?
Qw3r7yU10p!
Qw3r7yU10p!
What are you trying to do, specifically?
Pav
Pav
i have a program which has no automated controls.
this program changes various things in my comp, but i have to click in that program to make the changes.

so i want to make a program which automatically launches the other prog, clicks a few things in it, types a few things in it, and then closes that program at acertain time interval, like every 12 hours.
Evil Steve
Evil Steve
Quote:
Original post by Pav
ok, thanx a lot guys :)

1 more little question. how do i star another program and set the focus to it from within c++?

like if i want to execute c:\something.exe from within my app, and make it be in focus so i can use the mouse conrol on it?
ShellExecute is what you're after.
Pav
Pav
thanx a lot :)
Pav
Pav
ok, i wrote a simple prog just to test the function (console app) :

#include "windows.h"

void main()
{
INPUT mouseInput;
mouseInput.type = INPUT_MOUSE;
mouseInput.mi.dx = 10;
mouseInput.mi.dy = 10;

SendInput(1, &mouseInput, sizeof(mouseInput));
}

it fails to compile and says : "error C2065: 'INPUT' : undeclared identifier"

but it does know what INPUT is. it gave me context menus when i defined the mouseInput. stuff...

what does this mean?
Pav
Pav
nevermind. i had to add #define _WIN32_WINNT 0x0501 before including Windows.h.
DigitalDelusion
DigitalDelusion
If you want to click some buttons and enter text I would adivce you to simply use Spy++ it you have that availbile to get the ID's of the desiered controls and then simply send the messages directly. I did a hack like this to get rid of the silly password prompt from tortoise cvs, simply I did a program that ran in the background checking if the tortoisecvs password window was displayed and if it was it simply enterd my login information and hit enter.

Saved me loads of time with very little effort.

Good luck with your program.
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
Qw3r7yU10p!
Qw3r7yU10p!
Quote:
Original post by Pav
i have a program which has no automated controls.
this program changes various things in my comp, but i have to click in that program to make the changes.

Does it have any command line options?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.