### Initialize Keyboard and Mouse Controller Source: https://context7.com/darlingzerox/feiyilai-python/llms.txt Initializes a keyboard and mouse controller instance by loading the DLL and opening the default device port. This is the first step before performing any input simulation actions. It returns a controller object with an active handle to the device. ```python import 飞易来键鼠 # Initialize the controller (automatically opens port 1) controller = 飞易来键鼠.键鼠模拟() # The controller is now ready to use # Returns: controller object with active handle to device ``` -------------------------------- ### Open Device Port with Custom Configuration Source: https://context7.com/darlingzerox/feiyilai-python/llms.txt Opens a specific device port or a device identified by VID/PID. This is useful when multiple devices are connected. The `Open` method targets a port number (1-126), while `Open_VidPid` uses vendor and product IDs. Remember to close the device when done. ```python import 飞易来键鼠 controller = 飞易来键鼠.键鼠模拟() # Open specific port number (1-126) controller.Open(1) # Opens port 1 (default for single device) # Or open device by VID/PID (for specific hardware) controller.Open_VidPid(0x1234, 0x5678) # Close the device when done controller.Close() # Returns: 0 on success, non-zero on failure ``` -------------------------------- ### Press Keyboard Keys Using Windows Key Codes Source: https://context7.com/darlingzerox/feiyilai-python/llms.txt Simulates keyboard key presses using Windows Virtual Key Codes. The `KeyPress2` function allows specifying the key code and a repeat count. It also supports simulating key combinations like Ctrl+C by managing key down and up states. ```python import 飞易来键鼠 import time from headers.VKCode import VKCode as KCode controller = 飞易来键鼠.键鼠模拟() # Press 'F' key once controller.KeyPress2(KCode['F'], 1) # Press 'A' key 3 times controller.KeyPress2(KCode['A'], 3) # Press combination: Ctrl+C controller.KeyDown2(KCode['LCONTROL']) controller.KeyPress2(KCode['C'], 1) controller.KeyUp2(KCode['LCONTROL']) # Press Space bar controller.KeyPress2(KCode['SPACE'], 1) # Press function key F1 controller.KeyPress2(KCode['F1'], 1) # Returns: 0 on success, -1 on failure ``` -------------------------------- ### Control Keyboard Key State (Down/Up) Source: https://context7.com/darlingzerox/feiyilai-python/llms.txt Manages the pressed and released states of individual keyboard keys. `KeyDown2` simulates pressing a key down, and `KeyUp2` releases it. This is essential for simulating hold-down actions or complex key combinations. `KeyState2` can check the current state of a simulated key. ```python import 飞易来键鼠 import time from headers.VKCode import VKCode as KCode controller = 飞易来键鼠.键鼠模拟() # Hold down Shift key controller.KeyDown2(KCode['LSHIFT']) time.sleep(0.1) # Type "HELLO" while Shift is held controller.KeyPress2(KCode['H'], 1) controller.KeyPress2(KCode['E'], 1) controller.KeyPress2(KCode['L'], 2) controller.KeyPress2(KCode['O'], 1) # Release Shift key controller.KeyUp2(KCode['LSHIFT']) # Check if key is pressed (only works for simulated keys) state = controller.KeyState2(KCode['LSHIFT']) # Returns: 0=up, 1=down, -1=error # Release all keys at once controller.ReleaseAllKey() # Returns: 0 on success ``` -------------------------------- ### Perform Mouse Clicks Source: https://context7.com/darlingzerox/feiyilai-python/llms.txt Simulates mouse button clicks with a configurable repeat count. Supports left, right, and middle clicks. `LeftDoubleClick` is also provided for simulating double-clicks. ```python import 飞易来键鼠 controller = 飞易来键鼠.键鼠模拟() # Single left click controller.LeftClick(1) # Double left click (3 times) controller.LeftDoubleClick(3) # Right click once controller.RightClick(1) ``` -------------------------------- ### Check Keyboard LED States Source: https://context7.com/darlingzerox/feiyilai-python/llms.txt Reads the current state of keyboard indicator LEDs, specifically NumLock, CapsLock, and ScrollLock. This function allows querying whether these LEDs are currently on or off, returning 0 for off, 1 for on, and -1 for an error. ```python import 飞易来键鼠 controller = 飞易来键鼠.键鼠模拟() # Check NumLock LED state numlock_state = controller.NumLockLedState() # Returns: 0=off, 1=on, -1=error # Check CapsLock LED state capslock_state = controller.CapsLockLedState() # Returns: 0=off, 1=on, -1=error # Check ScrollLock LED state scrolllock_state = controller.ScrollLockLedState() # Returns: 0=off, 1=on, -1=error print(f"NumLock: {'ON' if numlock_state == 1 else 'OFF'}") print(f"CapsLock: {'ON' if capslock_state == 1 else 'OFF'}") print(f"ScrollLock: {'ON' if scrolllock_state == 1 else 'OFF'}") ``` -------------------------------- ### Input Text Strings with Different Encodings Source: https://context7.com/darlingzerox/feiyilai-python/llms.txt Types entire strings using different character encodings. The library supports ASCII, GBK (for Chinese characters), and Unicode. Note that newline (`\n`) and carriage return (`\r`) escape characters are not directly supported and must be handled manually if needed. ```python import 飞易来键鼠 controller = 飞易来键鼠.键鼠模拟() # Input ASCII string ascii_text = "Hello World 123!".encode('ascii') controller.KeyInputString(ascii_text, len(ascii_text)) # Input Chinese text (GBK encoding) chinese_text = "你好世界ABC123".encode('gbk') controller.KeyInputStringGBK(chinese_text, len(chinese_text)) # Input Unicode string unicode_text = "Hello世界😊".encode('utf-16le') controller.KeyInputStringUnicode(unicode_text, len(unicode_text)) # Note: \n and \r escape characters are not supported # Returns: 0 on success, -1 on failure ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.