Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,062 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,186 people online right now. Registration is fast and FREE... Join Now!




mouse click

 
Reply to this topicStart new topic

mouse click, how to do left/right click with c++

saravt
post 5 Mar, 2008 - 11:35 PM
Post #1


New D.I.C Head

*
Joined: 5 Mar, 2008
Posts: 3

I want to do automate the mouse clicks with c++, can anyone help on this...

Thanks,
Sarav...
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 5 Mar, 2008 - 11:39 PM
Post #2


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,324



Thanked 57 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


You can check the MSDN for documentation on the windows messaging API.

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

code.gif
User is offlineProfile CardPM

Go to the top of the page

saravt
post 6 Mar, 2008 - 12:38 AM
Post #3


New D.I.C Head

*
Joined: 5 Mar, 2008
Posts: 3

QUOTE(no2pencil @ 6 Mar, 2008 - 12:39 AM) *

You can check the MSDN for documentation on the windows messaging API.

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

code.gif



Ya thanks i tried it already and this is the code i used

CODE

//Sends a mouse click
void SendClick(int dX, int dY)
    {
    if (iClickType == MOUSEEVENTF_RIGHTCLICK) {
        mouse_event(MOUSEEVENTF_RIGHTDOWN, dX, dY, NULL, GetMessageExtraInfo());
        mouse_event(MOUSEEVENTF_RIGHTUP, dX, dY, NULL, GetMessageExtraInfo());
        }
    else if (iClickType == MOUSEEVENTF_LEFTCLICK) {
        mouse_event(MOUSEEVENTF_LEFTDOWN, dX, dY, NULL, GetMessageExtraInfo());
        mouse_event(MOUSEEVENTF_LEFTUP, dX, dY, NULL, GetMessageExtraInfo());
    }
}

VOID mouse_event(

   DWORD dwFlags, // flags specifying various motion/click variants
   DWORD dx, // horizontal mouse position or position change
   DWORD dy, // vertical mouse position or position change
   DWORD dwData, // amount of wheel movement
   DWORD dwExtraInfo  // 32 bits of application-defined information
  );


and i called the function as SendClick(MOUSEEVENTF_RIGHTCLICK, 10, 10)

but for this its giving error as 'MOUSEEVENTF_RIGHTCLICK' undefined(first use this funtion)

Thats why strucked...

Can you help on this now...

This post has been edited by saravt: 6 Mar, 2008 - 12:49 AM
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 6 Mar, 2008 - 12:52 AM
Post #4


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,324



Thanked 57 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


1st, please use code tags (as previously requested)

2nd, You are passing MOUSEEVENTF_RIGHTCLICK as an argument... what is it's value? That's why are you getting the undefined error. It doesn't mean anything, because it doesn't have a value. It doesn't exist.

CODE

#define MOUSEEVENTF_RIGHTCLICK 0

Would be one way to define it, but it probably wouldn't produce the results that you are looking for.

Furthermore, since you only posted one function, I can only assume (or hope) that you used included Winuser.h or Windows.h for the mouse_event function. Having a look at the MSDN tells us that MOUSEEVENTF_RIGHTDOWN is probably what you are looking for. I don't see MOUSEEVENTF_RIGHTCLICK anywhere on this page. Where did you get this code from that you posted here? Why are you using MOUSEEVENTF_RIGHTCLICK?

Also, please have a look at SendInput
User is offlineProfile CardPM

Go to the top of the page

saravt
post 6 Mar, 2008 - 01:28 AM
Post #5


New D.I.C Head

*
Joined: 5 Mar, 2008
Posts: 3

Actually i want to do some click operations so i m trying that with that code. And i already went through the things which you specified but i couldn't find any examples in that, so i did a search with that key words and from a forum i got that code. But now that code is giving error as

undefined X and Y for that dX and dY.

Even that SendInput doesn't have any examples, and i m trying to solves my issues.
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 6 Mar, 2008 - 01:36 AM
Post #6


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,324



Thanked 57 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


QUOTE(saravt @ 6 Mar, 2008 - 01:38 AM) *

CODE

VOID mouse_event(

   DWORD dwFlags, // flags specifying various motion/click variants
   DWORD dx, // horizontal mouse position or position change
   DWORD dy, // vertical mouse position or position change
   DWORD dwData, // amount of wheel movement
   DWORD dwExtraInfo  // 32 bits of application-defined information
  );



This isn't just copy-n-paste code... it's a descriptive layout.

the function is called mouse_event, & the 1st argument that it can take is dwFlags. Then there is a description about what dwFlags is...
The same goes for all of the arguments, they are described as to how to use this function.

1st page Google results : http://ooo.ayolo.info/wiki/doku.php?id=mouse_event shows a great example of how to use this function.

I really wish you luck with this project... I don't know how much programming experience that you have, but you can't just grab *something* off the web & plug it into your project & hope that it works. A lot of reading is required...
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/21/08 07:05AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month