Skip to content
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

Added window size functionality #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/pynput/mouse/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ def click(self, button, count=1):
controller.press(button)
controller.release(button)

def size(self):
"""Finds the size of the screen.

This is a tuple ``(x, y)`` for the maximum width and height.
"""
return self._size()

def __enter__(self):
"""Begins a series of clicks.

Expand Down Expand Up @@ -168,6 +175,13 @@ def _release(self, button):
"""
raise NotImplementedError()

def _size(self):
"""The implementation of the :meth:`size` method.

This is a platform dependent implementation.
"""
raise NotImplementedError()


# pylint: disable=W0223; This is also an abstract class
class Listener(AbstractListener):
Expand Down
4 changes: 4 additions & 0 deletions lib/pynput/mouse/_darwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ def _release(self, button):
if button == self._drag_button:
self._drag_button = None

def _size(self):
return Quartz.CGDisplayPixelsWide(Quartz.CGMainDisplayID()), \
Quartz.CGDisplayPixelsHigh(Quartz.CGMainDisplayID())

def __enter__(self):
self._click = 0
return self
Expand Down
4 changes: 4 additions & 0 deletions lib/pynput/mouse/_win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ def _release(self, button):
dwFlags=button.value[0])))),
ctypes.sizeof(INPUT))

def _size(self):
return ctypes.windll.user32.GetSystemMetrics(0), \
ctypes.windll.user32.GetSystemMetrics(1)


@Controller._receiver
class Listener(ListenerMixin, _base.Listener):
Expand Down
4 changes: 4 additions & 0 deletions lib/pynput/mouse/_xorg.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ def _release(self, button):
with display_manager(self._display) as dm:
Xlib.ext.xtest.fake_input(dm, Xlib.X.ButtonRelease, button.value)

def _size(self):
return self._display.screen().width_in_pixels, \
self._display.screen().height_in_pixels

def _check_bounds(self, *args):
"""Checks the arguments and makes sure they are within the bounds of a
short integer.
Expand Down