simulate mouse movements and click operations in c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madhuri.eerupula
    New Member
    • Jun 2006
    • 6

    simulate mouse movements and click operations in c#

    Hi.
    How to simulate(automa tic) mouse movements and click operation using c#.
    Actually, i got pixels in the face (face tracking) right now and i need to move mouse(automatic ally, 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
  • khaleek
    New Member
    • Mar 2007
    • 1

    #2
    Originally posted by madhuri.eerupul a
    Hi.
    How to simulate(automa tic) mouse movements and click operation using c#.
    Actually, i got pixels in the face (face tracking) right now and i need to move mouse(automatic ally, 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@y ahoo.com
    Thanks in Advance

    Comment

    • Sejton
      New Member
      • Mar 2007
      • 1

      #3
      using System;
      using System.Runtime. InteropServices ;
      ...


      // usingAPI for mouse governing and other possibilities

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



      enum Messages{WM_LBU TTONDOWN = 0x0201, WM_LBUTTONUP = 0x0202};
      const int MK_LBUTTON = 0x0001;
      [DllImport("User 32.dll")]
      static extern int SendMessage(Int Ptr hWnd, Messages uMsg, int wParam, IntPtr lParam);

      //импортируе м mouse_event():
      [DllImport("User 32.dll")]
      static extern void mouse_event(Mou seFlags 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(Mou seFlags.Absolut e | MouseFlags.Move , x, y, 0, UIntPtr.Zero);
      mouse_event(Mou seFlags.Absolut e | MouseFlags.Left Down , x, y, 0, UIntPtr.Zero);
      mouse_event(Mou seFlags.Absolut e | MouseFlags.Left Up, x, y, 0, UIntPtr.Zero);

      }



      #endregion

      Comment

      • JOHNYKUTTY
        New Member
        • Dec 2010
        • 10

        #4
        Simulate mouse click

        Hai friend,
        use the code below to simulate mouse click
        Code:
        using System.Runtime.InteropServices;
        
        private const UInt32 MOUSEEVENTF_LEFTDOWN = 0x0002;
        private const UInt32 MOUSEEVENTF_LEFTUP = 0x0004;
        [DllImport("user32.dll")]
                private static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, uint dwExtraInf);
        private void btnSet_Click(object sender, EventArgs e)
                {
                    int x = Convert.ToInt16(txtX.Text);//set x position 
                    int y = Convert.ToInt16(txtY.Text);//set y position 
                    Cursor.Position = new Point(x, y);
                    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);//make left button down
                    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);//make left button up
                }
        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)

        Comment

        Working...