Skip to content

Commit

Permalink
fix mouse position on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Commandcracker committed Feb 28, 2023
1 parent 5d14f95 commit 0015c1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion display_server_interactions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from platform import system as __system

__version__ = "0.0.dev6"
__version__ = "0.0.dev7"
__author__ = "Commandcracker"

__os_name = __system().lower()
Expand Down
19 changes: 12 additions & 7 deletions display_server_interactions/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def geometry(self) -> Box:
rect = RECT()
user32.GetWindowRect(self.window, byref(rect))
return Box(
x=0,
y=0,
x=rect.left,
y=rect.top,
width=rect.right - rect.left,
height=rect.bottom - rect.top
)
Expand Down Expand Up @@ -99,14 +99,19 @@ def send_str(self, str: str) -> None:
self.send_chr(chr)

def warp_pointer(self, x: int, y: int, geometry: Box = None) -> None:
if geometry:
rel_x, rel_y = x - geometry.x, y - geometry.y
else:
rel_x, rel_y = x, y
point = POINT(rel_x, rel_y)
if geometry is None:
geometry = self.geometry

x = x + geometry.x
y = y + geometry.y

point = POINT(x, y)
user32.SetCursorPos(point.x, point.y)

def send_mouse_click(self, x: int, y: int, button: MouseButtons = MouseButtons.LEFT) -> None:
x = x + self.geometry.x
y = y + self.geometry.y

# Press and release the button
down_code = 0
up_code = 0
Expand Down

0 comments on commit 0015c1a

Please sign in to comment.