Skip to content

Commit

Permalink
Improving Double Click
Browse files Browse the repository at this point in the history
Works now on my end, lets see if gh worker agrees...
  • Loading branch information
Vinyzu committed Aug 18, 2024
1 parent 5a7b744 commit 1c9798c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
17 changes: 6 additions & 11 deletions cdp_patches/input/async_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,12 @@ async def click(
y: Union[int, float],
pressed: str = "",
emulate_behaviour: Optional[bool] = True,
timeout: Optional[float] = None,
double_down: Optional[bool] = False,
timeout: Optional[float] = None
) -> None:
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) or double_down:
await self.down(button=button, x=x, y=y, emulate_behaviour=emulate_behaviour, timeout=timeout, pressed=pressed)
if self.emulate_behaviour and emulate_behaviour:
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 @@ -141,7 +140,7 @@ async def double_click(
if self.emulate_behaviour and emulate_behaviour:
# await self._sleep_timeout(random.uniform(0.14, 0.21))
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)
await self.click(button=button, x=x, y=y, emulate_behaviour=False, timeout=timeout, pressed=pressed)

self.last_x, self.last_y = x, y

Expand All @@ -152,18 +151,14 @@ async def down(
y: Union[int, float],
pressed: str = "",
emulate_behaviour: Optional[bool] = True,
timeout: Optional[float] = None,
double_down: Optional[bool] = False,
timeout: Optional[float] = None
) -> None:
x, y = int(x), int(y)

if self.emulate_behaviour and emulate_behaviour:
await self.move(x=x, y=y, timeout=timeout, emulate_behaviour=emulate_behaviour, pressed=pressed)
kwargs = _mk_kwargs(pressed)
if double_down:
self._base.double_down(button=button, x=x, y=y, **kwargs)
else:
self._base.down(button=button, x=x, y=y, **kwargs)
self._base.down(button=button, x=x, y=y, **kwargs)
self.last_x, self.last_y = x, y

async def up(self, button: Literal["left", "right", "middle"], x: Union[int, float], y: Union[int, float], pressed: str = "") -> None:
Expand Down
17 changes: 6 additions & 11 deletions cdp_patches/input/sync_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,12 @@ def click(
y: Union[int, float],
pressed: str = "",
emulate_behaviour: Optional[bool] = True,
timeout: Optional[float] = 0.07,
double_down: Optional[bool] = False,
timeout: Optional[float] = 0.07
) -> None:
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) or double_down:
self.down(button=button, x=x, y=y, emulate_behaviour=emulate_behaviour, timeout=timeout, pressed=pressed)
if self.emulate_behaviour and emulate_behaviour:
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 @@ -139,7 +138,7 @@ def double_click(
if emulate_behaviour and self.emulate_behaviour:
# self._sleep_timeout(random.uniform(0.14, 0.21))
self._sleep_timeout(timeout=timeout)
self.click(button=button, x=x, y=y, emulate_behaviour=False, timeout=timeout, pressed=pressed, double_down=True)
self.click(button=button, x=x, y=y, emulate_behaviour=False, timeout=timeout, pressed=pressed)

self.last_x, self.last_y = x, y

Expand All @@ -150,17 +149,13 @@ def down(
y: Union[int, float],
pressed: str = "",
emulate_behaviour: Optional[bool] = True,
timeout: Optional[float] = None,
double_down: Optional[bool] = False,
timeout: Optional[float] = None
) -> None:
x, y = int(x), int(y)

if self.emulate_behaviour and emulate_behaviour:
self.move(x=x, y=y, emulate_behaviour=emulate_behaviour, timeout=timeout, pressed=pressed)
if double_down:
self._base.double_down(button=button, x=x, y=y, **_mk_kwargs(pressed))
else:
self._base.down(button=button, x=x, y=y, **_mk_kwargs(pressed))
self._base.down(button=button, x=x, y=y, **_mk_kwargs(pressed))
self.last_x, self.last_y = x, y

def up(self, button: Literal["left", "right", "middle"], x: Union[int, float], y: Union[int, float], pressed: str = "") -> None:
Expand Down

0 comments on commit 1c9798c

Please sign in to comment.