Debian Codegraph @

selenium/webdriver/common/actions/key_input.py

raw symbols SCIP
1 # Licensed to the Software Freedom Conservancy (SFC) under one
2 # or more contributor license agreements. See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership. The SFC licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License. You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17 from . import interaction
18 from .input_device import InputDevice
19 from .interaction import Interaction
20 from .interaction import Pause
21
22
23 class KeyInput(InputDevice):
24 def __init__(self, name: str) -> None:
25 super().__init__()
26 self.name = name
27 self.type = interaction.KEY
28
29 def encode(self) -> dict:
30 return {"type": self.type, "id": self.name, "actions": [acts.encode() for acts in self.actions]}
31
32 def create_key_down(self, key) -> None:
33 self.add_action(TypingInteraction(self, "keyDown", key))
34
35 def create_key_up(self, key) -> None:
36 self.add_action(TypingInteraction(self, "keyUp", key))
37
38 def create_pause(self, pause_duration: float = 0) -> None:
39 self.add_action(Pause(self, pause_duration))
40
41
42 class TypingInteraction(Interaction):
43 def __init__(self, source, type_, key) -> None:
44 super().__init__(source)
45 self.type = type_
46 self.key = key
47
48 def encode(self) -> dict:
49 return {"type": self.type, "value": self.key}