| View previous topic :: View next topic |
| Author |
Message |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sat Jan 26, 2008 7:33 am Post subject: C# mouse position help |
|
|
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 |
|
 |
the_undead Expert Cheater
Reputation: 1
Joined: 12 Nov 2006 Posts: 235 Location: Johannesburg, South Africa
|
Posted: Sat Jan 26, 2008 8:05 am Post subject: |
|
|
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 |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sat Jan 26, 2008 8:20 am Post subject: |
|
|
I thought that Cursor.Position.X was read-only. o__O
_________________
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sat Jan 26, 2008 8:24 am Post subject: |
|
|
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 |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sat Jan 26, 2008 8:30 am Post subject: |
|
|
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);
}
|
_________________
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sat Jan 26, 2008 11:05 am Post subject: |
|
|
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 |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sat Jan 26, 2008 11:12 am Post subject: |
|
|
Oh yeah, I forgot:
add this to your "using" list:
| Code: |
using System.Runtime.InteropServices;
|
_________________
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sat Jan 26, 2008 11:22 am Post subject: |
|
|
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 |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Sat Jan 26, 2008 11:28 am Post subject: |
|
|
| samurai, you can do Cursor.Position = new Point(uint X, uint Y);
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sat Jan 26, 2008 11:41 am Post subject: |
|
|
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.
_________________
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sat Jan 26, 2008 11:52 am Post subject: |
|
|
Uhh...
Paste in the methods, paste in all the imports and just do like this:
So like:
| Code: |
Mouse.Cursor.Position = new Point(x,y);
LClick();
|
_________________
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sat Jan 26, 2008 12:03 pm Post subject: |
|
|
thx alot but.. if i turn it one more than 1 time the number of mouse clicking is increasing?
_________________
Stylo |
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Sat Jan 26, 2008 12:19 pm Post subject: |
|
|
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 |
|
 |
|