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 3443948
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:51:15+00:00 2026-05-18T08:51:15+00:00

ctypes.windll.user32.mouse_event(3, 0, 0, 0,0) I’m messing around with mouse positions and stumbled upon this

  • 0

ctypes.windll.user32.mouse_event(3, 0, 0, 0,0)

I’m messing around with mouse positions and stumbled upon this line which from what I understand emulates a mouse click. Does anyone have documentation to similar lines (such as right-click and so on)?

  • 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-05-18T08:51:16+00:00Added an answer on May 18, 2026 at 8:51 am

    I have a small class that wraps the mouse management.

    import win32gui, win32api, win32con, ctypes
    
    class Mouse:
        """It simulates the mouse"""
        MOUSEEVENTF_MOVE = 0x0001 # mouse move 
        MOUSEEVENTF_LEFTDOWN = 0x0002 # left button down 
        MOUSEEVENTF_LEFTUP = 0x0004 # left button up 
        MOUSEEVENTF_RIGHTDOWN = 0x0008 # right button down 
        MOUSEEVENTF_RIGHTUP = 0x0010 # right button up 
        MOUSEEVENTF_MIDDLEDOWN = 0x0020 # middle button down 
        MOUSEEVENTF_MIDDLEUP = 0x0040 # middle button up 
        MOUSEEVENTF_WHEEL = 0x0800 # wheel button rolled 
        MOUSEEVENTF_ABSOLUTE = 0x8000 # absolute move 
        SM_CXSCREEN = 0
        SM_CYSCREEN = 1
    
        def _do_event(self, flags, x_pos, y_pos, data, extra_info):
            """generate a mouse event"""
            x_calc = 65536 * x_pos / ctypes.windll.user32.GetSystemMetrics(self.SM_CXSCREEN) + 1
            y_calc = 65536 * y_pos / ctypes.windll.user32.GetSystemMetrics(self.SM_CYSCREEN) + 1
            return ctypes.windll.user32.mouse_event(flags, x_calc, y_calc, data, extra_info)
    
        def _get_button_value(self, button_name, button_up=False):
            """convert the name of the button into the corresponding value"""
            buttons = 0
            if button_name.find("right") >= 0:
                buttons = self.MOUSEEVENTF_RIGHTDOWN
            if button_name.find("left") >= 0:
                buttons = buttons + self.MOUSEEVENTF_LEFTDOWN
            if button_name.find("middle") >= 0:
                buttons = buttons + self.MOUSEEVENTF_MIDDLEDOWN
            if button_up:
                buttons = buttons << 1
            return buttons
    
        def move_mouse(self, pos):
            """move the mouse to the specified coordinates"""
            (x, y) = pos
            old_pos = self.get_position()
            x =  x if (x != -1) else old_pos[0]
            y =  y if (y != -1) else old_pos[1]    
            self._do_event(self.MOUSEEVENTF_MOVE + self.MOUSEEVENTF_ABSOLUTE, x, y, 0, 0)
    
        def press_button(self, pos=(-1, -1), button_name="left", button_up=False):
            """push a button of the mouse"""
            self.move_mouse(pos)
            self._do_event(self.get_button_value(button_name, button_up), 0, 0, 0, 0)
    
        def click(self, pos=(-1, -1), button_name= "left"):
            """Click at the specified placed"""
            self.move_mouse(pos)
            self._do_event(self._get_button_value(button_name, False)+self._get_button_value(button_name, True), 0, 0, 0, 0)
    
        def double_click (self, pos=(-1, -1), button_name="left"):
            """Double click at the specifed placed"""
            for i in xrange(2): 
                self.click(pos, button_name)
    
        def get_position(self):
            """get mouse position"""
            return win32api.GetCursorPos()
    

    Here is a small example:

    import time
    mouse = Mouse()
    mouse.click((20, 10), "left")
    time.sleep(2.0)
    
    mouse.click((100, 100), "right")
    

    I hope it helps

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

Sidebar

Related Questions

Could someone tell me why this doesn't work? def selectAndCopy(x,y,z,w): ctypes.windll.user32.SetCursorPos(x,y) time.sleep(1) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0,
This is inconsistent: from ctypes import * class S(Structure): _fields_ = [(x, POINTER(c_int)), (y,
I am trying this simple ctypes example and getting the error mentioned >>> from
I'm using ctypes to load a DLL in Python. This works great. Now we'd
I am looking to use ctypes to call some old fortran libraries which were
How do you update this environment variable at runtime so that ctypes can load
I have this dicT in my code that contain some positions. position = ['712,352',
ctypes.WinDLL(C:\Program Files\AHSDK\bin\ahscript.dll) Traceback (most recent call last): File <stdin>, line 1, in <module> File
I'm calling a C function using ctypes from Python. It returns a pointer to
I was reading the ctypes tutorial, and I came across this: s = Hello,

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.