Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi friends
i am working with aforge.net and VS2010 , to develop an application that
* get frames from webcam
* apply some aforge.net functions and get location of colored object infront of the cam.
* uses this object's location to move cursor, and after i shall use some technique to perform click operations.

i have done much work with it and application can move cursor in desktop explorer and browser etc, even when my application is inactive. for example when my application is minimized it still track the object and moves the pointer.

but problem is that when i run any game like VCOP2 etc then my application dont controll pointer.
plz help me to intract with the game aswell.

i have tried following two methods to move mouse pointer.
1:
Cursor.Position= (any point)

2:
C#
[System.Runtime.InteropServices.DllImport("user32.dll")]
        static extern bool SetCursorPos(int x, int y);
SetCursorPos(xpos, ypos);
Posted
Comments
Member 8973214 27-Feb-13 12:20pm    
the application should work like a pointing device.. for instance the application sends a point(x,y) to OS to move the mouse pointer at this location. so that the pointer will move by the application even in the games.
Sergey Alexandrovich Kryukov 27-Feb-13 14:41pm    
Then I turned out to be a pretty interesting question. Thank you for clarification.
—SA
Member 8973214 28-Feb-13 11:05am    
thanks for your time.

1 solution

Oh, no! You don't need to use P/Invoke as you do. You can use System.Windows.Forms.Cursor for this purpose:
http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.aspx[^].

Note that it's bad to use P/Invoke unless it's absolutely unavoidable, because it totally kills your platform compatibility.

[EDIT]

I recognize the problem if this API is not working. I explained the possible problem: there is a number of big incompatibilities between older GDI API and DirectX.

Then I have a different idea: instead of manipulating the mouse cursor, simulate mouse input by the function SendInput:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^].

Here, you unfortunately need to use P/Invoke, but you don't need to write it by yourself; it's already done for you:
http://www.pinvoke.net/default.aspx/user32.sendinput[^].

I tested it: it works very reliably. Actually, this is a low-level input, close to what is used by the hardware driver. You simulate input as it came from hardware, something you probably wanted to have in first place.

Please try it out and give me your feedback. You see, I never use any games, so I would like to here from you if you can solve this problem.

—SA
 
Share this answer
 
v2
Comments
Espen Harlinn 7-Feb-13 18:32pm    
Good advice :-D
Sergey Alexandrovich Kryukov 7-Feb-13 18:35pm    
Thank you, Espen.
—SA
Member 8973214 27-Feb-13 12:01pm    
thanks SA, sorry for inactivity , it was due to unavailability of internet service.
I am going to try your suggestion.
Member 8973214 27-Feb-13 12:22pm    
Sir SAK , I visited your suggested link but I did not get there that how to move pointer in the games. I need more help. any implemented example if you provide plz, which shows how to move mouse pointer?
Sergey Alexandrovich Kryukov 27-Feb-13 13:10pm    
Did you ask about setting cursor position? It tells you how to do it, doesn't it?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900