Search code examples
pythonpyautogui

Take a screenshot that includes the cursor


I am trying to make a program with pyautogui that does different things depending on how the cursor looks (for example the cursor looks different when you are resizing a window or something like that), however when taking a screenshot with pyautogui.screenshot() the cursor itself isn't included in the image. Is there any way to take a screenshot with python that will include the cursor? photo of what I mean enter image description here


Solution

  • There is no way (that I know of, anyway) you can include the cursor in the screenshot using pyautogui.

    But there are 2 hacky work-arounds :-

    1. You could press the hotkeys for taking the screenshot, i.e., just make the system take the screenshot, and get the image that way. For windows, it is win + prtscn, as far as I remember.

    2. You could get the position of the mouse at the time of taking the screenshot, get an image of a cursor from the net, and overlay the cursor over the screenshot taken by pyautogui using PIL or any other library as you wish.