Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. Programmatically Click mouse on specefic location

Programmatically Click mouse on specefic location

Scheduled Pinned Locked Moved Windows Forms
help
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shaina2231
    wrote on last edited by
    #1

    I m trying to click mouse automatically using code in some specific location for this i m using following code but its not working

    [System.Runtime.InteropServices.DllImport("user32.dll")]
    public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);

    public const int MOUSEEVENTF_LEFTDOWN = 0x02;
    public const int MOUSEEVENTF_LEFTUP = 0x04;
    public const int MOUSEEVENTF_RIGHTDOWN = 0x08;
    public const int MOUSEEVENTF_RIGHTUP = 0x10;

    public void MouseClick()
    {
    int x = 100;
    int y = 100;

    mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
    mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
    }

    Plz Help me To move cursor i m using Cursor.Position = new Point((int)10, (int)10); thats working fine Plz help

    S L 2 Replies Last reply
    0
    • S shaina2231

      I m trying to click mouse automatically using code in some specific location for this i m using following code but its not working

      [System.Runtime.InteropServices.DllImport("user32.dll")]
      public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);

      public const int MOUSEEVENTF_LEFTDOWN = 0x02;
      public const int MOUSEEVENTF_LEFTUP = 0x04;
      public const int MOUSEEVENTF_RIGHTDOWN = 0x08;
      public const int MOUSEEVENTF_RIGHTUP = 0x10;

      public void MouseClick()
      {
      int x = 100;
      int y = 100;

      mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
      mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
      }

      Plz Help me To move cursor i m using Cursor.Position = new Point((int)10, (int)10); thats working fine Plz help

      S Offline
      S Offline
      shaina2231
      wrote on last edited by
      #2

      OK the Problem IS SOlved

      L 1 Reply Last reply
      0
      • S shaina2231

        I m trying to click mouse automatically using code in some specific location for this i m using following code but its not working

        [System.Runtime.InteropServices.DllImport("user32.dll")]
        public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);

        public const int MOUSEEVENTF_LEFTDOWN = 0x02;
        public const int MOUSEEVENTF_LEFTUP = 0x04;
        public const int MOUSEEVENTF_RIGHTDOWN = 0x08;
        public const int MOUSEEVENTF_RIGHTUP = 0x10;

        public void MouseClick()
        {
        int x = 100;
        int y = 100;

        mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
        mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
        }

        Plz Help me To move cursor i m using Cursor.Position = new Point((int)10, (int)10); thats working fine Plz help

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, I'm using the following user32 functions: - SetCursorPos() to move the mouse - SendInput() to give a MOUSEEVENTF_LEFTDOWN and MOUSEEVENTF_LEFTUP IIRC the x,y parameters of mouse_event describe a relative mouse movement, so I keep them at zero. Here are my P/Invoke prototypes:

        \[DllImport("user32.dll", CallingConvention=CallingConvention.StdCall, SetLastError=true)\]
        public static extern IntPtr SendInput(int count, ref INPUT2 input, int size);
        
        \[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)\]
        public static extern IntPtr SetCursorPos(int x, int y);
        
        public struct MOUSEINPUT {
        	public int dx;
        	public int dy;
        	public int mouseData;
        	public int dwFlags;
        	public int time;
        	public IntPtr dwExtraInfo;
        }
        
        public struct INPUT2 {
        	public uint type1;
        	public MOUSEINPUT mi1;
        	public uint type2;
        	public MOUSEINPUT mi2;
        }
        

        :)

        Luc Pattyn


        I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


        1 Reply Last reply
        0
        • S shaina2231

          OK the Problem IS SOlved

          L Offline
          L Offline
          Lukas Molnar
          wrote on last edited by
          #4

          shaina2231 wrote:

          OK the Problem IS SOlved

          And how exactly did you solve the problem? I'm interested because I'm working on same thing. Lukas

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups