### Install AsyncVNC Source: https://asyncvnc.readthedocs.io Installs the AsyncVNC package using pip. This package requires Python 3.7 or newer. ```bash pip install asyncvnc ``` -------------------------------- ### Connect to Local Unauthenticated VNC Server Source: https://asyncvnc.readthedocs.io Connects to a local VNC server without authentication, prints client information, and then disconnects. This is a basic connection example. ```python import asyncio, asyncvnc async def run_client(): async with asyncvnc.connect('localhost') as client: print(client) asyncio.run(run_client()) ``` -------------------------------- ### connect() Source: https://asyncvnc.readthedocs.io Establishes an asynchronous connection to a VNC server. ```APIDOC ## connect() ### Description Establishes an asynchronous connection to a VNC server. ### Parameters (No specific parameters are detailed in the source.) ### Returns (No specific return value is detailed in the source.) ``` -------------------------------- ### Connect and Send Keyboard Input Source: https://asyncvnc.readthedocs.io Connects to a VNC server, sends 'hello world!' via keyboard input, and then disconnects. Requires authentication details if the server is password-protected. ```python import asyncio, asyncvnc async def run_client(): with asyncvnc.connect('localhost', 5900, 'username', 'password') as client: client.keyboard.write('hello world!') asyncio.run(run_client()) ``` -------------------------------- ### asyncvnc.connect Source: https://asyncvnc.readthedocs.io Establishes an asynchronous VNC client connection. It acts as an async context manager, yielding a connected `Client` instance upon successful connection. ```APIDOC ## asyncvnc.connect ### Description Make a VNC client connection. This is an async context manager that returns a connected `Client` instance. ### Parameters - **_host** (str) - Required - The hostname or IP address of the VNC server. - **_port** (int) - Optional - The port number for the VNC connection. Defaults to 5900. - **_username** (str | None) - Optional - The username for authentication. - **_password** (str | None) - Optional - The password for authentication. - **_host_key** (RSAPublicKey | None) - Optional - The server's public key (used on Mac). - **_opener** (None) - Optional - An opener function (currently unused or not specified). ``` -------------------------------- ### asyncvnc.Keyboard Source: https://asyncvnc.readthedocs.io Provides methods for interacting with the virtual keyboard on the VNC server. ```APIDOC ## asyncvnc.Keyboard ### Description Virtual keyboard. ### Methods - **hold(_* keys: str)** A context manager that presses the given keys upon entry and releases them in reverse order upon exit. - **press(_* keys: str)** Presses all the provided keys and then releases them in reverse order. - **write(_text: str)** Simulates typing by pressing and releasing each character in the provided text string sequentially. ``` -------------------------------- ### Take Screenshot and Save as PNG Source: https://asyncvnc.readthedocs.io Retrieves the VNC server's framebuffer as an RGBA numpy array, converts it to a PIL Image, and saves it as a PNG file. Requires Pillow library. ```python import asyncio, asyncvnc from PIL import Image async def run_client(): async with asyncvnc.connect('localhost') as client: # Retrieve pixels as a 3D numpy array pixels = await client.screenshot() # Save as PNG using PIL/pillow image = Image.fromarray(pixels) image.save('screenshot.png') asyncio.run(run_client()) ``` -------------------------------- ### Keyboard Class Source: https://asyncvnc.readthedocs.io Provides methods for simulating keyboard input on the VNC server. ```APIDOC ## Keyboard Class ### Description Provides methods for simulating keyboard input on the VNC server, including holding keys, pressing keys, and writing text. ### Methods #### `Keyboard.hold(key)` Holds down a specific key. #### `Keyboard.press(key)` Simulates pressing and releasing a specific key. #### `Keyboard.write(text)` Writes a string of text to the VNC server. ``` -------------------------------- ### Write Text to VNC Server Source: https://asyncvnc.readthedocs.io Simulates typing a string of text into the VNC server. Characters are queued and sent sequentially. ```python client.keyboard.write('hi there!') ``` -------------------------------- ### Mouse Class Source: https://asyncvnc.readthedocs.io Provides methods for simulating mouse input on the VNC server. ```APIDOC ## Mouse Class ### Description Provides methods for simulating mouse input on the VNC server, including moving the cursor, clicking buttons, and scrolling. ### Methods #### `Mouse.hold(button)` Holds down a mouse button. #### `Mouse.click(button)` Simulates a click with the specified mouse button. #### `Mouse.middle_click()` Simulates a middle mouse button click. #### `Mouse.right_click()` Simulates a right mouse button click. #### `Mouse.scroll_up()` Simulates scrolling the mouse wheel up. #### `Mouse.scroll_down()` Simulates scrolling the mouse wheel down. #### `Mouse.move(x, y)` Moves the mouse cursor to the specified coordinates (x, y). ``` -------------------------------- ### Connect to Traditional VNC Server with Password Source: https://asyncvnc.readthedocs.io Connects to a traditional VNC server requiring only a password for authentication. It's recommended to use this on localhost or via an SSH tunnel due to security concerns. ```python async with asyncvnc.connect('localhost', password='password'): ... ``` -------------------------------- ### Hold Keyboard Key Source: https://asyncvnc.readthedocs.io Demonstrates holding down a keyboard key (e.g., 'Ctrl') using a context manager. This is useful for simulating key combinations. ```python with client.keyboard.hold('Ctrl'): ... ``` -------------------------------- ### asyncvnc.Clipboard Source: https://asyncvnc.readthedocs.io Manages the VNC shared clipboard, allowing text to be read and written. ```APIDOC ## asyncvnc.Clipboard ### Description Shared clipboard. ### Attributes - **text** (str) - The current text content of the clipboard. Defaults to an empty string. ### Methods - **write(_text: str)** Sends the provided text to the VNC server's clipboard. ``` -------------------------------- ### Client Class Source: https://asyncvnc.readthedocs.io Represents a client connection to a VNC server, providing access to various functionalities. ```APIDOC ## Client Class ### Description Represents a client connection to a VNC server, providing access to various functionalities like clipboard, keyboard, mouse, and video streams. ### Methods #### `Client.read()` Reads data from the VNC connection. #### `Client.drain()` Clears any buffered data from the VNC connection. #### `Client.screenshot()` Takes a screenshot of the VNC server's display. ### Attributes #### `Client.clipboard` Provides access to the VNC server's clipboard. #### `Client.keyboard` Provides access to control the VNC server's keyboard. #### `Client.mouse` Provides access to control the VNC server's mouse. #### `Client.video` Provides access to the VNC server's video stream. #### `Client.host_key` (Description not available in source.) ``` -------------------------------- ### asyncvnc.Screen Source: https://asyncvnc.readthedocs.io Represents a detected physical screen within the VNC session. ```APIDOC ## asyncvnc.Screen ### Description Computer screen. ### Attributes - **x** (int) - The horizontal position of the screen in pixels. - **y** (int) - The vertical position of the screen in pixels. - **width** (int) - The width of the screen in pixels. - **height** (int) - The height of the screen in pixels. ### Properties - **slices** (Tuple[slice, slice]) - An object that can be used to crop the video buffer to this screen's dimensions. - **score** (float) - A confidence score indicating how likely this detection represents a real screen. It's proportional to the pixel area and adjusted for non-standard aspect ratios. ``` -------------------------------- ### Video Class Source: https://asyncvnc.readthedocs.io Provides access to the VNC server's video stream and its properties. ```APIDOC ## Video Class ### Description Provides access to the VNC server's video stream and its properties, including dimensions and raw data. ### Methods #### `Video.refresh()` Refreshes the video stream data. #### `Video.as_rgba()` Returns the video frame data as RGBA. #### `Video.is_complete()` Checks if the current video frame is complete. #### `Video.detect_screens()` Detects the screens available on the VNC server. ### Attributes #### `Video.name` (Description not available in source.) #### `Video.width` The width of the video stream. #### `Video.height` The height of the video stream. #### `Video.mode` (Description not available in source.) #### `Video.data` (Description not available in source.) ``` -------------------------------- ### Press Keyboard Keys Source: https://asyncvnc.readthedocs.io Simulates pressing multiple keyboard keys in sequence. Keys are stacked, meaning 'Ctrl' and 'c' would be pressed together if used in a hold context, but here they are pressed sequentially. ```python client.keyboard.press('Ctrl', 'c') ``` -------------------------------- ### Hold Mouse Button Source: https://asyncvnc.readthedocs.io Demonstrates holding down a mouse button using a context manager. This can be used for dragging or other continuous mouse actions. ```python with client.mouse.hold(): ... ``` -------------------------------- ### Click Mouse Button Source: https://asyncvnc.readthedocs.io Simulates a single left mouse click at the current cursor position. ```python client.mouse.click() ``` -------------------------------- ### Connect to macOS VNC Server with Authentication Source: https://asyncvnc.readthedocs.io Connects to a macOS VNC server using username and password authentication. The ellipsis indicates where further client operations would be placed. ```python async with asyncvnc.connect('localhost', username='user123', password='h4x0r'): ... ``` -------------------------------- ### Clipboard Class Source: https://asyncvnc.readthedocs.io Manages clipboard operations for the VNC connection. ```APIDOC ## Clipboard Class ### Description Manages clipboard operations for the VNC connection, allowing reading and writing text. ### Methods #### `Clipboard.write(text)` Writes the given text to the VNC server's clipboard. ### Attributes #### `Clipboard.text` Gets or sets the text content of the clipboard. ``` -------------------------------- ### asyncvnc.Mouse Source: https://asyncvnc.readthedocs.io Controls the virtual mouse cursor on the VNC server. ```APIDOC ## asyncvnc.Mouse ### Description Virtual mouse. ### Methods - **hold(_button: int = 0)** A context manager that presses the specified mouse button upon entry and releases it upon exit. Defaults to the left button (0). - **click(_button: int = 0)** Presses and releases the specified mouse button. Defaults to the left button (0). - **middle_click()** Presses and releases the middle mouse button. - **right_click()** Presses and releases the right mouse button. - **scroll_up(_repeat: int = 1)** Scrolls the mouse wheel upwards a specified number of times. - **scroll_down(_repeat: int = 1)** Scrolls the mouse wheel downwards a specified number of times. - **move(_x: int, _y: int)** Moves the mouse cursor to the specified X and Y coordinates. ``` -------------------------------- ### Screen Class Source: https://asyncvnc.readthedocs.io Represents a screen or a portion of the VNC server's display. ```APIDOC ## Screen Class ### Description Represents a screen or a portion of the VNC server's display, with properties for its dimensions and content. ### Attributes #### `Screen.x` The x-coordinate of the screen. #### `Screen.y` The y-coordinate of the screen. #### `Screen.width` The width of the screen. #### `Screen.height` The height of the screen. #### `Screen.slices` (Description not available in source.) #### `Screen.score` (Description not available in source.) ``` -------------------------------- ### Scroll Mouse Wheel Up Source: https://asyncvnc.readthedocs.io Simulates scrolling the mouse wheel upwards. ```python client.mouse.scroll_up() ``` -------------------------------- ### Tunnel VNC over SSH Source: https://asyncvnc.readthedocs.io Establishes an SSH connection first, then uses that connection to establish a VNC connection. This is useful for secure remote access. Requires AsyncSSH package. ```python import asyncio, asyncssh, asyncvnc async def run_client(): async with asyncssh.connect('myserver') as conn: async with asyncvnc.connect('localhost', opener=conn.open_connection) as client: print(client) asyncio.run(run_client()) ``` -------------------------------- ### asyncvnc.Video Source: https://asyncvnc.readthedocs.io Manages the video buffer received from the VNC server, allowing access to screen properties and data. ```APIDOC ## asyncvnc.Video ### Description Video buffer. ### Attributes - **name** (str) - The name of the desktop session. - **width** (int) - The width of the video buffer in pixels. - **height** (int) - The height of the video buffer in pixels. - **mode** (str) - The color channel order (e.g., 'RGBA'). - **data** (ndarray | None) - A 3D numpy array containing the video frame data. `None` if no data is available. ### Methods - **refresh(_x: int = 0, _y: int = 0, _width: int | None = None, _height: int | None = None)** Requests an update for a specific region of the video buffer from the server. - **as_rgba() -> ndarray** Returns the current video buffer data as a 3D RGBA numpy array. - **is_complete() -> bool** Checks if the entire video buffer is opaque (fully rendered). - **detect_screens() -> List[Screen]** Detects physical screens by analyzing the alpha channel of the video buffer. ``` -------------------------------- ### asyncvnc.Client Source: https://asyncvnc.readthedocs.io Represents an active VNC client connection, providing access to various VNC functionalities. ```APIDOC ## asyncvnc.Client ### Description VNC client. ### Attributes - **clipboard** (Clipboard) - Access to the shared clipboard functionality. - **keyboard** (Keyboard) - Access to the virtual keyboard functionality. - **mouse** (Mouse) - Access to the virtual mouse functionality. - **video** (Video) - Access to the video buffer and related operations. - **host_key** (RSAPublicKey | None) - The server's public key (Mac only). ### Methods - **read() -> UpdateType** Reads an update from the server and returns its type. - **_drain()** Waits for data to be written to the server. - **_screenshot(_x: int = 0, _y: int = 0, _width: int | None = None, _height: int | None = None) -> ndarray** Takes a screenshot and returns a 3D RGBA array. ``` -------------------------------- ### Detect Screens from Framebuffer Source: https://asyncvnc.readthedocs.io Extracts RGBA pixel data and uses it to detect individual screens within the VNC server's framebuffer, particularly useful for macOS servers that composite multiple monitors. ```python pixels = client.video.as_rgba() for screen in client.video.detect_screens(): screen_pixels = pixels[screen.slices] ``` -------------------------------- ### Move Mouse Cursor Source: https://asyncvnc.readthedocs.io Moves the mouse cursor to the specified X and Y coordinates on the VNC display. ```python client.mouse.move(100, 200) ``` -------------------------------- ### Right Click Mouse Source: https://asyncvnc.readthedocs.io Simulates a single right mouse click at the current cursor position. ```python client.mouse.right_click() ``` -------------------------------- ### asyncvnc.UpdateType Source: https://asyncvnc.readthedocs.io Enumeration representing different types of updates received from the VNC server. ```APIDOC ## asyncvnc.UpdateType ### Description Update from server to client. ### Members - **VIDEO** (int) - Represents a video update. - **CLIPBOARD** (int) - Represents a clipboard update. - **BELL** (int) - Represents a bell update. ``` -------------------------------- ### UpdateType Enum Source: https://asyncvnc.readthedocs.io Enumeration for different types of updates received from the VNC server. ```APIDOC ## UpdateType Enum ### Description Enumeration for different types of updates received from the VNC server. ### Members - `UpdateType.VIDEO`: Represents a video update. - `UpdateType.CLIPBOARD`: Represents a clipboard update. - `UpdateType.BELL`: Represents a bell event. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.