Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Invisible Mouse Clicks .Net

Name: Anonymous 2010-01-19 18:30

So I already know how to simulate mouse clicks, but I was wondering if there was a way to simulate a click without the actual cursor. The user can keep moving their mouse while the program simulated mouse clicks somewhere else.
Code in vb.net or C#.net appreciated.

Name: Anonymous 2010-01-19 18:37

>>1
You have to understand the underlying OS to do that.
On Win32, a mouse click is the same as a message sent to a window, which means you can fake it (it would be the same as a real one) by doing a SendMessage call with the parameters set properly (hWnd to the target window, Msg = WM_LBUTTONDOWN (or appropriate, look them up in MSDN):

WM_LBUTTONDOWN
fwKeys = wParam;        // key flags
xPos = LOWORD(lParam);  // horizontal position of cursor
yPos = HIWORD(lParam);  // vertical position of cursor


Doing it in C# or any other language would mean using the FFI or calling it directly. For C#, you need to write a p/invoke import for SendMessage.

btw, /prog/ isn't a place for asking questions that can be easily googlable.

Name: Anonymous 2010-01-19 18:41

super pseudo code, but you get the gist


function click(targetx,targety){
    tempx = GetMouseX();
    tempy = GetMouseY();
   
    SetMouseX(targetx);
    SetMouseY(targety);
   
    ClickMouse();
   
    SetMouseX(tempx);
    SetMouseY(tempy);
}


Something like this should be fast enough that the user won't notice anything.

Name: >>2 2010-01-19 18:42

>>3
That's silly. Why change the mouse position when you can have the OS send a real mouse click message which doesn't interfere with what the user is doing.

Name: Anonymous 2010-01-19 18:50

New MouseClicker m
m.BLAHBLAHClickfuckhaxmyanus(CUDDER CAR)

Name: Anonymous 2010-01-19 18:53

>>5
What's your problem?

Name: Anonymous 2010-01-19 19:09

Can't say I care about the topic, but thanks at least for creating a relevant thread. Best of luck solving it.

Name: Anonymous 2010-01-19 19:26

>Code in vb.net or C#.net

I just threw up in my mouth.

Name: Anonymous 2010-01-19 19:29

>>3
I've done something like this already, but I need something that doesn't interfere with the user.
>>2
Thanks.

Name: Anonymous 2010-01-19 19:32

>>2
I wouldn't suppose you have that google link would you?

Name: >>2 2010-01-19 19:44

>>10
I just thought how I would do it and wrote it down, but this seems like a common task, so you should be able to find info about it on google, here, let me google that for you:

http://www.google.com/search?q=simulating+mouse+click+in+c%23
First hit being: http://www.gamedev.net/community/forums/topic.asp?topic_id=321029 ... This doesn't use SendMessage, but mouse_event which is similar.
However, it seems that function is deprecated:
Windows NT: This function has been superseded. Use SendInput instead.
Searching for "simulating mouse click in c# SendMessage"
gives http://www.geekpedia.com/code139_Simulate-Mouse-Click-On-WebBrowser-Control.html which shows a more proper solution w/ p/invoke and SendMessage. This is really trivial stuff that can be found on google.

Name: Anonymous 2010-01-19 19:45

>>6
I have many

Name: Anonymous 2010-01-20 2:03

just so you know OP, it may have been a trivial google, but i was actually interested in hearing the solution.

Name: Anonymous 2011-02-04 17:02


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List