Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7780809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:01:31+00:00 2026-06-01T19:01:31+00:00

I am trying to automatically draw in a program similar to paint by simulating

  • 0

I am trying to automatically draw in a program similar to paint by simulating mouse movement and clicks with user32.dll in Windows 7.

Here’s what I have and how I use it:

Setup

    [DllImport("user32.dll")]
    static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);


    [Flags]
    public enum MouseEventFlags
    {
        LEFTDOWN = 0x00000002,
        LEFTUP = 0x00000004,
        MIDDLEDOWN = 0x00000020,
        MIDDLEUP = 0x00000040,
        MOVE = 0x00000001,
        ABSOLUTE = 0x00008000,
        RIGHTDOWN = 0x00000008,
        RIGHTUP = 0x00000010
    }

    public void LeftMouseDown()
    {
        mouse_event((int)(MouseEventFlags.LEFTDOWN), Cursor.Position.X, Cursor.Position.Y, 0, 0);
    }

    public void LeftMouseUp()
    {
        mouse_event((int)(MouseEventFlags.LEFTUP), Cursor.Position.X, Cursor.Position.Y, 0, 0);
    }

When Drawing

            foreach (var contour in contours)
            {
                LeftMouseDown();
                foreach (var point in contour)
                {
                    var x = point.X + offsetX;
                    var y = point.Y + offsetY;
                    Cursor.Position = new Point(x, y);
                    //LeftMouseDown();
                    System.Threading.Thread.Sleep(2);
                }
                LeftMouseUp();
            }

What I’m trying to simulate is the mouse being clicked and held, moved around to a bunch of points in each contour and then let up before moving on to the next contour.

The problem, is that this just holds the mouse button down for the first movement and then lets it up.

TL;DR

How can I keep the mouse left click down when the mouse is being moved around programatically?

I am trying to simulate drawing in a third party app. (Microsoft LINQ’s Whiteboard, the IM client.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:01:34+00:00Added an answer on June 1, 2026 at 7:01 pm

    Summarizing the comment trail: this has not the expected result because the code only simulates mouse clicks, not mouse motion. Moving the cursor with Cursor.Position directly changes the cursor position, bypassing the Windows input event queue. So doesn’t generate any notifications (WM_MOUSEMOVE messages) to the window that has the focus.

    Fix by adding a MouseMove() method to the helper class that uses mouse_event() with MouseEventFlags.MOVE

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a program that automatically corrects the perspective of a
We are trying to have faxes automatically be sent from within an SSIS package.
I'm trying to have a script automatically transform an xml file into several html
I'm trying to automatically exclude a library from my release build, but have it
I'm trying to automatically compress both CSS and JS using maven and this plugin
I am trying to automatically figure out which Delphi version (of Delphi 5 to
I'm trying to login automatically in a website using Perl with WWW::Mechanize . What
I'm trying to get php to automatically pass the session ID via url, even
I'm trying to make a script that automatically starts uploading after the data has
I'm trying to create a process to automatically generate thumbnails of the images uploaded

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.