dictation-toolbox / Caster

Dragonfly-Based Voice Programming and Accessibility Toolkit
Other
337 stars 122 forks source link

add missing keyboard keys #869

Closed kendonB closed 3 years ago

kendonB commented 3 years ago

add missing keyboard keys

Description

The keyboard grammar had used the punctuation keys from punctuation_support but not all of those characters (passed to Text in punctuation.py) exist in the dragonfly keyboard specification. This PR replaces those characters (" ", "-", "/", ",", and ":") with their respective dragonfly Key IDs ("space", "minus", "slash", "comma", and "colon").

The approach should be robust to people editing the specs in punctuation_support.

Related Issue

None. Mentioned on gitter

Motivation and Context

Fixing a bug

How Has This Been Tested

Just using the text engine

Types of changes

Checklist

Maintainer/Reviewer Checklist

LexiconCode commented 3 years ago

What do you think of this @kendonB? My intent was to make this easier if we have to extend anymore keys and make it a bit more readable. In the button_dictionary_1.update I used getspec(' '): "space" The getspec function reverses the keys and values so that we can use dictionary.get(value)

button_dictionary_1 = {
    "(F{}".format(i) + " | function {})".format(i) : "f{}".format(i)
    for i in range(1, 13)
    }

def getspec(value, dct=button_dictionary_1):
    # Reverses Keys and Values which allows for dct.get(value)
    # The returned String is the spoken spec for the command
    reversed_dictionary = dict(map(reversed, dct.items()))
    print(reversed_dictionary.get(value)) # debug
    return reversed_dictionary.get(value)

class Keyboard(MappingRule):
    mapping = {
        "<modifier> <button_dictionary_1>":
              R(Key("%(modifier)s%(button_dictionary_1)s"),
              rdescript="press button: %(modifier)s%(button_dictionary_1)s"),
        "<hold_release> <button_dictionary_1>":
              R(Key("%(button_dictionary_1)s:%(hold_release)s"),
              rdescript="%(hold_release)s button: %(button_dictionary_1)s"),
    }

    # These buttons can be used without using the "press" prefix.
    right_spec = "(right | ross)"
    left_spec = "(left | lease)"

    button_dictionary_1.update(caster_alphabet())
    button_dictionary_1.update(_tpd)
    shift_spec = "(shift | shin)"
    control_spec = "(control | fly)"
    alt_spec = "alt"
    windows_spec = "windows"
    # in the punctuation dictionary it uses " " which is not the correct dragonfly key name.
    del button_dictionary_1["[is] less [than] [or] equal [to]"]
    del button_dictionary_1["[is] equal to"]
    del button_dictionary_1["[is] greater [than] [or] equal [to]"]

    button_dictionary_1.update({
        "(tab | tabby)": "tab",
        "(backspace | clear)": "backspace",
        "(delete | deli)": "del",
        "(enter | shock)": "enter",
        left_spec: "left",
        right_spec: "right",
        "(up | sauce)": "up",
        "(down | dunce)": "down",
        "page (down | dunce)": "pgdown",
        "page (up | sauce)": "pgup",
        getspec(' '): "space",
        getspec(','): "comma",
        getspec('-'): "minus",
        getspec('/'): "slash",
        getspec(':'): "colon",
kendonB commented 3 years ago

Yes this is better. Great stuff! Happy with this as long as it works

LexiconCode commented 3 years ago

Yes this is better. Great stuff! Happy with this as long as it works

All right, if you have time for a quick test.

LexiconCode commented 3 years ago

The import for button_dictionary_1 is not properly initialized and updated.