14
14
# KIND, either express or implied. See the License for the
15
15
# specific language governing permissions and limitations
16
16
# under the License.
17
+
17
18
from __future__ import annotations
18
19
19
20
from ..utils import keys_to_typing
20
- from .interaction import KEY , Interaction
21
+ from .interaction import KEY , POINTER , WHEEL , Interaction
21
22
from .key_input import KeyInput
22
23
from .pointer_input import PointerInput
23
24
from .wheel_input import WheelInput
@@ -27,8 +28,19 @@ class KeyActions(Interaction):
27
28
def __init__ (self , source : KeyInput | PointerInput | WheelInput | None = None ) -> None :
28
29
if source is None :
29
30
source = KeyInput (KEY )
30
- self .source = source
31
- super ().__init__ (source )
31
+ self .input_source = source
32
+
33
+ # Determine the correct source type string based on the input object
34
+ if isinstance (source , KeyInput ):
35
+ source_type = KEY
36
+ elif isinstance (source , PointerInput ):
37
+ source_type = POINTER
38
+ elif isinstance (source , WheelInput ):
39
+ source_type = WHEEL
40
+ else :
41
+ source_type = KEY
42
+
43
+ super ().__init__ (source_type )
32
44
33
45
def key_down (self , letter : str ) -> KeyActions :
34
46
return self ._key_action ("create_key_down" , letter )
@@ -48,6 +60,6 @@ def send_keys(self, text: str | list) -> KeyActions:
48
60
return self
49
61
50
62
def _key_action (self , action : str , letter ) -> KeyActions :
51
- meth = getattr (self .source , action )
63
+ meth = getattr (self .input_source , action )
52
64
meth (letter )
53
65
return self
0 commit comments