diff --git a/zx/_device.py b/zx/_device.py index 1eb50bb..9c728bd 100644 --- a/zx/_device.py +++ b/zx/_device.py @@ -32,6 +32,12 @@ class IsTapePlayerPaused(DeviceEvent): pass +class KeyStroke(object): + def __init__(self, id, pressed): + self.id = id + self.pressed = pressed + + class PauseStateUpdated(DeviceEvent): pass diff --git a/zx/_gui.py b/zx/_gui.py index 8aab974..a0976b9 100644 --- a/zx/_gui.py +++ b/zx/_gui.py @@ -16,6 +16,7 @@ from ._device import GetEmulationTime from ._device import GetTapePlayerTime from ._device import IsTapePlayerPaused +from ._device import KeyStroke from ._device import PauseStateUpdated from ._device import QuantumRun from ._device import ScreenUpdated @@ -25,7 +26,6 @@ from ._error import USER_ERRORS from ._error import verbalize_error from ._except import EmulationExit -from ._keyboard import KEYS from ._time import get_elapsed_time from ._time import get_timestamp from ._utils import div_ceil @@ -380,11 +380,7 @@ def __on_key(self, event, devices): self._KEY_HANDLERS[event.id](devices) zx_key_id = self._GTK_KEYS_TO_ZX_KEYS.get(event.id, event.id) - key = KEYS.get(zx_key_id, None) - if key: - self.xmachine.paused = False - self.xmachine._quit_playback_mode() - self.xmachine._handle_key_stroke(key, event.pressed) + devices.notify(KeyStroke(zx_key_id, event.pressed)) def __on_gdk_click(self, widget, event): TYPES = { diff --git a/zx/_machine.py b/zx/_machine.py index 8a76813..3239fcf 100644 --- a/zx/_machine.py +++ b/zx/_machine.py @@ -16,11 +16,13 @@ from ._device import GetEmulationTime from ._device import GetTapePlayerTime from ._device import IsTapePlayerPaused +from ._device import KeyStroke from ._device import PauseStateUpdated from ._device import ToggleEmulationPause from ._device import ToggleTapePause from ._emulatorbase import _Spectrum48Base from ._except import EmulationExit +from ._keyboard import KEYS from ._rom import get_rom_image from ._utils import make16 @@ -429,6 +431,12 @@ def on_event(self, event, devices, result): return self._tape_player.get_time() elif isinstance(event, IsTapePlayerPaused): return self._is_tape_paused() + elif isinstance(event, KeyStroke): + key = KEYS.get(event.id, None) + if key: + self.paused = False + self._quit_playback_mode() + self._handle_key_stroke(key, event.pressed) elif isinstance(event, ToggleEmulationPause): self.paused ^= True elif isinstance(event, ToggleTapePause):