### Hook Mouse Events Source: https://context7.com/boppreh/mouse/llms.txt Installs a global listener to capture all mouse events system-wide. This is typically used for monitoring and logging mouse activity. ```APIDOC ## POST /mouse/hook ### Description Installs a global listener that captures all mouse events system-wide. ### Method POST ### Endpoint /mouse/hook ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **callback_url** (string) - Required - The URL to which captured events will be sent. ### Request Example ```json { "callback_url": "http://localhost:5000/events" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation, e.g., "hook_installed". #### Response Example ```json { "status": "hook_installed" } ``` ``` -------------------------------- ### Capture and Analyze Mouse Events with Hooks (Python) Source: https://context7.com/boppreh/mouse/llms.txt Shows how to use `mouse.hook` to capture all mouse events (button, move, wheel) in real-time and log them. It details how to install and uninstall hooks, process events within a callback, and analyze the captured data. ```python import mouse import time # Hook to capture and analyze events captured_events = [] def event_logger(event): captured_events.append(event) if isinstance(event, mouse.ButtonEvent): # ButtonEvent attributes: event_type, button, time print(f"Button Event - Type: {event.event_type}, Button: {event.button}, Time: {event.time}") elif isinstance(event, mouse.MoveEvent): # MoveEvent attributes: x, y, time print(f"Move Event - Position: ({event.x}, {event.y}), Time: {event.time}") elif isinstance(event, mouse.WheelEvent): # WheelEvent attributes: delta, time print(f"Wheel Event - Delta: {event.delta}, Time: {event.time}") # Install hook and capture events mouse.hook(event_logger) print("Capturing events for 5 seconds...") time.sleep(5) mouse.unhook(event_logger) # Analyze captured events print(f"\nCaptured {len(captured_events)} total events") button_events = [e for e in captured_events if isinstance(e, mouse.ButtonEvent)] move_events = [e for e in captured_events if isinstance(e, mouse.MoveEvent)] wheel_events = [e for e in captured_events if isinstance(e, mouse.WheelEvent)] print(f"Button events: {len(button_events)}") print(f"Move events: {len(move_events)}") print(f"Wheel events: {len(wheel_events)}") ``` -------------------------------- ### Capture All Mouse Events with Callback Source: https://context7.com/boppreh/mouse/llms.txt Defines a general callback function to handle all types of mouse events, including movement, button presses/releases, and wheel scrolling. It prints details specific to each event type. Ensure the 'mouse' library is installed. ```python import mouse import time # Define callback for all mouse events def handle_mouse_event(event): if isinstance(event, mouse.MoveEvent): print(f"Mouse moved to ({event.x}, {event.y})") elif isinstance(event, mouse.ButtonEvent): print(f"Button {event.button} {event.event_type} at {event.time}") elif isinstance(event, mouse.WheelEvent): print(f"Wheel scrolled {event.delta} at {event.time}") # Install the hook mouse.hook(handle_mouse_event) # Let it run for 10 seconds print("Monitoring mouse events for 10 seconds...") time.sleep(10) # Clean up mouse.unhook(handle_mouse_event) ``` -------------------------------- ### Hook Mouse Events - Python Source: https://context7.com/boppreh/mouse/llms.txt Installs a global listener to capture all mouse events system-wide. This allows for real-time monitoring, logging, or reacting to mouse movements, clicks, and scrolls, regardless of which application is active. The listener runs in a separate thread to prevent blocking the main program. ```python import mouse import time # Example hook function (not fully defined in provided text) # def on_click(event): # print(f"Clicked at: {event.x}, {event.y}") # mouse.on_click(on_click) # Keep the script running to listen for events # try: # while True: # time.sleep(1) # except KeyboardInterrupt: # print("Stopping listener.") ``` -------------------------------- ### Advanced Button Event Filtering Source: https://context7.com/boppreh/mouse/llms.txt Provides granular control over which button events trigger callbacks by specifying target buttons and event types (down, up, double). This example demonstrates listening for specific combinations. Requires the 'mouse' library. ```python import mouse import time # Custom callback with event details def button_handler(event): print(f"Button: {event.button}, Type: {event.event_type}, Time: {event.time}") # Listen to multiple buttons and event types mouse.on_button( callback=lambda: print("Middle or right button action!"), buttons=('middle', 'right'), types=('down', 'up') ) # Listen only to button down events on left and middle mouse.on_button( callback=lambda: print("Left or middle pressed down"), buttons=['left', 'middle'], types=['down'] ) # Listen for any event on extra mouse buttons mouse.on_button( callback=lambda: print("Extra button used!"), buttons=('x', 'x2'), types=('up', 'down', 'double') ) print("Monitoring advanced button events for 10 seconds...") time.sleep(10) mouse.unhook_all() ``` -------------------------------- ### WheelEvent Index Method (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Returns the first index of a given `value` within the WheelEvent data, with optional `start` and `stop` range parameters. Raises ValueError if the value is not found. ```python WheelEvent.index(self, value, start=0, stop=9223372036854775807) ``` -------------------------------- ### Drag Mouse - Python Source: https://context7.com/boppreh/mouse/llms.txt Simulates dragging the mouse from a starting point to an ending point while holding down a button. Supports both absolute and relative coordinates, as well as animated drags with customizable duration. Ideal for tasks like selecting text or moving files. ```python import mouse # Drag from one point to another (absolute coordinates) mouse.drag(start_x=100, start_y=100, end_x=500, end_y=500, absolute=True, duration=0) # Slow animated drag mouse.drag(200, 200, 800, 400, absolute=True, duration=2) # Relative drag from current position current_x, current_y = mouse.get_position() mouse.drag(current_x, current_y, current_x + 300, current_y + 200, absolute=True, duration=1) # Quick drag for selecting text mouse.drag(100, 300, 400, 300, absolute=True, duration=0.5) ``` -------------------------------- ### Drag Mouse (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Simulates holding down the left mouse button, moving from a start to an end position, and then releasing the button. Supports absolute or relative positioning and animated movement. ```python mouse.drag(start_x, start_y, end_x, end_y, absolute=True, duration=0) ``` -------------------------------- ### Filter Mouse Events by Type Constants (Python) Source: https://context7.com/boppreh/mouse/llms.txt Explains how to use event type constants like `mouse.UP`, `mouse.DOWN`, and `mouse.DOUBLE` to filter and handle specific mouse button actions. Includes examples of using these constants with `mouse.hook`, `mouse.wait`, and `mouse.record`. ```python import mouse import time # Event type constants print(f"Up event: {mouse.UP}") # 'up' - button released print(f"Down event: {mouse.DOWN}") # 'down' - button pressed print(f"Double event: {mouse.DOUBLE}") # 'double' - double click # Use in event filtering def handle_down_only(event): if isinstance(event, mouse.ButtonEvent) and event.event_type == mouse.DOWN: print(f"Button {event.button} was pressed down") mouse.hook(handle_down_only) # Wait for specific event types print("Press and hold any button...") mouse.wait(button='left', target_types=(mouse.DOWN,)) print("Button pressed!") print("Release the button...") mouse.wait(button='left', target_types=(mouse.UP,)) print("Button released!") # Record only button down events print("Recording down events only... Right-click to stop") events = mouse.record(button='right', target_types=(mouse.DOWN,)) mouse.unhook_all() ``` -------------------------------- ### Get Mouse Position Source: https://context7.com/boppreh/mouse/llms.txt Retrieves the current cursor position on the screen. ```APIDOC ## GET /mouse/position ### Description Returns the current cursor position as a tuple of (x, y) screen coordinates. ### Method GET ### Endpoint /mouse/position ### Parameters #### Path Parameters None #### Query Parameters None ### Request Example None ### Response #### Success Response (200) - **position** (tuple) - A tuple containing the x and y screen coordinates of the cursor, e.g., (100, 200). #### Response Example ```json { "position": [100, 200] } ``` ``` -------------------------------- ### Get Mouse Position (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Retrieves the current (x, y) coordinates of the mouse cursor. ```python mouse.get_position() ``` -------------------------------- ### Drag Mouse Source: https://context7.com/boppreh/mouse/llms.txt Performs a drag operation by moving the mouse cursor from a start point to an end point while holding down a specified mouse button. ```APIDOC ## POST /mouse/drag ### Description Performs drag operations by moving the mouse while holding down a button. ### Method POST ### Endpoint /mouse/drag ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **start_x** (integer) - Required - The starting x-coordinate of the drag. - **start_y** (integer) - Required - The starting y-coordinate of the drag. - **end_x** (integer) - Required - The ending x-coordinate of the drag. - **end_y** (integer) - Required - The ending y-coordinate of the drag. - **absolute** (boolean) - Optional (default: true) - If true, uses absolute coordinates for start and end; if false, uses relative coordinates. - **duration** (float) - Optional (default: 0) - The time in seconds over which the drag should occur. - **button** (string) - Optional (default: 'left') - The mouse button to hold down during the drag. ### Request Example ```json { "start_x": 100, "start_y": 100, "end_x": 500, "end_y": 500, "duration": 1 } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation, e.g., "success". #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Get Mouse Position - Python Source: https://context7.com/boppreh/mouse/llms.txt Retrieves the current cursor coordinates. It returns a tuple (x, y) representing the screen position. This function is essential for tasks requiring knowledge of the current mouse location, such as initiating relative movements or validating current cursor placement. ```python import mouse # Get current mouse position x, y = mouse.get_position() print(f"Mouse is at ({x}, {y})") # Use position for relative movements current_x, current_y = mouse.get_position() mouse.move(current_x + 100, current_y + 50, absolute=True) ``` -------------------------------- ### Mouse Version Source: https://github.com/boppreh/mouse/blob/master/README.md Retrieves the version of the mouse library. ```APIDOC ## mouse.version ### Description Returns the installed version of the mouse library. ### Returns - str: The version string of the mouse library. ### Example ```python print(f"Mouse library version: {mouse.version}") ``` ``` -------------------------------- ### Mouse Library Version (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Retrieves the version of the mouse library. ```python mouse.version ``` -------------------------------- ### Replay Mouse Events with Custom Filters (Python) Source: https://context7.com/boppreh/mouse/llms.txt Demonstrates replaying recorded mouse events with options to include or exclude specific event types like clicks, moves, or wheel actions. This allows for targeted playback of user interactions. ```python import mouse # Assuming 'events' is a list of recorded mouse events # Replay only movements mouse.play(events, include_clicks=False, include_moves=True, include_wheel=False) # Full replay with all events mouse.play(events, speed_factor=1.0, include_clicks=True, include_moves=True, include_wheel=True) ``` -------------------------------- ### Mouse Control Functions Source: https://github.com/boppreh/mouse/blob/master/README.md Functions for simulating mouse actions and managing mouse events. ```APIDOC ## mouse.is_pressed ### Description Checks if a specific mouse button is currently pressed. ### Parameters - **button** (str): The mouse button to check (e.g., 'left', 'right', 'middle'). ### Returns - bool: True if the button is pressed, False otherwise. ### Example ```python if mouse.is_pressed('left'): print("Left button is pressed.") ``` ## mouse.press ### Description Simulates pressing a mouse button down. ### Parameters - **button** (str): The mouse button to press (e.g., 'left', 'right', 'middle'). ### Example ```python mouse.press('left') ``` ## mouse.release ### Description Simulates releasing a mouse button. ### Parameters - **button** (str): The mouse button to release (e.g., 'left', 'right', 'middle'). ### Example ```python mouse.release('left') ``` ## mouse.click ### Description Simulates a single mouse click. ### Parameters - **button** (str): The mouse button to click (e.g., 'left', 'right', 'middle'). Defaults to 'left'. ### Example ```python mouse.click('right') ``` ## mouse.double_click ### Description Simulates a double mouse click. ### Parameters - **button** (str): The mouse button to double-click (e.g., 'left', 'right', 'middle'). Defaults to 'left'. ### Example ```python mouse.double_click() ``` ## mouse.right_click ### Description Simulates a right mouse click. ### Example ```python mouse.right_click() ``` ## mouse.wheel ### Description Simulates scrolling the mouse wheel. ### Parameters - **delta** (int): The amount to scroll. Positive values scroll up, negative values scroll down. ### Example ```python mouse.wheel(1) # Scroll up mouse.wheel(-1) # Scroll down ``` ## mouse.move ### Description Simulates moving the mouse pointer to a specific position. ### Parameters - **x** (int): The target X-coordinate. - **y** (int): The target Y-coordinate. - **absolute** (bool): If True, coordinates are absolute. If False, coordinates are relative to the current position. Defaults to True. - **duration** (float): The time in seconds to take for the move. Defaults to 0. ### Example ```python mouse.move(100, 200, absolute=True, duration=0.5) ``` ## mouse.drag ### Description Simulates dragging the mouse from one position to another while holding a button. ### Parameters - **button** (str): The mouse button to hold down during the drag. - **to_x** (int): The target X-coordinate. - **to_y** (int): The target Y-coordinate. - **absolute** (bool): If True, coordinates are absolute. If False, coordinates are relative to the current position. Defaults to True. - **duration** (float): The time in seconds to take for the drag. Defaults to 0. ### Example ```python mouse.drag('left', 300, 400, duration=1) ``` ## mouse.on_button ### Description Registers a callback function to be executed when a mouse button is pressed or released. ### Parameters - **callback** (function): The function to call. It will receive a `ButtonEvent` object. - **args** (tuple): Optional arguments to pass to the callback. - **kwargs** (dict): Optional keyword arguments to pass to the callback. ### Example ```python def on_button_event(event): print(f"Button event: {event}") mouse.on_button(on_button_event) ``` ## mouse.on_click ### Description Registers a callback function to be executed when a mouse button is clicked. ### Parameters - **callback** (function): The function to call. It will receive a `ButtonEvent` object. - **args** (tuple): Optional arguments to pass to the callback. - **kwargs** (dict): Optional keyword arguments to pass to the callback. ### Example ```python def on_click_event(event): print(f"Click event: {event}") mouse.on_click(on_click_event) ``` ## mouse.on_double_click ### Description Registers a callback function to be executed when a mouse button is double-clicked. ### Parameters - **callback** (function): The function to call. It will receive a `ButtonEvent` object. - **args** (tuple): Optional arguments to pass to the callback. - **kwargs** (dict): Optional keyword arguments to pass to the callback. ### Example ```python def on_double_click_event(event): print(f"Double click event: {event}") mouse.on_double_click(on_double_click_event) ``` ## mouse.on_right_click ### Description Registers a callback function to be executed when the right mouse button is clicked. ### Parameters - **callback** (function): The function to call. It will receive a `ButtonEvent` object. - **args** (tuple): Optional arguments to pass to the callback. - **kwargs** (dict): Optional keyword arguments to pass to the callback. ### Example ```python def on_right_click_event(event): print(f"Right click event: {event}") mouse.on_right_click(on_right_click_event) ``` ## mouse.on_middle_click ### Description Registers a callback function to be executed when the middle mouse button is clicked. ### Parameters - **callback** (function): The function to call. It will receive a `ButtonEvent` object. - **args** (tuple): Optional arguments to pass to the callback. - **kwargs** (dict): Optional keyword arguments to pass to the callback. ### Example ```python def on_middle_click_event(event): print(f"Middle click event: {event}") mouse.on_middle_click(on_middle_click_event) ``` ## mouse.wait ### Description Waits until a specific mouse event occurs. ### Parameters - **event_type** (str): The type of event to wait for (e.g., 'down', 'up', 'click', 'double'). - **button** (str, optional): The specific button to wait for. Defaults to None (any button). ### Example ```python print("Waiting for a left button click...") mouse.wait('click', button='left') print("Left button clicked!") ``` ## mouse.get_position ### Description Gets the current position of the mouse pointer. ### Returns - tuple: A tuple containing the current (x, y) coordinates. ### Example ```python x, y = mouse.get_position() print(f"Current mouse position: ({x}, {y})") ``` ## mouse.hook ### Description Hooks into global mouse events, allowing you to receive all mouse events. ### Parameters - **callback** (function): The function to call for each mouse event. It will receive an event object (ButtonEvent, MoveEvent, or WheelEvent). - **args** (tuple): Optional arguments to pass to the callback. - **kwargs** (dict): Optional keyword arguments to pass to the callback. ### Example ```python def handle_mouse_event(event): print(f"Received mouse event: {event}") mouse.hook(handle_mouse_event) ``` ## mouse.unhook ### Description Unhooks a previously registered callback function. ### Parameters - **callback** (function): The callback function to unhook. ### Example ```python # Assuming 'my_callback' was previously registered with mouse.hook mouse.unhook(my_callback) ``` ## mouse.unhook_all ### Description Unhooks all currently registered mouse event callbacks. ### Example ```python mouse.unhook_all() ``` ## mouse.record ### Description Records a sequence of mouse events. ### Parameters - **trigger_mouseup** (bool): If True, stops recording when the mouse button is released. Defaults to True. - **trigger_mousedown** (bool): If True, starts recording when the mouse button is pressed. Defaults to False. ### Returns - list: A list of recorded event objects. ### Example ```python print("Move your mouse and click to record...") events = mouse.record(trigger_mousedown=True) print(f"Recorded {len(events)} events.") ``` ## mouse.play ### Description Plays back a recorded sequence of mouse events. ### Parameters - **events** (list): A list of event objects to play back. - **speed_factor** (float): A factor to adjust the playback speed. 1.0 is normal speed. Defaults to 1.0. - **absolute** (bool): If True, coordinates are absolute. If False, coordinates are relative. Defaults to True. ### Example ```python # Assuming 'recorded_events' is a list obtained from mouse.record() mouse.play(recorded_events) ``` ``` -------------------------------- ### Listen for Specific Button Events (Clicks, Double-Clicks) Source: https://context7.com/boppreh/mouse/llms.txt Registers separate callback functions for specific mouse button actions such as left clicks, right clicks, and double-clicks. It uses counters to track events. Requires the 'mouse' library. Input is user mouse interaction; output is printed event notifications. ```python import mouse import time # Counter for tracking events click_count = [0] # Callback for left clicks def on_left_click(): click_count[0] += 1 print(f"Left click detected! Total: {click_count[0]}") # Callback for right clicks def on_right_click(): print("Right click detected!") # Callback for double clicks def on_double(): print("Double click detected!") # Register handlers mouse.on_click(on_left_click) mouse.on_right_click(on_right_click) mouse.on_double_click(on_double) # Run for 15 seconds print("Click anywhere... monitoring for 15 seconds") time.sleep(15) # Clean up all hooks mouse.unhook_all() print(f"Final click count: {click_count[0]}") ``` -------------------------------- ### Record Mouse Actions for Playback Source: https://context7.com/boppreh/mouse/llms.txt Records a sequence of mouse events (movements, clicks, scrolls) until a specified stop condition (e.g., a specific button click) is met. The recorded events can then be replayed. Requires the 'mouse' library. ```python import mouse # Record until right button is clicked print("Perform mouse actions... Right-click to stop recording") events = mouse.record(button='right', target_types=('down',)) print(f"Recorded {len(events)} events") # Record until middle button is clicked print("Recording... Middle-click to stop") macro = mouse.record(button='middle', target_types=('down',)) # Record with left button as stop trigger print("Click left button to stop recording") recorded_actions = mouse.record(button='left', target_types=('up',)) # Display recorded event types for event in recorded_actions: if isinstance(event, mouse.ButtonEvent): print(f"Button: {event.button} {event.event_type}") elif isinstance(event, mouse.MoveEvent): print(f"Move: ({event.x}, {event.y})") elif isinstance(event, mouse.WheelEvent): print(f"Wheel: {event.delta}") ``` -------------------------------- ### Utilize Mouse Button Constants for API Calls (Python) Source: https://context7.com/boppreh/mouse/llms.txt Demonstrates the use of predefined constants like `mouse.LEFT`, `mouse.RIGHT`, and `mouse.MIDDLE` for clear and consistent mouse button identification in various library functions such as `click`, `press`, `wait`, and `is_pressed`. ```python import mouse # Use constants for button identification print(f"Left button constant: {mouse.LEFT}") # 'left' print(f"Right button constant: {mouse.RIGHT}") # 'right' print(f"Middle button constant: {mouse.MIDDLE}") # 'middle' print(f"Extra button X: {mouse.X}") # 'x' print(f"Extra button X2: {mouse.X2}") # 'x2' # Use in function calls mouse.click(button=mouse.LEFT) mouse.press(button=mouse.RIGHT) mouse.wait(button=mouse.MIDDLE) # Check button state with constants if mouse.is_pressed(mouse.LEFT): print("Left button is pressed") # Use in event handlers mouse.on_button( callback=lambda: print("Action detected"), buttons=(mouse.LEFT, mouse.MIDDLE, mouse.RIGHT), types=(mouse.UP, mouse.DOWN) ) ``` -------------------------------- ### Play Recorded Mouse Events with Speed Control Source: https://context7.com/boppreh/mouse/llms.txt Replays a previously recorded sequence of mouse events. Allows controlling the playback speed using a `speed_factor` and filtering which types of events (clicks, moves, wheel) are replayed. Requires the 'mouse' library and a recorded event list. ```python import mouse # Record a sequence (example: record until right-click) print("Perform actions... Right-click to stop") events = mouse.record(button='right', target_types=('down',)) # Replay at normal speed print("Replaying at normal speed...") mouse.play(events, speed_factor=1.0) # Replay at 2x speed print("Replaying at double speed...") mouse.play(events, speed_factor=2.0) # Replay at half speed print("Replaying in slow motion...") mouse.play(events, speed_factor=0.5) # Replay as fast as possible print("Replaying at maximum speed...") mouse.play(events, speed_factor=0) # Replay only clicks, no movements mouse.play(events, include_clicks=True, include_moves=False, include_wheel=True) ``` -------------------------------- ### WheelEvent Class and Constructor (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Defines the WheelEvent class, used for handling mouse wheel events. It accepts `delta` (scroll amount) and `time` (event timestamp) as arguments. ```python WheelEvent(delta, time) ``` -------------------------------- ### Press and Release Mouse Buttons Source: https://context7.com/boppreh/mouse/llms.txt Provides fine-grained control for pressing and releasing mouse buttons, essential for drag-and-drop operations. ```APIDOC ## POST /mouse/press_release ### Description Simulates pressing or releasing a mouse button. ### Method POST ### Endpoint /mouse/press_release ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **state** (string) - Required - The action to perform ('press' or 'release'). - **button** (string) - Optional (default: 'left') - The button to press or release ('left', 'right', 'middle', 'x', 'x2'). ### Request Example ```json { "state": "press", "button": "left" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation, e.g., "success". #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Mouse Event Objects Source: https://github.com/boppreh/mouse/blob/master/README.md Classes representing different types of mouse events. ```APIDOC ## class mouse.ButtonEvent ### Description Represents a button event (press or release). ### Attributes - **event_type** (str): The type of button event ('down' or 'up'). - **button** (str): The button that was pressed or released (e.g., 'left', 'right', 'middle'). - **time** (float): The timestamp of the event. ### Example ```python # Assuming 'event' is an instance of ButtonEvent print(f"Event type: {event.event_type}") print(f"Button: {event.button}") print(f"Timestamp: {event.time}") ``` ## class mouse.MoveEvent ### Description Represents a mouse movement event. ### Attributes - **x** (int): The new X-coordinate of the mouse pointer. - **y** (int): The new Y-coordinate of the mouse pointer. - **time** (float): The timestamp of the event. ### Example ```python # Assuming 'event' is an instance of MoveEvent print(f"New position: ({event.x}, {event.y})") print(f"Timestamp: {event.time}") ``` ## class mouse.WheelEvent ### Description Represents a mouse wheel event. ### Attributes - **delta** (int): The direction and amount the wheel was scrolled. - **time** (float): The timestamp of the event. ``` -------------------------------- ### Wait for Specific Mouse Action Source: https://context7.com/boppreh/mouse/llms.txt Blocks the program's execution until a specified mouse button event occurs. This is useful for synchronizing actions in scripts or automation. Supports waiting for button clicks, presses, or any action on specific buttons. Requires the 'mouse' library. ```python import mouse # Wait for left button click (up event) print("Click the left mouse button to continue...") mouse.wait(button='left', target_types=('up',)) print("Left button clicked!") # Wait for right button press (down event) print("Press the right mouse button...") mouse.wait(button='right', target_types=('down',)) print("Right button pressed!") # Wait for any event (down, up, or double) on middle button print("Perform any action with the middle button...") mouse.wait(button='middle', target_types=('up', 'down', 'double')) print("Middle button action detected!") # Use in automation workflow print("Click to start process...") mouse.wait() # Waits for any button click by default print("Process started!") ``` -------------------------------- ### Move Mouse Cursor - Python Source: https://context7.com/boppreh/mouse/llms.txt Moves the mouse cursor to specified screen coordinates. Supports instant or animated movements with adjustable duration. Can perform both absolute movements to fixed points and relative movements from the current position. ```python import mouse # Instant absolute movement to coordinates mouse.move(500, 300, absolute=True, duration=0) # Animated movement over 2 seconds (smooth) mouse.move(800, 600, absolute=True, duration=2) # Relative movement from current position mouse.move(100, -50, absolute=False, duration=0) # Slow animated relative movement x, y = mouse.get_position() mouse.move(x + 200, y + 100, absolute=True, duration=1.5, steps_per_second=120) ``` -------------------------------- ### Mouse Event Constants Source: https://github.com/boppreh/mouse/blob/master/README.md Constants used to represent mouse button states and event types. ```APIDOC ## mouse.DOWN ### Description Represents a mouse button down event. ### Constant Value `'down'` ## mouse.UP ### Description Represents a mouse button up event. ### Constant Value `'up'` ## mouse.LEFT ### Description Represents the left mouse button. ### Constant Value `'left'` ## mouse.MIDDLE ### Description Represents the middle mouse button. ### Constant Value `'middle'` ## mouse.RIGHT ### Description Represents the right mouse button. ### Constant Value `'right'` ## mouse.DOUBLE ### Description Represents a double-click event. ### Constant Value `'double'` ``` -------------------------------- ### Click Mouse Buttons Source: https://context7.com/boppreh/mouse/llms.txt Simulates a mouse button click at the current cursor position or a specified position. Supports left, right, middle, and extra mouse buttons. ```APIDOC ## POST /mouse/click ### Description Simulates mouse button clicks with support for left, right, middle, and extra buttons. ### Method POST ### Endpoint /mouse/click ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **button** (string) - Optional (default: 'left') - The button to click ('left', 'right', 'middle', 'x', 'x2'). - **x** (integer) - Optional - The x-coordinate to click at. If not provided, uses the current cursor position. - **y** (integer) - Optional - The y-coordinate to click at. If not provided, uses the current cursor position. ### Request Example ```json { "button": "right" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation, e.g., "success". #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Mouse Wheel Scroll (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Simulates scrolling the mouse wheel. A positive `delta` scrolls up, and a negative `delta` scrolls down. ```python mouse.wheel(delta=1) ``` -------------------------------- ### Move Mouse Cursor Source: https://context7.com/boppreh/mouse/llms.txt Moves the mouse cursor to a specified position on the screen, with options for absolute or relative movement and animated duration. ```APIDOC ## POST /mouse/move ### Description Moves the mouse cursor to a specific position with optional animation support. ### Method POST ### Endpoint /mouse/move ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **x** (integer) - Required - The target x-coordinate. - **y** (integer) - Required - The target y-coordinate. - **absolute** (boolean) - Optional (default: true) - If true, moves to absolute coordinates; if false, moves relative to the current position. - **duration** (float) - Optional (default: 0) - The time in seconds over which the movement should occur. A duration of 0 means instant movement. - **steps_per_second** (integer) - Optional - Specifies the number of steps per second for animated movement. ### Request Example ```json { "x": 800, "y": 600, "absolute": true, "duration": 2 } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation, e.g., "success". #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Register Click Event Callback (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Registers a callback function to be invoked when the left mouse button is clicked. ```python mouse.on_click(callback, args=()) ``` -------------------------------- ### Release Mouse Button (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Simulates releasing a mouse button. Defaults to the 'left' button. ```python mouse.release(button='left') ``` -------------------------------- ### Press and Release Mouse Buttons - Python Source: https://context7.com/boppreh/mouse/llms.txt Provides granular control over mouse button states, allowing buttons to be pressed down and held, then released. This is crucial for implementing drag-and-drop functionality or any operation requiring sustained button presses. It also includes a utility to check if a button is currently held. ```python import mouse import time # Hold down left button mouse.press(button='left') time.sleep(2) # Button stays pressed mouse.release(button='left') # Hold right button mouse.press(button='right') print("Right button is held") mouse.release(button='right') # Check if button is currently pressed mouse.press('left') if mouse.is_pressed('left'): print("Left button is pressed!") mouse.release('left') ``` -------------------------------- ### Right Mouse Click (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Simulates a single right mouse click. ```python mouse.right_click() ``` -------------------------------- ### Click Mouse Buttons - Python Source: https://context7.com/boppreh/mouse/llms.txt Simulates various mouse button clicks, including left, right, middle, and custom buttons (e.g., 'x', 'x2'). Clicks can be performed at the current cursor position or at a specified coordinate after moving the cursor. Supports single and double clicks. ```python import mouse # Left click at current position mouse.click(button='left') # Right click mouse.right_click() # Double click mouse.double_click(button='left') # Middle click mouse.click(button='middle') # Click at specific position mouse.move(400, 300) mouse.click() # Custom button clicks (for mice with extra buttons) mouse.click(button='x') mouse.click(button='x2') ``` -------------------------------- ### Register Right Click Event Callback (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Registers a callback function to be invoked when the right mouse button is clicked. ```python mouse.on_right_click(callback, args=()) ``` -------------------------------- ### Scroll Mouse Wheel Source: https://context7.com/boppreh/mouse/llms.txt Simulates scrolling the mouse wheel by a specified amount. Positive delta scrolls up, negative scrolls down. ```APIDOC ## POST /mouse/wheel ### Description Simulates mouse wheel scrolling. ### Method POST ### Endpoint /mouse/wheel ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **delta** (integer) - Required - The amount to scroll. Positive values scroll up, negative values scroll down. ### Request Example ```json { "delta": 5 } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation, e.g., "success". #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Move Mouse (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Moves the mouse cursor to a specified position or relative to the current position. Supports animated movement with a specified duration and steps per second. ```python mouse.move(x, y, absolute=True, duration=0, steps_per_second=120.0) ``` -------------------------------- ### Single Mouse Click (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Simulates a single click with the specified mouse button. Defaults to the 'left' button. ```python mouse.click(button='left') ``` -------------------------------- ### Register Double Click Event Callback (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Registers a callback function to be invoked when the left mouse button is double-clicked. ```python mouse.on_double_click(callback, args=()) ``` -------------------------------- ### Register Button Event Callback (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Registers a callback function to be invoked when specified mouse button events occur. Allows customization of buttons and event types (up, down, double). ```python mouse.on_button(callback, args=(), buttons=('left', 'middle', 'right', 'x', 'x2'), types=('up', 'down', 'double')) ``` -------------------------------- ### Press Mouse Button (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Simulates pressing a mouse button without releasing it. Defaults to the 'left' button. ```python mouse.press(button='left') ``` -------------------------------- ### Double Mouse Click (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Simulates a double click with the specified mouse button. Defaults to the 'left' button. ```python mouse.double_click(button='left') ``` -------------------------------- ### Mouse X Coordinate Field (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Represents the 'x' coordinate field, likely for internal use or specific event data. ```python mouse.X = 'x' ``` -------------------------------- ### Register Middle Click Event Callback (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Registers a callback function to be invoked when the middle mouse button is clicked. ```python mouse.on_middle_click(callback, args=()) ``` -------------------------------- ### Scroll Mouse Wheel - Python Source: https://context7.com/boppreh/mouse/llms.txt Simulates scrolling the mouse wheel. Positive values scroll the wheel upwards, while negative values scroll downwards. The `delta` parameter controls the magnitude of the scroll. This function is useful for automating scrolling actions in applications. ```python import mouse import time # Scroll up by 5 clicks mouse.wheel(delta=5) # Scroll down by 3 clicks mouse.wheel(delta=-3) # Scroll up one click at a time for i in range(10): mouse.wheel(1) time.sleep(0.1) # Large scroll down mouse.wheel(delta=-20) ``` -------------------------------- ### Check Button State - Python Source: https://context7.com/boppreh/mouse/llms.txt Allows checking the current state of a mouse button (pressed or not pressed). This is useful for conditional logic in scripts, such as waiting for a specific button to be engaged or disengaged before proceeding. It can be used in loops to monitor button activity. ```python import mouse import time # Start pressing the left button mouse.press('left') # Check button state if mouse.is_pressed('left'): print("Left button is currently pressed") else: print("Left button is not pressed") # Release and check again mouse.release('left') print(f"After release: {mouse.is_pressed('left')}") # False # Monitor button state in a loop print("Click and hold the right button...") while not mouse.is_pressed('right'): time.sleep(0.1) print("Right button detected!") ``` -------------------------------- ### Mouse X2 Coordinate Field (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Represents the 'x2' coordinate field, possibly for extended or alternative x-axis data. ```python mouse.X2 = 'x2' ``` -------------------------------- ### Wait for Mouse Button Event (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Blocks program execution until a specified mouse button performs a targeted event (up, down, double click). ```python mouse.wait(button='left', target_types=('up', 'down', 'double')) ``` -------------------------------- ### Check Button State Source: https://context7.com/boppreh/mouse/llms.txt Checks whether a specific mouse button is currently in a pressed state. ```APIDOC ## GET /mouse/is_pressed ### Description Checks whether a specific mouse button is currently pressed down. ### Method GET ### Endpoint /mouse/is_pressed ### Parameters #### Path Parameters None #### Query Parameters - **button** (string) - Required - The button to check ('left', 'right', 'middle', 'x', 'x2'). ### Request Example None (uses query parameters) ### Response #### Success Response (200) - **is_pressed** (boolean) - True if the button is pressed, false otherwise. #### Response Example ```json { "is_pressed": true } ``` ``` -------------------------------- ### WheelEvent Count Method (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Returns the number of occurrences of a specific `value` within the WheelEvent data. This method is part of the WheelEvent class. ```python WheelEvent.count(self, value) ``` -------------------------------- ### Mouse Button State Check (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md Checks if a specified mouse button is currently pressed. It defaults to checking the 'left' button. ```python mouse.is_pressed(button='left') ``` -------------------------------- ### WheelEvent Time Alias (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md An alias for field number 1 within the WheelEvent, likely representing the timestamp of the event. ```python WheelEvent.time ``` -------------------------------- ### WheelEvent Delta Alias (Python) Source: https://github.com/boppreh/mouse/blob/master/README.md An alias for field number 0 within the WheelEvent, likely representing the scroll delta. ```python WheelEvent.delta ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.