Did you consider having methods for these interactions, rather than relying on a string match? For example:

    keyboard.tap_shift
    keyboard.enable_caps_lock
    keyboard.tap_backspace
    keyboard.tap_return