Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C# mouse position help
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sat Jan 26, 2008 7:33 am    Post subject: C# mouse position help Reply with quote

how can i set the mouse position while my form is running of cours
and what is the command to make the mouse click on the left button
can u guys give me the code for it please?

_________________
Stylo
Back to top
View user's profile Send private message
the_undead
Expert Cheater
Reputation: 1

Joined: 12 Nov 2006
Posts: 235
Location: Johannesburg, South Africa

PostPosted: Sat Jan 26, 2008 8:05 am    Post subject: Reply with quote

SetCursorPos.
Not sure if there is a managed API for it though. So you'll have to use P/INVOKE to import.

_________________
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sat Jan 26, 2008 8:08 am    Post subject: Reply with quote

oh thanks it wasnt exectly that command it was curoser.position.x but thx anyway Smile
_________________
Stylo
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sat Jan 26, 2008 8:20 am    Post subject: Reply with quote

I thought that Cursor.Position.X was read-only. o__O
_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sat Jan 26, 2008 8:24 am    Post subject: Reply with quote

yea now that ur saying it is.. but i fixed it now it's Cursor.Position = new Point(x,y);

btw how do i send a mouse click through my form??

_________________
Stylo
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sat Jan 26, 2008 8:30 am    Post subject: Reply with quote

I've had a lot of trouble with that.

If you want to emulate a mouse click to your form, you might just call your button event with null, null as the parameters (I never seem to need the "object sender" or "EventArgs e". If you wanna get low-level (note that you have to do this for other forms), then you can import mouse_event from user32.dll:

Code:

    [Flags]
    public enum MouseEventFlags : uint
    {
       LEFTDOWN   = 0x00000002,
       LEFTUP     = 0x00000004,
       MIDDLEDOWN = 0x00000020,
       MIDDLEUP   = 0x00000040,
       MOVE       = 0x00000001,
       ABSOLUTE   = 0x00008000,
       RIGHTDOWN  = 0x00000008,
       RIGHTUP    = 0x00000010
    }

    [DllImport("user32.dll")]
    public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, int dwExtraInfo);


And call it like this:

Code:

    public static void LClick()
    {
       mouse_event((uint)MouseEventFlags.LEFTDOWN,0,0,0,0);
       Pause(150); //Give it time to understand it
       mouse_event((uint)MouseEventFlags.LEFTUP,0,0,0,0);
       Pause(100);
    }

    public static void Pause(int val)
    {
                    System.Threading.Thread.Sleep(val);
    }

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sat Jan 26, 2008 11:05 am    Post subject: Reply with quote

i'm getting an error with the line
Code:

[DllImport("user32.dll")]

The type or namespace name 'DllImport' could not be found (are you missing a using directive or an assembly reference?)

_________________
Stylo
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sat Jan 26, 2008 11:12 am    Post subject: Reply with quote

Oh yeah, I forgot:

add this to your "using" list:

Code:

using System.Runtime.InteropServices;

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sat Jan 26, 2008 11:22 am    Post subject: Reply with quote

ok it is ok now.. how do i use it now if i wanna make the mouse click for me one time ?
_________________
Stylo
Back to top
View user's profile Send private message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Sat Jan 26, 2008 11:28 am    Post subject: Reply with quote

samurai, you can do Cursor.Position = new Point(uint X, uint Y);
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sat Jan 26, 2008 11:41 am    Post subject: Reply with quote

Thanks Symbol.

@OP:

That does click once:

It "pushes" the left mouse button down, waits 150 milliseconds, then "lets go" of the left mouse button, emulating a click.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sat Jan 26, 2008 11:49 am    Post subject: Reply with quote

can u tell me please how to use it in my form Crying or Very sad
_________________
Stylo
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sat Jan 26, 2008 11:52 am    Post subject: Reply with quote

Uhh...

Paste in the methods, paste in all the imports and just do like this:

Code:

LClick();


So like:

Code:

Mouse.Cursor.Position = new Point(x,y);
LClick();

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sat Jan 26, 2008 12:03 pm    Post subject: Reply with quote

thx alot but.. if i turn it one more than 1 time the number of mouse clicking is increasing?
_________________
Stylo
Back to top
View user's profile Send private message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Sat Jan 26, 2008 12:19 pm    Post subject: Reply with quote

for (int i = 0; i < nOfClicks; i++)
LClick();

or

void LClick(int nOfTimesToClick)
{
for (int i = 0; i < nOfTimesToClick; i++)
{
mouse_event((uint)MouseEventFlags.LEFTDOWN,0,0,0,0);
Pause(10);
mouse_event((uint)MouseEventFlags.LEFTUP,0,0,0,0);
Pause(10);
}
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites