diff --git a/pyproject.toml b/pyproject.toml index 1508b1e..82d05a7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "simonsays_drgreengiant" -version = "2.0.1" +version = "2.0.2" authors = [{ name = "Simon Howroyd", email = "howroydlsu@gmail.com" }] description = "A Twitch Plays style programme to allow users in Twitch chats to control the broadcasters mouse and keyboard" keywords = ["twitch", "chat", "twitchplays", "troll"] diff --git a/src/simonsays_drgreengiant/gameactions.py b/src/simonsays_drgreengiant/gameactions.py index c980185..b58da02 100644 --- a/src/simonsays_drgreengiant/gameactions.py +++ b/src/simonsays_drgreengiant/gameactions.py @@ -125,6 +125,8 @@ def run(self, *, force: bool = False) -> errorcodes.ErrorSet: return hidactions.MoveMouseRelative(actionconfig.hidconfig).run(force=force) elif isinstance(actionconfig.hidconfig, hidactions.MouseMoveDirectionActionConfig): return hidactions.MoveMouseRelativeDirection(actionconfig.hidconfig).run(force=force) + elif isinstance(actionconfig.hidconfig, hidactions.MouseMoveDirectionSmoothActionConfig): + return hidactions.MoveMouseRelativeDirectionSmooth(actionconfig.hidconfig).run(force=force) else: return errorcodes.errorset(errorcodes.ErrorCode.NOT_IMPLEMENTED) diff --git a/src/simonsays_drgreengiant/hidactions.py b/src/simonsays_drgreengiant/hidactions.py index eb7b54a..e293783 100644 --- a/src/simonsays_drgreengiant/hidactions.py +++ b/src/simonsays_drgreengiant/hidactions.py @@ -130,6 +130,16 @@ class MouseMoveCartesianActionConfig: device: HidType = HidType.MOUSE_MOVE +@dataclasses.dataclass(slots=True) +class MouseMoveCartesianSmoothActionConfig: + """An action to move the mouse in cartesian coordinates in a smooth way""" + x: int + y: int + repeats: int = 10 + pause: float = 0.01 + device: HidType = HidType.MOUSE_MOVE + + class MouseMoveDirectionUnknown(Exception): """Unknown mouse move direction""" pass @@ -172,7 +182,17 @@ class MouseMoveDirectionActionConfig: device: HidType = HidType.MOUSE_MOVE -Config = KeyboardActionConfig | MouseButtonActionConfig | MouseMoveCartesianActionConfig | MouseMoveDirectionActionConfig +@dataclasses.dataclass(slots=True) +class MouseMoveDirectionSmoothActionConfig: + """An action to move the mouse smoothly in a direction""" + distance: int + direction: MouseMoveDirection + repeats: int = 10 + pause: float = 0.01 + device: HidType = HidType.MOUSE_MOVE + + +Config = KeyboardActionConfig | MouseButtonActionConfig | MouseMoveCartesianActionConfig | MouseMoveCartesianSmoothActionConfig | MouseMoveDirectionActionConfig | MouseMoveDirectionSmoothActionConfig ##################################################################### @@ -244,6 +264,22 @@ def run(self, *, force: bool = False) -> errorcodes.ErrorSet: return dummy_run(f"Moving mouse (relative) by: {self.config.x}, {self.config.y}") +@dataclasses.dataclass(slots=True) +class MoveMouseRelativeSmooth: + """Move the mouse relative to its current position""" + config: MouseMoveCartesianSmoothActionConfig + + def run(self, *, force: bool = False) -> errorcodes.ErrorSet: + """Run the action""" + if not DEBUG: + x = self.config.x // self.config.repeats + y = self.config.y // self.config.repeats + look_action = MoveMouseRelative(MouseMoveCartesianActionConfig(x, y)) + + return actions.ActionRepeatWithWait(look_action, self.config.repeats, actions.Wait(self.config.pause)).run(force=force) + return dummy_run(f"Moving mouse smoothly (relative) by: {self.config.x}, {self.config.y} in {self.config.repeats} repeats with {self.config.pause} pause") + + @dataclasses.dataclass(slots=True) class MoveMouseRelativeDirection: """Move the mouse relative to its current position in a direction""" @@ -256,6 +292,23 @@ def run(self, *, force: bool = False) -> errorcodes.ErrorSet: return dummy_run(f"Moving mouse (relative direction) by: {self.config.distance} in direction {self.config.direction.value}") +@dataclasses.dataclass(slots=True) +class MoveMouseRelativeDirectionSmooth: + """Move the mouse relative to its current position, smoothly in a direction""" + config: MouseMoveDirectionSmoothActionConfig + + def run(self, *, force: bool = False) -> errorcodes.ErrorSet: + """Run the action""" + if not DEBUG: + x, y = MouseMoveDirection.to_cartesian(self.config.direction, self.config.distance) + x = x // self.config.repeats + y = y // self.config.repeats + look_action = MoveMouseRelative(MouseMoveCartesianActionConfig(x, y)) + + return actions.ActionRepeatWithWait(look_action, self.config.repeats, actions.Wait(self.config.pause)).run(force=force) + return dummy_run(f"Moving mouse smoothly (relative direction) by: {self.config.distance} in directino {self.config.direction.value} repeats with {self.config.pause} pause") + + @dataclasses.dataclass(slots=True) class PressKey: """Press a key""" diff --git a/src/simonsays_drgreengiant/phasmoactions.py b/src/simonsays_drgreengiant/phasmoactions.py index 4da20e4..a491178 100644 --- a/src/simonsays_drgreengiant/phasmoactions.py +++ b/src/simonsays_drgreengiant/phasmoactions.py @@ -350,7 +350,7 @@ class LookUp(GenericAction): @dataclasses.dataclass(slots=True) class LookUpConfig(LookConfig): """Look up config""" - hidconfig: hidactions.Config = dataclasses.field(default_factory=lambda: hidactions.MouseMoveDirectionActionConfig(DEFAULTS.LOOK_DISTANCE, hidactions.MouseMoveDirection.UP)) + hidconfig: hidactions.Config = dataclasses.field(default_factory=lambda: hidactions.MouseMoveDirectionSmoothActionConfig(DEFAULTS.LOOK_DISTANCE, hidactions.MouseMoveDirection.UP)) @dataclasses.dataclass(slots=True) @@ -363,7 +363,7 @@ class LookDown(GenericAction): @dataclasses.dataclass(slots=True) class LookDownConfig(LookConfig): """Look down config""" - hidconfig: hidactions.Config = dataclasses.field(default_factory=lambda: hidactions.MouseMoveDirectionActionConfig(DEFAULTS.LOOK_DISTANCE, hidactions.MouseMoveDirection.DOWN)) + hidconfig: hidactions.Config = dataclasses.field(default_factory=lambda: hidactions.MouseMoveDirectionSmoothActionConfig(DEFAULTS.LOOK_DISTANCE, hidactions.MouseMoveDirection.DOWN)) @dataclasses.dataclass(slots=True) @@ -376,7 +376,7 @@ class LookLeft(GenericAction): @dataclasses.dataclass(slots=True) class LookLeftConfig(LookConfig): """Look left config""" - hidconfig: hidactions.Config = dataclasses.field(default_factory=lambda: hidactions.MouseMoveDirectionActionConfig(DEFAULTS.LOOK_DISTANCE, hidactions.MouseMoveDirection.LEFT)) + hidconfig: hidactions.Config = dataclasses.field(default_factory=lambda: hidactions.MouseMoveDirectionSmoothActionConfig(DEFAULTS.LOOK_DISTANCE, hidactions.MouseMoveDirection.LEFT)) @dataclasses.dataclass(slots=True) @@ -389,7 +389,7 @@ class LookRight(GenericAction): @dataclasses.dataclass(slots=True) class LookRightConfig(LookConfig): """Look right config""" - hidconfig: hidactions.Config = dataclasses.field(default_factory=lambda: hidactions.MouseMoveDirectionActionConfig(DEFAULTS.LOOK_DISTANCE, hidactions.MouseMoveDirection.RIGHT)) + hidconfig: hidactions.Config = dataclasses.field(default_factory=lambda: hidactions.MouseMoveDirectionSmoothActionConfig(DEFAULTS.LOOK_DISTANCE, hidactions.MouseMoveDirection.RIGHT)) PeekConfig = LookConfig @@ -405,7 +405,7 @@ class PeekUp(GenericAction): @dataclasses.dataclass(slots=True) class PeekUpConfig(PeekConfig): """Peek up config""" - hidconfig: hidactions.Config = dataclasses.field(default_factory=lambda: hidactions.MouseMoveDirectionActionConfig(DEFAULTS.PEEK_DISTANCE, hidactions.MouseMoveDirection.UP)) + hidconfig: hidactions.Config = dataclasses.field(default_factory=lambda: hidactions.MouseMoveDirectionSmoothActionConfig(DEFAULTS.PEEK_DISTANCE, hidactions.MouseMoveDirection.UP)) @dataclasses.dataclass(slots=True) @@ -418,7 +418,7 @@ class PeekDown(GenericAction): @dataclasses.dataclass(slots=True) class PeekDownConfig(PeekConfig): """Peek down config""" - hidconfig: hidactions.Config = dataclasses.field(default_factory=lambda: hidactions.MouseMoveDirectionActionConfig(DEFAULTS.PEEK_DISTANCE, hidactions.MouseMoveDirection.DOWN)) + hidconfig: hidactions.Config = dataclasses.field(default_factory=lambda: hidactions.MouseMoveDirectionSmoothActionConfig(DEFAULTS.PEEK_DISTANCE, hidactions.MouseMoveDirection.DOWN)) @dataclasses.dataclass(slots=True) @@ -431,7 +431,7 @@ class PeekLeft(GenericAction): @dataclasses.dataclass(slots=True) class PeekLeftConfig(PeekConfig): """Peek left config""" - hidconfig: hidactions.Config = dataclasses.field(default_factory=lambda: hidactions.MouseMoveDirectionActionConfig(DEFAULTS.PEEK_DISTANCE, hidactions.MouseMoveDirection.LEFT)) + hidconfig: hidactions.Config = dataclasses.field(default_factory=lambda: hidactions.MouseMoveDirectionSmoothActionConfig(DEFAULTS.PEEK_DISTANCE, hidactions.MouseMoveDirection.LEFT)) @dataclasses.dataclass(slots=True) @@ -444,7 +444,7 @@ class PeekRight(GenericAction): @dataclasses.dataclass(slots=True) class PeekRightConfig(PeekConfig): """Peek right config""" - hidconfig: hidactions.Config = dataclasses.field(default_factory=lambda: hidactions.MouseMoveDirectionActionConfig(DEFAULTS.PEEK_DISTANCE, hidactions.MouseMoveDirection.RIGHT)) + hidconfig: hidactions.Config = dataclasses.field(default_factory=lambda: hidactions.MouseMoveDirectionSmoothActionConfig(DEFAULTS.PEEK_DISTANCE, hidactions.MouseMoveDirection.RIGHT)) ##################################################################### @@ -734,8 +734,8 @@ def run(self, *, force: bool = False) -> errorcodes.ErrorSet: distance = actionconfig.distance or DEFAULTS.PEEK_DISTANCE - lookup = hidactions.MoveMouseRelativeDirection(hidactions.MouseMoveDirectionActionConfig(distance, hidactions.MouseMoveDirection.UP)) - lookdown = hidactions.MoveMouseRelativeDirection(hidactions.MouseMoveDirectionActionConfig(distance, hidactions.MouseMoveDirection.DOWN)) + lookup = hidactions.MoveMouseRelativeDirectionSmooth(hidactions.MouseMoveDirectionSmoothActionConfig(distance, hidactions.MouseMoveDirection.UP)) + lookdown = hidactions.MoveMouseRelativeDirectionSmooth(hidactions.MouseMoveDirectionSmoothActionConfig(distance, hidactions.MouseMoveDirection.DOWN)) once = actions.ActionSequence([lookup, actions.Wait(pause), lookdown]) return actions.ActionRepeatWithWait(once, repeats, actions.Wait(pause)).run(force=force)