Skip to content

Commit

Permalink
Windows Double Clicks Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinyzu committed Aug 18, 2024
1 parent d4f6d08 commit 5a7b744
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 2 additions & 3 deletions cdp_patches/input/async_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ async def click(
x, y = int(x), int(y)

await self.down(button=button, x=x, y=y, emulate_behaviour=emulate_behaviour, timeout=timeout, pressed=pressed, double_down=double_down)
if self.emulate_behaviour and emulate_behaviour:
if (self.emulate_behaviour and emulate_behaviour) or double_down:
await self._sleep_timeout(timeout=timeout)
await self.up(button=button, x=x, y=y, pressed=pressed)
self.last_x, self.last_y = x, y
Expand All @@ -140,8 +140,7 @@ async def double_click(
await self.click(button=button, x=x, y=y, timeout=timeout, emulate_behaviour=emulate_behaviour, pressed=pressed)
if self.emulate_behaviour and emulate_behaviour:
# await self._sleep_timeout(random.uniform(0.14, 0.21))
# await self._sleep_timeout(timeout=timeout)
pass
await self._sleep_timeout(timeout=timeout)
await self.click(button=button, x=x, y=y, emulate_behaviour=False, timeout=timeout, pressed=pressed, double_down=True)

self.last_x, self.last_y = x, y
Expand Down
3 changes: 3 additions & 0 deletions cdp_patches/input/os_base/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ def double_down(self, button: Literal["left", "right", "middle"], x: int, y: int
flags, click_point = _calc_flags_and_coords(pressed, [x, y])
win32functions.PostMessage(self.browser_window, msg, win32structures.WPARAM(flags), win32structures.LPARAM(click_point))

# wait until the thread can accept another message
win32functions.WaitGuiThreadIdle(self.browser_window.handle)

def up(self, button: Literal["left", "right", "middle"], x: int, y: int, pressed: str = "") -> None:
self.ensure_window()
self.browser_window.release_mouse(button=button, pressed=pressed, coords=(int(x * self.scale_factor), int(y * self.scale_factor)))
Expand Down
5 changes: 2 additions & 3 deletions cdp_patches/input/sync_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def click(
x, y = int(x), int(y)

self.down(button=button, x=x, y=y, emulate_behaviour=emulate_behaviour, timeout=timeout, pressed=pressed, double_down=double_down)
if self.emulate_behaviour and emulate_behaviour:
if (self.emulate_behaviour and emulate_behaviour) or double_down:
self._sleep_timeout(timeout=timeout)
self.up(button=button, x=x, y=y, pressed=pressed)
self.last_x, self.last_y = x, y
Expand All @@ -138,8 +138,7 @@ def double_click(
self.click(button=button, x=x, y=y, timeout=timeout, emulate_behaviour=emulate_behaviour, pressed=pressed)
if emulate_behaviour and self.emulate_behaviour:
# self._sleep_timeout(random.uniform(0.14, 0.21))
# self._sleep_timeout(timeout=timeout)
pass
self._sleep_timeout(timeout=timeout)
self.click(button=button, x=x, y=y, emulate_behaviour=False, timeout=timeout, pressed=pressed, double_down=True)

self.last_x, self.last_y = x, y
Expand Down

0 comments on commit 5a7b744

Please sign in to comment.