This Python project streams the computer's screen along with the mouse cursor to a connected client device over a network using sockets. It captures the screen using the mss library and overlays the mouse cursor in real-time. The images are compressed and sent via a socket to a client for display.
- Real-time screen capture: Uses
mssfor fast and efficient screen capturing. - Mouse cursor overlay: The mouse cursor is captured and overlaid on the screenshot using
ctypes. - Optimized JPEG compression: The captured screen is compressed into JPEG format with adjustable quality to balance speed and image quality.
- Custom framerate: Adjusts the sleep time dynamically to maintain a specified framerate.
- Automatic reconnection: Attempts to reconnect for 2 minutes if the connection is lost.
To run this project, you need to install the following Python libraries:
pip install mss pillow- Screen Capture: The
msslibrary captures the screen in real-time. You can adjust which monitor to capture by changing the monitor index. - Mouse Cursor Overlay: The mouse cursor position is retrieved using
ctypesand then a custom cursor image (e.g.,cursor.png) is overlaid on the screen capture. - Socket Connection: The screen and cursor data are sent over a socket to a client device. The program tries to connect to the client for up to 2 minutes before giving up.
- Framerate Control: The program is designed to maintain a target framerate (default is 40 FPS) by dynamically adjusting the sleep time between frames.
- Set up the client: Make sure the client device is ready to receive the screen stream over a socket on port
8888. - Modify the IP address: Replace
'Device IP'in the code with the IP address of the client device. - Run the script:
python screen_stream.pyThe program will start capturing the screen, overlay the cursor, and send it to the client device.
Cursor Image
Ensure that you have a cursor.png file in the same directory as the script. This image will be used as the custom mouse cursor overlay.
- Adjust the framerate: You can modify the
target_fpsvariable to increase or decrease the frames per second (FPS). - Change image quality: Adjust the
qualityparameter in theimg.save()function to change the JPEG compression level. - Resize the image: You can uncomment the
img.resize()line to downscale the captured image for faster transmission if needed.
When the connection is established, you'll see:
Connection established
If the connection fails, it will retry for 2 minutes, displaying messages such as:
Connection failed: [error message]. Retrying...
- Android app where you can view your casting.
- rewriting the code in
CorC++for better performance.