Keyboard#
Keyboard is a custom class for implementing keyboard layout and is required for augmenters such as keystroke_error.v1, and char_replace_random.v1.
augmenty.keyboard#
Function for defining and handling keyboard layouts.
- class augmenty.keyboard.Keyboard(*, keyboard_array: Dict[str, List[List[str]]], shift_distance: int = 3)[source]#
Bases:
BaseModel
A Pydantic dataclass object for constructing Keyboard setup.
- Parameters:
keyboard_array (Dict[str, str]) – An array corresponding to a keyboard. This should include two keys a “default” and a “shift”. Each containing an array of non-shifted and shifted keys respectively.
shift_distance (int) – The distance given by the shift operator. Defaults to 3.
- Returns:
a Keyboard object
- Return type:
- coordinate(key: str) Tuple[int, int] [source]#
Get coordinate for key.
- Parameters:
key (str) – keyboard key
- Returns:
key coordinate on keyboard
- Return type:
Tuple[int, int]
- euclidian_distance(key_a: str, key_b: str) int [source]#
Returns euclidian distance between two keys.
- Parameters:
key_a (str) – keyboard key
key_b (str) – keyboard key
- Returns:
The euclidian distance between two keyboard keys.
- Return type:
int
- static from_registry(entry: str, shift_distance: int = 3) Keyboard [source]#
Creates a keyboard from a registry.
- get_neighbours(key: str, distance: int = 1) List[int] [source]#
gets the neighbours of a key with a specified distance.
- Parameters:
key (str) – A keyboard key
distance (int, optional) – The euclidian distance of neightbours. Defaults to 1.
- Returns:
The neighbours of a key with a specified distance.
- Return type:
List[int]
- is_shifted(key: str) bool [source]#
is the key shifted?
- Parameters:
key (str) – keyboard key
- Returns:
a boolean indicating whether key is shifted.
- Return type:
bool
- keyboard_array: Dict[str, List[List[str]]]#
- shift_distance: int#