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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. how to perform mouse click on forms applications?

how to perform mouse click on forms applications?

Scheduled Pinned Locked Moved C#
questiontutorial
8 Posts 4 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
    smr85
    wrote on last edited by
    #1

    i want to simulate the mouse ... so how can i make right click or left click? what is the command i should use?

    O R S 3 Replies Last reply
    0
    • S smr85

      i want to simulate the mouse ... so how can i make right click or left click? what is the command i should use?

      O Offline
      O Offline
      OrlandoCurioso
      wrote on last edited by
      #2

      I have used this InterOp snippet: private const uint MOUSEEVENTF_LEFTDOWN = 0x0002; private const uint MOUSEEVENTF_LEFTUP = 0x0004; [DllImport("user32.dll")] private static extern void mouse_event( uint dwFlags, // motion and click options uint dx, // horizontal position or change uint dy, // vertical position or change uint dwData, // wheel movement IntPtr dwExtraInfo // application-defined information ); private static void SendClick(Point location) { Cursor.Position = location; mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, IntPtr.Zero); mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, IntPtr.Zero); }

      S 1 Reply Last reply
      0
      • S smr85

        i want to simulate the mouse ... so how can i make right click or left click? what is the command i should use?

        R Offline
        R Offline
        rah_sin
        wrote on last edited by
        #3

        u can try MouseEventArgs ev = new MouseEventArgs(MouseButtons.Left,1,0,0,1); object_MouseDown(sender,ev); rahul

        S 1 Reply Last reply
        0
        • O OrlandoCurioso

          I have used this InterOp snippet: private const uint MOUSEEVENTF_LEFTDOWN = 0x0002; private const uint MOUSEEVENTF_LEFTUP = 0x0004; [DllImport("user32.dll")] private static extern void mouse_event( uint dwFlags, // motion and click options uint dx, // horizontal position or change uint dy, // vertical position or change uint dwData, // wheel movement IntPtr dwExtraInfo // application-defined information ); private static void SendClick(Point location) { Cursor.Position = location; mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, IntPtr.Zero); mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, IntPtr.Zero); }

          S Offline
          S Offline
          smr85
          wrote on last edited by
          #4

          thx alot for ur replay... but i need the event of right click too i tried to make the same code but with intiail value private const uint MOUSEEVENTF_RIGHTDOWN = 0x0008; private const uint MOUSEEVENTF_RIGHTUP = 0x000a; but it didnot work ....

          1 Reply Last reply
          0
          • S smr85

            i want to simulate the mouse ... so how can i make right click or left click? what is the command i should use?

            S Offline
            S Offline
            suguimoto
            wrote on last edited by
            #5

            Hi! for a left click I used SendMessage Example: public enum Button_Messages { BM_CLICK = 245, BM_GETCHECK = 240, BM_GETIMAGE = 246, BM_GETSTATE = 242, BM_SETCHECK = 241, BM_SETIMAGE = 247, BM_SETSTATE = 243, BM_SETSTYLE = 244, } if you create the application, you have the proccess and the handle, otherwise you can find it with FindWindow then you can find wihch control to Left click. Button is the Class name, Import Option is the Text of the control. hControl = FindWindowEx(windowHandle, IntPtr.Zero, "Button", "Import Options"); Once you have the Control´s handle you can simulate the left click, if SendMessage returns True it was successful, if False it was not possible to perform the click. SendMessage(hControl, (int)Button_Messages.BM_CLICK, (uint)0, (int)0);

            S 1 Reply Last reply
            0
            • R rah_sin

              u can try MouseEventArgs ev = new MouseEventArgs(MouseButtons.Left,1,0,0,1); object_MouseDown(sender,ev); rahul

              S Offline
              S Offline
              smr85
              wrote on last edited by
              #6

              the object_MouseDown(sender,ev); need a using or somthing ...are it function or built in? so can u tell me plz how to define it, thx in advance

              R 1 Reply Last reply
              0
              • S smr85

                the object_MouseDown(sender,ev); need a using or somthing ...are it function or built in? so can u tell me plz how to define it, thx in advance

                R Offline
                R Offline
                rah_sin
                wrote on last edited by
                #7

                the object is like u can take example if u have added click event for lable1 to simulate this event with out acctualy clicking mouse button u can make ur custom mouse click event MouseEventArgs ev = new MouseEventArgs(MouseButtons.Left or MouseButtons.Right,1,0,0,1); and then call mouse click method of lable like this Lable1_MouseClick(Lable1,ev); rahul

                1 Reply Last reply
                0
                • S suguimoto

                  Hi! for a left click I used SendMessage Example: public enum Button_Messages { BM_CLICK = 245, BM_GETCHECK = 240, BM_GETIMAGE = 246, BM_GETSTATE = 242, BM_SETCHECK = 241, BM_SETIMAGE = 247, BM_SETSTATE = 243, BM_SETSTYLE = 244, } if you create the application, you have the proccess and the handle, otherwise you can find it with FindWindow then you can find wihch control to Left click. Button is the Class name, Import Option is the Text of the control. hControl = FindWindowEx(windowHandle, IntPtr.Zero, "Button", "Import Options"); Once you have the Control´s handle you can simulate the left click, if SendMessage returns True it was successful, if False it was not possible to perform the click. SendMessage(hControl, (int)Button_Messages.BM_CLICK, (uint)0, (int)0);

                  S Offline
                  S Offline
                  smr85
                  wrote on last edited by
                  #8

                  thx it finaly run ...

                  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