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 – 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 – The distance given by the shift operator.

Returns:

a Keyboard object

Return type:

Keyboard

all_keys()[source]#

Yields all keys in keyboard.

Yields:

all keys in keyboard.

coordinate(key: str) Tuple[int, int][source]#

Get coordinate for key.

Parameters:

key – keyboard key

Returns:

key coordinate on keyboard

create_distance_dict(distance: int = 1) dict[source]#
euclidian_distance(key_a: str, key_b: str) int[source]#

Returns euclidian distance between two keys.

Parameters:
  • key_a – keyboard key

  • key_b – keyboard key

Returns:

The euclidian distance between two keyboard keys.

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 – A keyboard key

  • distance – The euclidian distance of neightbours.

Returns:

The neighbours of a key with a specified distance.

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#