-
-
Notifications
You must be signed in to change notification settings - Fork 108
Windows: capture cursor #272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
de9c4c1
cace5d5
1c77da6
d1306a7
19cb97f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -20,6 +20,8 @@ | |||||
| RECT, | ||||||
| UINT, | ||||||
| WORD, | ||||||
| POINT, | ||||||
| HICON | ||||||
| ) | ||||||
| from threading import local | ||||||
| from typing import Any, Optional | ||||||
|
|
@@ -38,7 +40,9 @@ | |||||
|
|
||||||
|
|
||||||
| class BITMAPINFOHEADER(Structure): | ||||||
| """Information about the dimensions and color format of a DIB.""" | ||||||
| """ | ||||||
| Information about the dimensions and color format of a DIB. | ||||||
| """ | ||||||
|
|
||||||
| _fields_ = [ | ||||||
| ("biSize", DWORD), | ||||||
|
|
@@ -51,7 +55,7 @@ class BITMAPINFOHEADER(Structure): | |||||
| ("biXPelsPerMeter", LONG), | ||||||
| ("biYPelsPerMeter", LONG), | ||||||
| ("biClrUsed", DWORD), | ||||||
| ("biClrImportant", DWORD), | ||||||
| ("biClrImportant", DWORD) | ||||||
| ] | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -63,6 +67,33 @@ class BITMAPINFO(Structure): | |||||
| _fields_ = [("bmiHeader", BITMAPINFOHEADER), ("bmiColors", DWORD * 3)] | ||||||
|
|
||||||
|
|
||||||
| class CURSORINFO(Structure): | ||||||
| """ | ||||||
| Information about the cursor. | ||||||
| """ | ||||||
|
|
||||||
| _fields_ = [ | ||||||
| ("cbSize", DWORD), | ||||||
| ("flags", DWORD), | ||||||
| ("hCursor", HDC), | ||||||
| ("ptScreenPos", POINT) | ||||||
| ] | ||||||
|
|
||||||
|
|
||||||
| class ICONINFO(Structure): | ||||||
| """ | ||||||
| Information about an icon or cursor. | ||||||
| """ | ||||||
|
|
||||||
| _fields_ = [ | ||||||
| ("fIcon", BOOL), | ||||||
| ("xHotspot", DWORD), | ||||||
| ("yHotspot", DWORD), | ||||||
| ("hbmMask", HBITMAP), | ||||||
| ("hbmColor", HBITMAP) | ||||||
| ] | ||||||
|
|
||||||
|
|
||||||
| MONITORNUMPROC = WINFUNCTYPE(INT, DWORD, DWORD, POINTER(RECT), DOUBLE) | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -80,9 +111,12 @@ class BITMAPINFO(Structure): | |||||
| "CreateCompatibleDC": ("gdi32", [HDC], HDC), | ||||||
| "DeleteDC": ("gdi32", [HDC], HDC), | ||||||
| "DeleteObject": ("gdi32", [HGDIOBJ], INT), | ||||||
| "DrawIcon": ("user32", [HDC, INT, INT, HICON], BOOL), | ||||||
| "EnumDisplayMonitors": ("user32", [HDC, c_void_p, MONITORNUMPROC, LPARAM], BOOL), | ||||||
| "GetCursorInfo": ("user32", [POINTER(CURSORINFO)], BOOL), | ||||||
| "GetDeviceCaps": ("gdi32", [HWND, INT], INT), | ||||||
| "GetDIBits": ("gdi32", [HDC, HBITMAP, UINT, UINT, c_void_p, POINTER(BITMAPINFO), UINT], BOOL), | ||||||
| "GetIconInfo": ("user32", [HICON, POINTER(ICONINFO)], BOOL), | ||||||
| "GetSystemMetrics": ("user32", [INT], INT), | ||||||
| "GetWindowDC": ("user32", [HWND], HDC), | ||||||
| "ReleaseDC": ("user32", [HWND, HDC], c_int), | ||||||
|
|
@@ -121,6 +155,13 @@ def __init__(self, /, **kwargs: Any) -> None: | |||||
| bmi.bmiHeader.biClrImportant = 0 # See grab.__doc__ [3] | ||||||
| self._handles.bmi = bmi | ||||||
|
|
||||||
| ci = CURSORINFO() | ||||||
| ci.cbSize = ctypes.sizeof(CURSORINFO) | ||||||
| self._handles.ci = ci | ||||||
|
|
||||||
| iconinfo = ICONINFO() # 'ii' felt uncomfortable | ||||||
|
||||||
| iconinfo = ICONINFO() # 'ii' felt uncomfortable | |
| icon_info = ICONINFO() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea i will fix that too
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (llm): The initialization of 'iconinfo' without checking the return value of 'GetIconInfo' could lead to issues if 'GetIconInfo' fails. It would be safer to check the return value before assuming that 'iconinfo' has been properly initialized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to not change that part. If the process fails, then an exception will be raised.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was changed for the linux implementation so i did it but i can see why you would like to avoid that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are all good on Linux side: https://github.com/BoboTiG/python-mss/blob/v9.0.1/src/mss/linux.py#L424
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the documentation 💪🏻
For the implementation, do we need to copy all from the grab() method? Can it be simplified to only the cursor itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i did not care to look into it but now that you said it i will see if something can be done about simplifying it to just the cursor
i will update you once im done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UPDATE: im afraid it would not be possible since the cursor is a part of the screen's device context, it should not be a huge issue as im making a small 32x32 bitmap and capturing only the cursor's image
im sorry if im wrong, im not an expert at windows api and i would love to learn something new
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use more explicit name?
cusor_infoseems a good one.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, will do