### Complete Automation Example Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md This example demonstrates a full automation sequence using HIDController and SerialTransport. It opens Spotlight, types a command, and executes it. Ensure the correct serial port and baudrate are specified. ```python from pych9329 import HIDController, SerialTransport import time with SerialTransport(port='/dev/ttyUSB0', baudrate=115200) as transport: controller = HIDController(transport, screen_width=1920, screen_height=1080) # Open Spotlight (macOS) controller.hotkey('cmd', 'space') time.sleep(0.5) # Type application name controller.write('Terminal') time.sleep(0.5) # Press Enter controller.press('enter') time.sleep(1) # Type command controller.write('echo "Hello from CH9329!"') controller.press('enter') ``` -------------------------------- ### Install PyCH9329-HID Package Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Install the package using pip. Ensure Python 3 and pyserial are installed. ```bash pip install pych9329-hid ``` -------------------------------- ### Basic Usage - Low Level Protocol Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Demonstrates sending keyboard and mouse reports, and retrieving device information using the low-level CH9329 protocol. Requires SerialTransport setup. ```python from pych9329 import CH9329, SerialTransport # Create transport and CH9329 instance with SerialTransport(port='/dev/ttyUSB0', baudrate=115200) as transport: ch9329 = CH9329(transport) # Send keyboard report ch9329.send_keyboard(modifier=0, keycodes=[0x04]) # Send relative mouse movement ch9329.send_mouse_rel(dx=10, dy=5, buttons=0x01) # Send absolute mouse position ch9329.send_mouse_abs(x=100, y=200, buttons=0x01) # Get device information info = ch9329.get_info() print(f"Version: {info['version']}") print(f"USB Connected: {info['usb_connected']}") print(f"Num Lock: {info['num_lock_on']}") print(f"Caps Lock: {info['caps_lock_on']}") print(f"Scroll Lock: {info['scroll_lock_on']}") ``` -------------------------------- ### Configuration and USB Descriptors Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Shows how to get, modify, and apply CH9329 configurations, set custom USB descriptors, and restore factory defaults. Includes chip reset. ```python from pych9329 import CH9329, SerialTransport with SerialTransport(port='/dev/ttyUSB0', baudrate=115200) as transport: ch9329 = CH9329(transport) # Get current configuration config = ch9329.get_config() # CH9329Config: # Work Mode: Keyboard+Mouse (Hardware) # Serial Mode: Protocol mode (Hardware) # Address: 0x00 # Baud Rate: 9600 # Packet Interval: 3ms # VID: 0x861A # PID: 0x29E1 # Keyboard Submit Interval: 0ms # Keyboard Release Delay: 1ms # Auto Enter Flag: 0 # Enter Characters: 0d00000000000000 # Filter Strings: 0000000000000000 # Custom Descriptor Enable: {'vendor': True, 'product': False, 'sn': False} # Keyboard Fast Submission: 0 # Modify configuration config.baudrate = 9600 config.vid = 0x1234 config.pid = 0x5678 # Enable vendor and product string descriptors config.custom_descriptor_enable = {'vendor': True, 'product': True, 'sn': False} # Apply configuration if ch9329.set_config(config): print("Configuration updated successfully!") # Set USB descriptors ch9329.set_usb_descriptor(0x00, "My Company") # Vendor ch9329.set_usb_descriptor(0x01, "CH9329 Keyboard") # Product ch9329.set_usb_descriptor(0x02, "SN-12345") # Serial Number # Read back USB descriptors vendor = ch9329.get_usb_descriptor(0x00) product = ch9329.get_usb_descriptor(0x01) serial = ch9329.get_usb_descriptor(0x02) print(f"Vendor: {vendor}, Product: {product}, SN: {serial}") # Restore factory defaults if ch9329.set_config_to_default(): print("Factory settings restored!") # Reset chip ch9329.chip_reset() ``` -------------------------------- ### Get Device Information Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Retrieves device information as a dictionary. ```python controller.getDeviceInfo() ``` -------------------------------- ### Configuration Management Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Methods for managing device configuration, including getting, setting, and restoring default settings, as well as performing a chip reset. ```APIDOC ## Configuration Management ### `get_config()` #### Description Get device configuration. #### Returns `CH9329Config` object or `None` ### `set_config(config)` #### Description Set device configuration. #### Parameters - **config** (`CH9329Config`) #### Returns `bool` - True if successful ### `set_config_to_default()` #### Description Restore factory default settings. #### Returns `bool` - True if successful ### `chip_reset()` #### Description Perform software reset. #### Returns `bool` - True if successful ``` -------------------------------- ### Control Button Event Handlers Source: https://github.com/zonghai-li/pych9329-hid/blob/main/tests/functional/test_bench.html Manages the start/stop capturing functionality and clears the log and canvas. The 'start' button toggles the capturing state, while 'stop' and 'clear-all' provide reset functionalities. ```javascript startBtn.onclick = () => { capturing = true; startBtn.classList.add('on'); appendLog({type:'sys', key:'start'}); } document.getElementById('stop').onclick = () => { capturing = false; startBtn.classList.remove('on'); appendLog({type:'sys', key:'stop'}); } document.getElementById('clear-all').onclick = () => { logEl.innerHTML = ''; clearCanvas(); document.getElementById('notepad').value = ''; } ``` -------------------------------- ### Canvas Drag and Draw Logic Source: https://github.com/zonghai-li/pych9329-hid/blob/main/tests/functional/test_bench.html Manages drawing on a canvas via mouse events (mousedown, mousemove, mouseup), capturing drag start, movement, and end, along with associated coordinates and modifier keys. ```javascript function getCanvasPos(e) { const rect = canvas.getBoundingClientRect(); return { x: e.clientX - rect.left, y: e.clientY - rect.top }; } canvas.addEventListener('mousedown', (e) => { if(!capturing) return; if(e.button !== 0) return; // Only allow left mouse button isDrawing = true; const pos = getCanvasPos(e); ctx.beginPath(); ctx.moveTo(pos.x, pos.y); updateMouseButtonPills(e); appendLog({type:'drag', key:'Start', shift:e.shiftKey, meta:e.metaKey, detail:`Scr(${e.screenX},${e.screenY})`}); }); canvas.addEventListener('mousemove', (e) => { if(!isDrawing || !capturing) return; updateMouseButtonPills(e); const pos = getCanvasPos(e); ctx.lineTo(pos.x, pos.y); ctx.stroke(); }); canvas.addEventListener('mouseup', () => { isDrawing = false; ctx.closePath(); updateMouseButtonPills(event); appendLog({type:'drag', key:'End'}); }); function clearCanvas() { ctx.clearRect(0, 0, canvas.width, canvas.height); } ``` -------------------------------- ### Import HIDController Options Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Choose between the full package name or a recommended short alias for importing HIDController. ```python # Option 1: Full package name from pych9329_hid import HIDController # Option 2: Short alias (recommended) from pych9329 import HIDController ``` -------------------------------- ### Set USB Product String Descriptor Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Sets the USB product string descriptor. Returns true if successful. ```python controller.set_usb_descriptor(0x01, "MyProduct") ``` -------------------------------- ### Set Device Configuration Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Sets the device configuration. Returns true if successful. ```python controller.set_config(config) ``` -------------------------------- ### Press and Hold a Key Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Simulates pressing and holding a keyboard key. Use this in combination with `keyUp`. ```python controller.keyDown('shift') ``` -------------------------------- ### Set USB Vendor String Descriptor Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Sets the USB vendor string descriptor. Returns true if successful. ```python controller.set_usb_descriptor(0x00, "MyVendor") ``` -------------------------------- ### CH9329.get_info() Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Retrieves essential information about the connected CH9329 device, including firmware version and lock key states. ```APIDOC ## CH9329.get_info() ### Description Get device information. ### Method `get_info()` ### Returns `dict` with keys: `version`, `usb_connected`, `num_lock_on`, `caps_lock_on`, `scroll_lock_on` ``` -------------------------------- ### Perform Software Reset Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Performs a software reset on the device. Returns true if successful. ```python controller.chip_reset() ``` -------------------------------- ### Restore Factory Default Configuration Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Restores the device to its factory default settings. Returns true if successful. ```python controller.set_config_to_default() ``` -------------------------------- ### List Available Serial Devices Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Use this snippet to find and display available serial ports on your system. It iterates through detected ports and prints their device path and description. ```python import serial.tools.list_ports ports = serial.tools.list_ports.comports() for port in ports: print(f"Port: {port.device}, Description: {port.description}") ``` -------------------------------- ### Release a Key Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Simulates releasing a keyboard key. Use this after `keyDown`. ```python controller.keyUp('shift') ``` -------------------------------- ### Press Key Combination Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Simulates pressing a combination of keys, like hotkeys or shortcuts. ```python controller.hotkey('cmd', 'a') ``` -------------------------------- ### Press and Release a Key Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Simulates pressing and releasing a keyboard key. Use this for single key presses. ```python controller.press('a') ``` -------------------------------- ### Press Numpad Key Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Simulates pressing a key on the numeric keypad. ```python controller.numpadPress('7') ``` -------------------------------- ### Scrollable Container Initialization Source: https://github.com/zonghai-li/pych9329-hid/blob/main/tests/functional/test_bench.html Initializes and populates vertical and horizontal scrollable containers with grid cells, setting up event listeners to track scroll position, delta, and direction. ```javascript function initScrollContainers() { const vscroll = document.getElementById('vscroll-container'); const hscroll = document.getElementById('hscroll-container'); if(!vscroll || !hscroll) return; const colors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#FFA07A', '#98D8C8', '#F7DC6F', '#BB8FCE', '#85C1E2', '#F8B739', '#6C5CE7']; // 竖直滚动 - 20x20 网格 const vGrid = document.createElement('div'); vGrid.className = 'grid-content'; for(let i = 0; i < 400; i++) { const cell = document.createElement('div'); cell.className = 'grid-cell'; cell.style.backgroundColor = colors[i % colors.length]; cell.textContent = i + 1; vGrid.appendChild(cell); } vscroll.appendChild(vGrid); // 水平滚动 - 40x6 网格 const hGrid = document.createElement('div'); hGrid.className = 'grid-content h-scroll'; for(let i = 0; i < 240; i++) { const cell = document.createElement('div'); cell.className = 'grid-cell'; cell.style.backgroundColor = colors[i % colors.length]; cell.textContent = i + 1; hGrid.appendChild(cell); } hscroll.appendChild(hGrid); // 竖直滚动事件监听 let lastVScroll = 0; vscroll.addEventListener('scroll', (e) => { const current = e.target.scrollTop; const delta = current - lastVScroll; const direction = delta > 0 ? '↓' : delta < 0 ? '↑' : ''; document.getElementById('vscroll-pos').textContent = current + 'px'; document.getElementById('vscroll-delta').textContent = (delta >= 0 ? '+' : '') + delta + 'px'; document.getElementById('vscroll-dir').textContent = direction; if(capturing) { appendLog({ type: 'vscroll', key: 'VScroll', detail: `Position: ${current}px, Delta: ${delta > 0 ? '+' : ''}${delta}px ${direction}` }); } lastVScroll = current; }); // 水平滚动事件监听 let lastHScroll = 0; hscroll.addEventListener('scroll', (e) => { const current = e.target.scrollLeft; const delta = current - lastHScroll; const direction = delta > 0 ? '→' : delta < 0 ? '←' : ''; document.getElementById('hscroll-pos').textContent = current + 'px'; document.getElementById('hscroll-delta').textContent = (delta >= 0 ? '+' : '') + delta + 'px'; document.getElementById('hscroll-dir').textContent = direction; if(capturing) { appendLog({ type: 'hscroll', key: 'HScroll', detail: `Position: ${current}px, Delta: ${delta > 0 ? '+' : ''}${delta}px ${direction}` }); } lastHScroll = current; }); } initScrollContainers(); ``` -------------------------------- ### Click Mouse Button Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Simulates a mouse button click. Supports specifying the button and number of clicks. ```python controller.click('left', clicks=2) ``` -------------------------------- ### Mouse Event Handling Source: https://github.com/zonghai-li/pych9329-hid/blob/main/tests/functional/test_bench.html Handles mousedown, dblclick, and contextmenu events for a button, logging event details. ```javascript const btn = document.getElementById('btn'); function handleMouse(e, type) { const isCorrect = true; appendLog({ type: type, key: e.button, shift: e.shiftKey, ctrl: e.ctrlKey, alt: e.altKey, meta: e.metaKey, detail: `Pos:(${e.screenX},${e.screenY}) [${isCorrect?'✓':'✗'}]` }); }; btn.addEventListener('mousedown', (e) => handleMouse(e, 'mousedown')); btn.addEventListener('dblclick', (e) => handleMouse(e, 'dblclick')); btn.addEventListener('contextmenu', (e) => handleMouse(e, 'contextmenu')); ``` -------------------------------- ### USB String Descriptors Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Methods for retrieving and setting USB string descriptors, such as vendor, product, and serial number. ```APIDOC ## USB String Descriptors ### `get_usb_descriptor(type)` #### Description Get USB string descriptor. #### Parameters - **type** (int) - USB Descriptor Type (e.g., 0x00 for Vendor, 0x01 for Product, 0x02 for Serial Number) #### Returns `str` or `None` ### `set_usb_descriptor(type, string)` #### Description Set USB string descriptor. #### Parameters - **type** (int) - USB Descriptor Type - **string** (str) - The string to set for the descriptor #### Returns `bool` - True if successful ``` -------------------------------- ### Global Keyboard Event Listener Source: https://github.com/zonghai-li/pych9329-hid/blob/main/tests/functional/test_bench.html Captures and logs all keydown and keyup events globally, recording the key pressed, its code, and modifier key states (shift, ctrl, alt, meta). ```javascript window.addEventListener('keydown', (e) => { if(!capturing) return; appendLog({type:'keydown', key:e.key, code:e.code, shift:e.shiftKey, ctrl:e.ctrlKey, alt:e.altKey, meta:e.metaKey}); }); window.addEventListener('keyup', (e) => { if(!capturing) return; appendLog({type:'keyup', key:e.key, code:e.code, shift:e.shiftKey, ctrl:e.ctrlKey, alt:e.altKey, meta:e.metaKey}); }); ``` -------------------------------- ### Press and Hold Mouse Button Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Simulates pressing and holding a mouse button. Use in conjunction with `mouseUp`. ```python controller.mouseDown('left') ``` -------------------------------- ### High-Level HID Controller Operations Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Utilizes the HIDController for simplified keyboard, mouse, and scrolling operations. Requires SerialTransport and screen dimensions. ```python from pych9329 import HIDController, SerialTransport # Create HID controller with SerialTransport(port='/dev/ttyUSB0', baudrate=115200) as transport: controller = HIDController(transport, screen_width=1920, screen_height=1080) # Keyboard operations controller.press('a') controller.write('Hello World') controller.hotkey('cmd', 'space') # Mouse operations controller.moveTo(100, 200, duration=0.5) controller.click(button='left') controller.dragRel(50, 30) # Scrolling controller.scroll(5) # Scroll up controller.hscroll(-2) # Scroll left ``` -------------------------------- ### Release Mouse Button Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Simulates releasing a mouse button. Use after `mouseDown`. ```python controller.mouseUp('left') ``` -------------------------------- ### Set USB Serial Number String Descriptor Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Sets the USB serial number string descriptor. Returns true if successful. ```python controller.set_usb_descriptor(0x02, "12345") ``` -------------------------------- ### Send Keyboard Report Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Sends a keyboard report with specified modifiers and keycodes. Returns true if successful. ```python controller.send_keyboard(modifier, keycodes) ``` -------------------------------- ### HIDController Hardware Operations Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md High-level methods for hardware-related operations, such as resetting the cursor and retrieving device information. ```APIDOC ## HIDController (High-Level API) - Hardware Operations ### `reset()` #### Description Reset cursor to (0,0). #### Returns None ### `getDeviceInfo()` #### Description Get device information. #### Returns `dict` with device info ``` -------------------------------- ### Horizontal Scroll Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Simulates horizontal scrolling by a specified number of clicks. ```python controller.hscroll(-2) ``` -------------------------------- ### Drag Mouse to Coordinates Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Simulates dragging the mouse to absolute coordinates (x, y) with the button held down. ```python controller.dragTo(100, 200) ``` -------------------------------- ### Mouse Operations Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Methods for sending mouse movements (relative and absolute) and button events. ```APIDOC ## Mouse Operations ### `send_mouse_rel(dx, dy, buttons, wheel)` #### Description Send relative mouse movement. #### Parameters - **dx** (int) - Change in x-coordinate - **dy** (int) - Change in y-coordinate - **buttons** (int) - Mouse buttons state - **wheel** (int) - Mouse wheel movement #### Returns `bool` - True if successful ### `send_mouse_abs(x, y, buttons, wheel)` #### Description Send absolute mouse position. #### Parameters - **x** (int) - Absolute x-coordinate - **y** (int) - Absolute y-coordinate - **buttons** (int) - Mouse buttons state - **wheel** (int) - Mouse wheel movement #### Returns `bool` - True if successful ``` -------------------------------- ### HIDController Keyboard Operations Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md High-level methods for controlling keyboard input, including pressing, holding, releasing keys, typing text, and hotkeys. ```APIDOC ## HIDController (High-Level API) - Keyboard Operations ### `press(key)` #### Description Press and release a key. #### Parameters - **key** (str) - The key to press and release. #### Example `controller.press('a')` ### `keyDown(key)` #### Description Press and hold a key. #### Parameters - **key** (str) - The key to press and hold. #### Example `controller.keyDown('shift')` ### `keyUp(key)` #### Description Release a key. #### Parameters - **key** (str) - The key to release. #### Example `controller.keyUp('shift')` ### `write(text)` #### Description Type a string. #### Parameters - **text** (str) - The string to type. #### Example `controller.write('Hello\n')` ### `hotkey(*keys)` #### Description Press a key combination. #### Parameters - **keys** (str) - Variable number of keys to press in combination. #### Example `controller.hotkey('cmd', 'a')` ### `releaseAllKey()` #### Description Release all keyboard keys. ### `numpadPress(key)` #### Description Press a numpad key. #### Parameters - **key** (str) - The numpad key to press. #### Example `controller.numpadPress('7')` ### `numpadWrite(text)` #### Description Type numpad characters. #### Parameters - **text** (str) - The string of numpad characters to type. #### Example `controller.numpadWrite('123')` ``` -------------------------------- ### HIDController Scrolling Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md High-level methods for performing mouse wheel scrolling, both vertically and horizontally. ```APIDOC ## HIDController (High-Level API) - Scrolling ### `scroll(clicks)` #### Description Perform a vertical scroll. #### Parameters - **clicks** (int) - The number of scroll clicks (positive for down, negative for up). #### Example `controller.scroll(5)` ### `hscroll(clicks)` #### Description Perform a horizontal scroll. #### Parameters - **clicks** (int) - The number of horizontal scroll clicks (positive for right, negative for left). #### Example `controller.hscroll(-2)` ``` -------------------------------- ### Send Relative Mouse Movement Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Sends a relative mouse movement report. Returns true if successful. ```python controller.send_mouse_rel(dx, dy, buttons, wheel) ``` -------------------------------- ### HIDController Mouse Movement Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md High-level methods for controlling mouse cursor movement, both to absolute coordinates and relative positions. ```APIDOC ## HIDController (High-Level API) - Mouse Movement ### `moveTo(x, y, duration)` #### Description Move the mouse cursor to specified coordinates. #### Parameters - **x** (int) - The target x-coordinate. - **y** (int) - The target y-coordinate. - **duration** (float) - The time in seconds to complete the movement (optional). #### Example `controller.moveTo(100, 200, duration=0.5)` ### `moveRel(dx, dy, duration)` #### Description Move the mouse cursor relatively from its current position. #### Parameters - **dx** (int) - The change in the x-coordinate. - **dy** (int) - The change in the y-coordinate. - **duration** (float) - The time in seconds to complete the movement (optional). #### Example `controller.moveRel(10, 5)` ``` -------------------------------- ### Vertical Scroll Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Simulates vertical scrolling by a specified number of clicks. ```python controller.scroll(5) ``` -------------------------------- ### Send Absolute Mouse Position Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Sends an absolute mouse position report. Returns true if successful. ```python controller.send_mouse_abs(x, y, buttons, wheel) ``` -------------------------------- ### Keyboard Operations Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Methods for sending keyboard reports, including key codes and modifiers. ```APIDOC ## Keyboard Operations ### `send_keyboard(modifier, keycodes)` #### Description Send keyboard report. #### Parameters - **modifier** (int) - Modifier keys - **keycodes** (list of int) - Key codes to send #### Returns `bool` - True if successful ``` -------------------------------- ### Drag Mouse Relatively Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Simulates dragging the mouse by a relative amount (dx, dy) with the button held down. ```python controller.dragRel(50, 30) ``` -------------------------------- ### HIDController Mouse Button Operations Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md High-level methods for controlling mouse button actions, including clicks, presses, and releases. ```APIDOC ## HIDController (High-Level API) - Mouse Button Operations ### `click(button, clicks)` #### Description Click a mouse button. #### Parameters - **button** (str) - The mouse button to click ('left', 'right', 'middle'). - **clicks** (int) - The number of clicks (default is 1). #### Example `controller.click('left', clicks=2)` ### `mouseDown(button)` #### Description Press and hold a mouse button. #### Parameters - **button** (str) - The mouse button to press. #### Example `controller.mouseDown('left')` ### `mouseUp(button)` #### Description Release a mouse button. #### Parameters - **button** (str) - The mouse button to release. #### Example `controller.mouseUp('left')` ### `releaseMouseButton()` #### Description Release all mouse buttons. #### Example `controller.releaseMouseButton()` ``` -------------------------------- ### Type a String Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Types a given string using the keyboard. Handles special characters and newlines. ```python controller.write('Hello\n') ``` -------------------------------- ### Release All Keyboard Keys Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Releases all currently pressed keyboard keys. ```python controller.releaseAllKey() ``` -------------------------------- ### Move Mouse to Coordinates Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Moves the mouse cursor to absolute coordinates (x, y) over a specified duration. ```python controller.moveTo(100, 200, duration=0.5) ``` -------------------------------- ### Read All Available Data from Serial Port Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Reads all currently available bytes from the serial port. ```python transport.read_all() ``` -------------------------------- ### HIDController Drag Operations Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md High-level methods for performing drag operations with the mouse, both relative and to absolute coordinates. ```APIDOC ## HIDController (High-Level API) - Drag Operations ### `dragRel(dx, dy)` #### Description Perform a relative drag operation. #### Parameters - **dx** (int) - The relative change in the x-coordinate. - **dy** (int) - The relative change in the y-coordinate. #### Example `controller.dragRel(50, 30)` ### `dragTo(x, y)` #### Description Perform a drag operation to specified coordinates. #### Parameters - **x** (int) - The target x-coordinate. - **y** (int) - The target y-coordinate. #### Example `controller.dragTo(100, 200)` ``` -------------------------------- ### Write Raw Bytes to Serial Port Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Writes raw bytes directly to the serial port. ```python transport.write(data) ``` -------------------------------- ### SerialTransport Layer Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Methods for interacting with the serial transport layer, including writing raw data, reading data, and managing the port connection. ```APIDOC ## SerialTransport (Transport Layer) ### `write(data)` #### Description Write raw bytes to port. #### Parameters - **data** (bytes) - The bytes to write. #### Returns None ### `read(size)` #### Description Read up to `size` bytes. #### Parameters - **size** (int) - The maximum number of bytes to read. #### Returns `bytes` read (may be empty on timeout) ### `read_all()` #### Description Read all available data. #### Returns All available bytes ### `is_open()` #### Description Check if port is open. #### Returns `bool` ### `close()` #### Description Close the serial port. #### Returns None ``` -------------------------------- ### Move Mouse Relatively Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Moves the mouse cursor by a relative amount (dx, dy). ```python controller.moveRel(10, 5) ``` -------------------------------- ### Release All Mouse Buttons Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Releases all currently pressed mouse buttons. ```python controller.releaseMouseButton() ``` -------------------------------- ### Read Bytes from Serial Port Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Reads up to a specified number of bytes from the serial port. May return empty bytes on timeout. ```python transport.read(size) ``` -------------------------------- ### Check if Serial Port is Open Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Returns a boolean indicating whether the serial port is currently open. ```python transport.is_open() ``` -------------------------------- ### Reset Cursor Position Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Resets the mouse cursor position to (0,0). ```python controller.reset() ``` -------------------------------- ### Type Numpad Characters Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Types a string of numeric characters using the numpad. ```python controller.numpadWrite('123') ``` -------------------------------- ### Close Serial Port Source: https://github.com/zonghai-li/pych9329-hid/blob/main/README.md Closes the serial port connection. ```python transport.close() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.