none
Mouse Properties

    Question

  • Hello, I want some things about my computer's mouse using C#

    • First I want to set the mouse position in a position of my screen(Important not to the form only, whole the screen)
    • Second I want to get mouse's postion on whole screen again
    • And third I want to make mouse click somewher in the form

    e.x Mouse.SetCordinates(0, 134) //for example this cordinates are in Windows Start Button

    Mouse.Click // clicks Windows Start button

    Point p = new Point(134, 21);

    if(Mouse.Cordinates == p)

    { Mouse.Click }

    It is possible to do that?


    George Andredakis

    The limits of what a computer can do are difined only from programmer's imagination

    Wednesday, May 3, 2017 4:24 PM

Answers

  • There are several ways.

    For example with mouse_event() (upper left is (0, 0))=>

    int nXMove = 20, nYMove = 20;
    Cursor.Position = new System.Drawing.Point(nXMove, nYMove);
    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    
    // Declarations
    public const int MOUSEEVENTF_MOVE = 0x0001;
    public const int MOUSEEVENTF_LEFTDOWN = 0x0002;
    public const int MOUSEEVENTF_LEFTUP = 0x0004;
    public const int MOUSEEVENTF_ABSOLUTE = 0x8000;
    
    [DllImport("user32.dll")]
       public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);

    Wednesday, May 3, 2017 5:37 PM

All replies

  • Are you specifically asking about the Windows Start button or in general? At any rate you are going to need to obtain a handle to any window you want to send messages to, including mouse click messages. See if this helps get you started:

    How Can I "Play" With The Windows Start Button?

    It's for VB6 but the concept is pretty much the same.

    Wednesday, May 3, 2017 4:48 PM
  • There are several ways.

    For example with mouse_event() (upper left is (0, 0))=>

    int nXMove = 20, nYMove = 20;
    Cursor.Position = new System.Drawing.Point(nXMove, nYMove);
    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    
    // Declarations
    public const int MOUSEEVENTF_MOVE = 0x0001;
    public const int MOUSEEVENTF_LEFTDOWN = 0x0002;
    public const int MOUSEEVENTF_LEFTUP = 0x0004;
    public const int MOUSEEVENTF_ABSOLUTE = 0x8000;
    
    [DllImport("user32.dll")]
       public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);

    Wednesday, May 3, 2017 5:37 PM
  • and what about mouse click?

    George Andredakis

    The limits of what a computer can do are difined only from programmer's imagination

    Thursday, May 4, 2017 6:35 AM
  • and what about mouse click?


    Mouse click ?

    The code above does a mouse click (MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP)


    Thursday, May 4, 2017 6:52 AM
  • 1 for set position  Cursor.Position = New Point(x, y)

    2 for get position Dim Pt As Point = New Point(MousePosition)

    3 for mouse click Read this

    Regards

    Thursday, May 4, 2017 9:37 AM