By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,382 Members | 1,623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,382 IT Pros & Developers. It's quick & easy.

simulate mouse movements and click operations in c#

P: 6
Hi.
How to simulate(automatic) mouse movements and click operation using c#.
Actually, i got pixels in the face (face tracking) right now and i need to move mouse(automatically, without using mouse manually) i.e., simulate mouse click operation using those pixels in c#.
I think we can use robot() class in java , to achieve this, but how can we do this using c#.
Hope you understand my problem and get bck to me asap.


thanx
bye
Jun 14 '06 #1
Share this Question
Share on Google+
3 Replies


P: 1
Hi.
How to simulate(automatic) mouse movements and click operation using c#.
Actually, i got pixels in the face (face tracking) right now and i need to move mouse(automatically, without using mouse manually) i.e., simulate mouse click operation using those pixels in c#.
I think we can use robot() class in java , to achieve this, but how can we do this using c#.
Hope you understand my problem and get bck to me asap.


thanx
bye

Have find the solution of your problem.
Actually i am facing the same problem now a days.
Pls tell me if you find the solution.
My email id is khaleek_ahmad@yahoo.com
Thanks in Advance
Mar 6 '07 #2

P: 1
using System;
using System.Runtime.InteropServices;
...


// usingAPI for mouse governing and other possibilities

#region Подключение API для управления мышкой и других возможностей



enum Messages{WM_LBUTTONDOWN = 0x0201, WM_LBUTTONUP = 0x0202};
const int MK_LBUTTON = 0x0001;
[DllImport("User32.dll")]
static extern int SendMessage(IntPtr hWnd, Messages uMsg, int wParam, IntPtr lParam);

//импортируем mouse_event():
[DllImport("User32.dll")]
static extern void mouse_event(MouseFlags dwFlags, int dx, int dy, int dwData, UIntPtr dwExtraInfo);
//для удобства использования создаем перечисление с необходимыми флагами (константами), которые определяют действия мыши:
//as a matter of convenience, use create enumeration with necessary flags (constants), which define actions of mouse:

[Flags]
enum MouseFlags
{
Move = 0x0001, LeftDown = 0x0002, LeftUp = 0x0004, RightDown = 0x0008,
RightUp = 0x0010, Absolute = 0x8000};
/// <summary>
/// Кликнуть в какомто месте экрана
///Click In some place of screen
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
private void TestMouse(int x, int y)
{

mouse_event(MouseFlags.Absolute | MouseFlags.Move, x, y, 0, UIntPtr.Zero);
mouse_event(MouseFlags.Absolute | MouseFlags.LeftDown , x, y, 0, UIntPtr.Zero);
mouse_event(MouseFlags.Absolute | MouseFlags.LeftUp, x, y, 0, UIntPtr.Zero);

}



#endregion
Mar 6 '07 #3

JOHNYKUTTY
P: 10
Hai friend,
use the code below to simulate mouse click
Expand|Select|Wrap|Line Numbers
  1. using System.Runtime.InteropServices;
  2.  
  3. private const UInt32 MOUSEEVENTF_LEFTDOWN = 0x0002;
  4. private const UInt32 MOUSEEVENTF_LEFTUP = 0x0004;
  5. [DllImport("user32.dll")]
  6.         private static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, uint dwExtraInf);
  7. private void btnSet_Click(object sender, EventArgs e)
  8.         {
  9.             int x = Convert.ToInt16(txtX.Text);//set x position 
  10.             int y = Convert.ToInt16(txtY.Text);//set y position 
  11.             Cursor.Position = new Point(x, y);
  12.             mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);//make left button down
  13.             mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);//make left button up
  14.         }
  15.  
txtX is a text box to set x position of cursor
txtY is a text box to set y position of cursor
btnSet is a a button
when yo clicks on the button btnset the cursor will move to the position specified in two text boxes(txtX & txtY)
Jan 3 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.