You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Perhaps adding CLI arguments like --with-cursor and --cursor-file=FILE.
Add adding keywords/attributes with_cursor=False and cursor_file='' to the MSS class.
I think it can be interesting to merge the cursor into the pixels directly and not only in the final PNG.
The script gets the current mouse cursor icon to bitmap and adds it to the screenshot. It's very fast, so no performance problems.
However, I'm not quite sure how to implement it. The dependencies to win32gui can be exchanged for call to cTypes for sure. Maybe someone else can add the code in a beautiful fashion?
For just getting the mouse coordinates at the time of making a screenshot, using python-xlib:
from Xlib import display
pointer = display.Display().screen().root.query_pointer()
position = (pointer.root_x, pointer.root_y)
But then you have to draw a cursor yourself into the screen grab, and you do not know the actual cursor image used by the display at the particular moment. Cursor rendering is its own little kingdom in X11 ...
Here is how ffmpeg goes about it. It may seem however, that python-xlib does not expose the xfixes API as of now, nor does ffmpeg-python expose that ffmpeg function retrieving the pointer image.
It should be possible to use ctypes to access the XFixesGetCursorImage function from libXfixes.so to get back a XFixesCursorImage C structure like here, but in python.
See also the structure of the image struct here or in the original X source ...
I've written a working module for linux, that get the cursor image using Ctypes : https://github.com/zorvios/PyXCursor
is there anything we could do to add this feature ?
v8.0.0 added Linux support. Thanks to @zorvios it introduces all bricks needed for upcoming Mac, and Windows, supports (like MSSBase._merge(screenshot, cursor)).
Activity
BoboTiG commentedon Apr 9, 2018
As of now, no.
But it may be an interesting feature to add.
jamespreed commentedon May 26, 2018
As an interim solution, could you capture the mouse position on screen and add it to the .png file metadata on write out?
A good example of getting the mouse position is given in the 2nd answer here:
https://stackoverflow.com/questions/3698635/getting-cursor-position-in-python
BoboTiG commentedon May 26, 2018
It could be a good start.
Perhaps adding CLI arguments like
--with-cursorand--cursor-file=FILE.Add adding keywords/attributes
with_cursor=Falseandcursor_file=''to theMSSclass.I think it can be interesting to merge the cursor into the pixels directly and not only in the final PNG.
What do ou think @itsdax and @jamespreed ?
itsdax commentedon May 26, 2018
Yes! That sounds like the right approach.
In Java, there's a method for getting the cursor's state (text hover, resize, move, etc)
java.awt.Cursor.getType()If there's a similar one in python, it can be used to trigger different icons.
jamespreed commentedon May 28, 2018
Integrating a cursor directly into the pixels would be great. You could have several choices: cursor, crosshair, or concentric circles.
BoboTiG commentedon Aug 7, 2018
FI we can find some clues from the pyinput module.
BoboTiG commentedon Jan 29, 2019
This is how we could do it for GNU/Linux:
https://github.com/MaartenBaert/ssr/blob/master/src/AV/Input/X11Input.cpp
skjerns commentedon Jan 30, 2020
I've written a solution for Windows.
The script gets the current mouse cursor icon to bitmap and adds it to the screenshot. It's very fast, so no performance problems.
However, I'm not quite sure how to implement it. The dependencies to win32gui can be exchanged for call to cTypes for sure. Maybe someone else can add the code in a beautiful fashion?
matanox commentedon May 21, 2020
Maybe the best reference for linux would be ffmpeg, where mouse capture is implemented as part of screen grabbing (taking a screenshot).
For just getting the mouse coordinates at the time of making a screenshot, using python-xlib:
But then you have to draw a cursor yourself into the screen grab, and you do not know the actual cursor image used by the display at the particular moment. Cursor rendering is its own little kingdom in X11 ...
matanox commentedon May 21, 2020
Here is how ffmpeg goes about it. It may seem however, that python-xlib does not expose the xfixes API as of now, nor does ffmpeg-python expose that ffmpeg function retrieving the pointer image.
matanox commentedon May 21, 2020
It should be possible to use ctypes to access the
XFixesGetCursorImagefunction from libXfixes.so to get back aXFixesCursorImageC structure like here, but in python.See also the structure of the image struct here or in the original X source ...
zorvios commentedon May 26, 2020
I found a solution but it depends on GTK2 for now and it is written in python2
using x.py and xlib.py from http://code.google.com/p/pyxlib-ctypes/
here is a working exemple https://github.com/zorvios/X11CursorImagePy2
zorvios commentedon Jun 4, 2020
I've written a working module for linux, that get the cursor image using Ctypes :
https://github.com/zorvios/PyXCursor
is there anything we could do to add this feature ?
1 remaining item
amadeok commentedon Jun 1, 2021
if using PIL for processing a workaround could be the one here:
https://github.com/swharden/pyScreenCapture/blob/master/go.py
Linux: added mouse support (partially fixes #55)
Linux: added mouse support (partially fixes #55)
Linux: added mouse support (partially fixes #55)
BoboTiG commentedon Apr 5, 2023
v8.0.0 added Linux support. Thanks to @zorvios it introduces all bricks needed for upcoming Mac, and Windows, supports (like
MSSBase._merge(screenshot, cursor)).basket-ball commentedon Aug 25, 2023
with_cursor=Trueis only supported in linux. not in windows. Can it be supported in windows? thxBoboTiG commentedon Jan 25, 2024
Windows support is ongoing with #272.
tamnguyenvan commentedon Oct 15, 2024
@BoboTiG , I'd like to suggest a solution.
I have implemented it in my project, and it has worked perfectly.
Refs: https://github.com/tamnguyenvan/screenvivid/blob/main/screenvivid/models/utils/cursor/loader.py
Add cursor to windows capture
Add cursor to windows capture
Add cursor to windows capture