Path: blob/trunk/py/selenium/webdriver/common/actions/key_input.py
1864 views
# Licensed to the Software Freedom Conservancy (SFC) under one1# or more contributor license agreements. See the NOTICE file2# distributed with this work for additional information3# regarding copyright ownership. The SFC licenses this file4# to you under the Apache License, Version 2.0 (the5# "License"); you may not use this file except in compliance6# with the License. You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing,11# software distributed under the License is distributed on an12# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13# KIND, either express or implied. See the License for the14# specific language governing permissions and limitations15# under the License.16from . import interaction17from .input_device import InputDevice18from .interaction import Interaction, Pause192021class KeyInput(InputDevice):22def __init__(self, name: str) -> None:23super().__init__()24self.name = name25self.type = interaction.KEY2627def encode(self) -> dict:28return {"type": self.type, "id": self.name, "actions": [acts.encode() for acts in self.actions]}2930def create_key_down(self, key) -> None:31self.add_action(TypingInteraction(self, "keyDown", key))3233def create_key_up(self, key) -> None:34self.add_action(TypingInteraction(self, "keyUp", key))3536def create_pause(self, pause_duration: float = 0) -> None:37self.add_action(Pause(self, pause_duration))383940class TypingInteraction(Interaction):41def __init__(self, source, type_, key) -> None:42super().__init__(source)43self.type = type_44self.key = key4546def encode(self) -> dict:47return {"type": self.type, "value": self.key}484950