try:
    from adafruit_hid.keycode import Keycode

    keycodes = {
        "\ue31e": [Keycode.SPACEBAR],
        "\u002e": [Keycode.PERIOD],
        "\u003c": [Keycode.SHIFT, Keycode.COMMA],
        "\u0031": [Keycode.ONE],
        "\u21b9": [Keycode.TAB],
        "\u002c": [Keycode.COMMA],
        "\u0032": [Keycode.TWO],
        "\u0065": [Keycode.E],
        "\u0045": [Keycode.SHIFT, Keycode.E],
        "\u0045": [Keycode.EQUALS],
        "\u0035": [Keycode.FIVE],
        "\u21dc": [Keycode.BACKSPACE],
        "\u003a": [Keycode.SHIFT, Keycode.SEMICOLON],
        "\u0033": [Keycode.THREE],
        "\u0061": [Keycode.A],
        "\u0041": [Keycode.SHIFT, Keycode.A],
        "\u002b": [Keycode.SHIFT, Keycode.EQUALS],
        "\u0036": [Keycode.SIX],
        "\u0072": [Keycode.R],
        "\u0052": [Keycode.SHIFT, Keycode.R],
        "\u002f": [Keycode.FORWARD_SLASH],
        "\uea6d": [Keycode.LEFT_CONTROL, Keycode.F],
        "\u0075": [Keycode.U],
        "\u0055": [Keycode.SHIFT, Keycode.U],
        "\u0027": [Keycode.QUOTE],
        "\u0038": [Keycode.EIGHT],
        "\u21af": [Keycode.ESCAPE],
        "\u003b": [Keycode.SEMICOLON],
        "\u0034": [Keycode.FOUR],
        "\u0069": [Keycode.I],
        "\u0049": [Keycode.SHIFT, Keycode.I],
        "\u002a": [Keycode.SHIFT, Keycode.EIGHT],
        "\u0037": [Keycode.SEVEN],
        "\u0063": [Keycode.C],
        "\u0043": [Keycode.SHIFT, Keycode.C],
        "\u005c": [Keycode.BACKSLASH],
        "\u2229": [Keycode.LEFT_CONTROL, Keycode.A],
        "\u0078": [Keycode.X],
        "\u0058": [Keycode.SHIFT, Keycode.X],
        "\u0022": [Keycode.SHIFT, Keycode.QUOTE],
        "\u0039": [Keycode.NINE],
        "\u006c": [Keycode.L],
        "\u004c": [Keycode.SHIFT, Keycode.L],
        "\u007e": [Keycode.SHIFT, Keycode.GRAVE_ACCENT],
        "\u21da": [Keycode.APPLICATION, Keycode.LEFT_ARROW],
        "\u007a": [Keycode.Z],
        "\u005a": [Keycode.SHIFT, Keycode.Z],
        "\u003e": [Keycode.SHIFT, Keycode.PERIOD],
        "\u21db": [Keycode.APPLICATION, Keycode.RIGHT_ARROW],
        "\u0064": [Keycode.D],
        "\u0044": [Keycode.SHIFT, Keycode.D],
        "\u0060": [Keycode.GRAVE_ACCENT],
        "\uebd2": [Keycode.LEFT_CONTROL, Keycode.V],
        "\u0068": [Keycode.H],
        "\u0048": [Keycode.SHIFT, Keycode.H],
        "\u0040": [Keycode.SHIFT, Keycode.TWO],
        "\u0030": [Keycode.ZERO],
        "\u21b5": [Keycode.RETURN],
        "\u21ab": [Keycode.SHIFT, Keycode.RETURN],
        "\u002d": [Keycode.MINUS],
        "\u21ff": [Keycode.PRINT_SCREEN],
        "\u006f": [Keycode.O],
        "\u004f": [Keycode.SHIFT, Keycode.O],
        "\u0029": [Keycode.SHIFT, Keycode.ZERO],
        "\u2193": [Keycode.DOWN_ARROW],
        "\u006d": [Keycode.M],
        "\u004d": [Keycode.SHIFT, Keycode.M],
        "\u0028": [Keycode.SHIFT, Keycode.NINE],
        "\u2192": [Keycode.RIGHT_ARROW],
        "\u0070": [Keycode.P],
        "\u0050": [Keycode.SHIFT, Keycode.P],
        "\u005f": [Keycode.SHIFT, Keycode.MINUS],
        "\u0066": [Keycode.F],
        "\u0046": [Keycode.SHIFT, Keycode.F],
        "\u0023": [Keycode.SHIFT, Keycode.THREE],
        "\u2191": [Keycode.UP_ARROW],
        "\u0077": [Keycode.W],
        "\u0057": [Keycode.SHIFT, Keycode.W],
        "\u007c": [Keycode.SHIFT, Keycode.BACKSLASH],
        "\u006a": [Keycode.J],
        "\u004a": [Keycode.SHIFT, Keycode.J],
        "\u0025": [Keycode.SHIFT, Keycode.FIVE],
        "\u0071": [Keycode.Q],
        "\u0051": [Keycode.SHIFT, Keycode.Q],
        "\u003f": [Keycode.SHIFT, Keycode.FORWARD_SLASH],
        "\u21c0": [Keycode.APPLICATION, Keycode.SPACEBAR],
        "\u0079": [Keycode.Y],
        "\u0059": [Keycode.SHIFT, Keycode.Y],
        "\u0024": [Keycode.SHIFT, Keycode.FOUR],
        "\u2190": [Keycode.LEFT_ARROW],
        "\u0062": [Keycode.B],
        "\u0042": [Keycode.SHIFT, Keycode.B],
        "\u007d": [Keycode.SHIFT, Keycode.RIGHT_BRACKET],
        "\u006b": [Keycode.K],
        "\u004b": [Keycode.SHIFT, Keycode.K],
        "\u007b": [Keycode.SHIFT, Keycode.LEFT_BRACKET],
        "\u0067": [Keycode.G],
        "\u0047": [Keycode.SHIFT, Keycode.G],
        "\u0021": [Keycode.SHIFT, Keycode.ONE],
        "\u0073": [Keycode.S],
        "\u0053": [Keycode.SHIFT, Keycode.S],
        "\u005e": [Keycode.SHIFT, Keycode.SIX],
        "\u21e4": [Keycode.HOME],
        "\u0076": [Keycode.V],
        "\u0056": [Keycode.SHIFT, Keycode.V],
        "\u005d": [Keycode.RIGHT_BRACKET],
        "\u21e5": [Keycode.END],
        "\u006e": [Keycode.N],
        "\u004e": [Keycode.SHIFT, Keycode.N],
        "\u005b": [Keycode.LEFT_BRACKET],
        "\uebcc": [Keycode.LEFT_CONTROL, Keycode.C],
        "\u0074": [Keycode.T],
        "\u0054": [Keycode.SHIFT, Keycode.T],
        "\u0026": [Keycode.SHIFT, Keycode.SEVEN],
        "\uf31a": [Keycode.APPLICATION],
    }
except:
    pass


characters = [
    [
        [
            [
                [
                    [None, None, None, None],  # 00000
                    [
                        "\ue31e",
                        "\u002e",
                        "\u003c",
                        "\u0031",
                    ],  # 00001 [SPACE, FULLSTOP, LESS THAN, 1]
                ],
                [
                    ["\u21b9", "\u002c", None, "\u0032"],  # 00010 [TAB, COMMA, None, 2]
                    ["\u0065", "\u0045", "\u003d", "\u0035"],  # 00011 [e, E, EQUALS, 5]
                ],
            ],
            [
                [
                    [
                        "\u21dc",
                        "\u003a",
                        None,
                        "\u0033",
                    ],  # 00100 [BACKSPACE, COLON, None, 3]
                    ["\u0061", "\u0041", "\u002b", "\u0036"],  # 00101 [a, A, PLUS, 6]
                ],
                [
                    [
                        "\u0072",
                        "\u0052",
                        "\u002f",
                        "\uea6d",
                    ],  # 00110 [r, R, SLASH, CTRL+F]
                    [
                        "\u0075",
                        "\u0055",
                        "\u0027",
                        "\u0038",
                    ],  # 00111 [u, U, APOSTROPHE, 8]
                ],
            ],
        ],
        [
            [
                [
                    [
                        "\u21af",
                        "\u003b",
                        None,
                        "\u0034",
                    ],  # 01000 [ESCAPE, SEMICOLON, None, 4]
                    [
                        "\u0069",
                        "\u0049",
                        "\u002a",
                        "\u0037",
                    ],  # 01001 [i, I, ASTERISK, 7]
                ],
                [
                    [
                        "\u0063",
                        "\u0043",
                        "\u005c",
                        "\u2229",
                    ],  # 01010 [c, C, BACKSLASH, CTRL+A]
                    [
                        "\u0078",
                        "\u0058",
                        "\u0022",
                        "\u0039",
                    ],  # 01011 [x, X, DOUBLE QUOTES, 9]
                ],
            ],
            [
                [
                    [
                        "\u006c",
                        "\u004c",
                        "\u007e",
                        "\u21da",
                    ],  # 01100 [l, L, TILDE, SUPER LEFT]
                    [
                        "\u007a",
                        "\u005a",
                        "\u003e",
                        "\u21db",
                    ],  # 01101 [z, Z, GREATER THAN, SUPER RIGHT]
                ],
                [
                    [
                        "\u0064",
                        "\u0044",
                        "\u0060",
                        "\uebd2",
                    ],  # 01110 [d, D, TICK, CTRL+V]
                    ["\u0068", "\u0048", "\u0040", "\u0030"],  # 01111 [h, H, AT, 0]
                ],
            ],
        ],
    ],
    [
        [
            [
                [
                    [
                        "\u21b5",
                        "\u21ab",
                        "\u002d",
                        "\u21ff",
                    ],  # 10000 [RETURN, SHIFT RETURN, MINUS, PRINT SCREEN]
                    [
                        "\u006f",
                        "\u004f",
                        "\u0029",
                        "\u2193",
                    ],  # 10001 [o, O, CLOSE BRACKET, DOWN]
                ],
                [
                    [
                        "\u006d",
                        "\u004d",
                        "\u0028",
                        "\u2192",
                    ],  # 10010 [m, M, OPEN BRACKET, RIGHT]
                    [
                        "\u0070",
                        "\u0050",
                        "\u005f",
                        None,
                    ],  # 10011 [p, P, UNDERSCORE, None]
                ],
            ],
            [
                [
                    ["\u0066", "\u0046", "\u0023", "\u2191"],  # 10100 [f, F, HASH, UP]
                    ["\u0077", "\u0057", "\u007c", None],  # 10101 [w, W, PIPE, None]
                ],
                [
                    ["\u006a", "\u004a", "\u0025", None],  # 10110 [j, J, PERCENT, None]
                    [
                        "\u0071",
                        "\u0051",
                        "\u003f",
                        "\u21c0",
                    ],  # 10111 [q, Q, QUESTION MARK, SUPER+SPACE]
                ],
            ],
        ],
        [
            [
                [
                    [
                        "\u0079",
                        "\u0059",
                        "\u0024",
                        "\u2190",
                    ],  # 11000 [y, Y, DOLLAR, LEFT]
                    [
                        "\u0062",
                        "\u0042",
                        "\u007d",
                        None,
                    ],  # 11001 [b, B, CLOSE CURLY BRACKET, None]
                ],
                [
                    [
                        "\u006b",
                        "\u004b",
                        "\u007b",
                        None,
                    ],  # 11010 [k, K, OPEN CURLY BRACKET, None]
                    [
                        "\u0067",
                        "\u0047",
                        "\u0021",
                        None,
                    ],  # 11011 [g, G, EXCLAMATION MARK, None]
                ],
            ],
            [
                [
                    [
                        "\u0073",
                        "\u0053",
                        "\u005e",
                        "\u21e4",
                    ],  # 11100 [s, S, CIRCUMFLEX, HOME]
                    [
                        "\u0076",
                        "\u0056",
                        "\u005d",
                        "\u21e5",
                    ],  # 11101 [v, V, CLOSE SQUARE BRACKET, END]
                ],
                [
                    [
                        "\u006e",
                        "\u004e",
                        "\u005b",
                        "\uebcc",
                    ],  # 11110 [n, N, OPEN SQUARE BRACKET, CTRL+C]
                    [
                        "\u0074",
                        "\u0054",
                        "\u0026",
                        "\uf31a",
                    ],  # 11111 [t, T, AMPERSAND, SUPER]
                ],
            ],
        ],
    ],
]

extra_characters = ["\u00e9", "\u00e7"]

shortcuts = [
    [
        [
            [
                [
                    [None, None, None, None],  # 00000
                    [None, None, None, None],  # 00001 [None, None, None, None]
                ],
                [
                    [None, None, None, None],  # 00010 [None, None, None, None]
                    [None, None, None, None],  # 00011 [None, None, None, None]
                ],
            ],
            [
                [
                    [None, None, None, None],  # 00100 [None, None, None, None]
                    [None, None, None, None],  # 00101 [None, None, None, None]
                ],
                [
                    [None, None, None, None],  # 00110 [None, None, None, None]
                    [None, None, None, None],  # 00111 [None, None, None, None]
                ],
            ],
        ],
        [
            [
                [
                    [None, None, None, None],  # 01000 [None, None, None, None]
                    [None, None, None, None],  # 01001 [None, None, None, None]
                ],
                [
                    [None, None, None, None],  # 01010 [None, None, None, None]
                    [None, None, None, None],  # 01011 [None, None, None, None]
                ],
            ],
            [
                [
                    [None, None, None, None],  # 01100 [None, None, None, None]
                    [None, None, None, None],  # 01101 [None, None, None, None]
                ],
                [
                    [None, None, None, None],  # 01110 [None, None, None, None]
                    [None, None, None, None],  # 01111 [None, None, None, None]
                ],
            ],
        ],
    ],
    [
        [
            [
                [
                    [None, None, None, None],  # 10000 [None, None, None, None]
                    [None, None, None, None],  # 10001 [None, None, None, None]
                ],
                [
                    [None, None, None, None],  # 10010 [None, None, None, None]
                    [None, None, None, None],  # 10011 [None, None, None, None]
                ],
            ],
            [
                [
                    [None, None, None, None],  # 10100 [None, None, None, None]
                    [None, None, None, None],  # 10101 [None, None, None, None]
                ],
                [
                    [None, None, None, None],  # 10110 [None, None, None, None]
                    [None, None, None, None],  # 10111 [None, None, None, None]
                ],
            ],
        ],
        [
            [
                [
                    [None, None, None, None],  # 11000 [None, None, None, None]
                    [None, None, None, None],  # 11001 [None, None, None, None]
                ],
                [
                    [None, None, None, None],  # 11010 [None, None, None, None]
                    [None, None, None, None],  # 11011 [None, None, None, None]
                ],
            ],
            [
                [
                    [None, None, None, None],  # 11100 [None, None, None, None]
                    [None, None, None, None],  # 11101 [None, None, None, None]
                ],
                [
                    [None, None, None, None],  # 11110 [None, None, None, None]
                    [None, None, None, None],  # 11111 [None, None, None, None]
                ],
            ],
        ],
    ],
]

words = [
    [
        [
            [
                [
                    [
                        [None, None, None, None],  # 00000
                        ["Tom", None, None, None],  # 00001 [Tom, None, None, None]
                    ],
                    [
                        ["is", None, None, None],  # 00010 [is, None, None, None]
                        [None, None, None, None],  # 00011 [None, None, None, None]
                    ],
                ],
                [
                    [
                        ["name", None, None, None],  # 00100 [name, None, None, None]
                        [None, None, None, None],  # 00101 [None, None, None, None]
                    ],
                    [
                        [None, None, None, None],  # 00110 [None, None, None, None]
                        [None, None, None, None],  # 00111 [None, None, None, None]
                    ],
                ],
            ],
            [
                [
                    [
                        ["my", None, None, None],  # 01000 [my, None, None, None]
                        [None, None, None, None],  # 01001 [None, None, None, None]
                    ],
                    [
                        [None, None, None, None],  # 01010 [None, None, None, None]
                        [None, None, None, None],  # 01011 [None, None, None, None]
                    ],
                ],
                [
                    [
                        [None, None, None, None],  # 01100 [None, None, None, None]
                        [None, None, None, None],  # 01101 [None, None, None, None]
                    ],
                    [
                        [None, None, None, None],  # 01110 [None, None, None, None]
                        [None, None, None, None],  # 01111 [None, None, None, None]
                    ],
                ],
            ],
        ],
        [
            [
                [
                    [
                        ["hello", None, None, None],  # 10000 [Hello, None, None, None]
                        [None, None, None, None],  # 10001 [None, None, None, None]
                    ],
                    [
                        [None, None, None, None],  # 10010 [None, None, None, None]
                        [None, None, None, None],  # 10011 [None, None, None, None]
                    ],
                ],
                [
                    [
                        [None, None, None, None],  # 10100 [None, None, None, None]
                        [None, None, None, None],  # 10101 [None, None, None, None]
                    ],
                    [
                        [None, None, None, None],  # 10110 [None, None, None, None]
                        [None, None, None, None],  # 10111 [None, None, None, None]
                    ],
                ],
            ],
            [
                [
                    [
                        [None, None, None, None],  # 11000 [None, None, None, None]
                        [None, None, None, None],  # 11001 [None, None, None, None]
                    ],
                    [
                        [None, None, None, None],  # 11010 [None, None, None, None]
                        [None, None, None, None],  # 11011 [None, None, None, None]
                    ],
                ],
                [
                    [
                        [None, None, None, None],  # 11100 [None, None, None, None]
                        [None, None, None, None],  # 11101 [None, None, None, None]
                    ],
                    [
                        [None, None, None, None],  # 11110 [None, None, None, None]
                        [None, None, None, None],  # 11111 [None, None, None, None]
                    ],
                ],
            ],
        ],
    ],
    [
        [
            [
                [
                    [
                        [None, None, None, None],  # 00000
                        [None, None, None, None],  # 00001 [None, None, None, None]
                    ],
                    [
                        [None, None, None, None],  # 00010 [None, None, None, None]
                        [None, None, None, None],  # 00011 [None, None, None, None]
                    ],
                ],
                [
                    [
                        [None, None, None, None],  # 00100 [None, None, None, None]
                        [None, None, None, None],  # 00101 [None, None, None, None]
                    ],
                    [
                        [None, None, None, None],  # 00110 [None, None, None, None]
                        [None, None, None, None],  # 00111 [None, None, None, None]
                    ],
                ],
            ],
            [
                [
                    [
                        [None, None, None, None],  # 01000 [None, None, None, None]
                        [None, None, None, None],  # 01001 [None, None, None, None]
                    ],
                    [
                        [None, None, None, None],  # 01010 [None, None, None, None]
                        [None, None, None, None],  # 01011 [None, None, None, None]
                    ],
                ],
                [
                    [
                        [None, None, None, None],  # 01100 [None, None, None, None]
                        [None, None, None, None],  # 01101 [None, None, None, None]
                    ],
                    [
                        [None, None, None, None],  # 01110 [None, None, None, None]
                        [None, None, None, None],  # 01111 [None, None, None, None]
                    ],
                ],
            ],
        ],
        [
            [
                [
                    [
                        [None, None, None, None],  # 10000 [None, None, None, None]
                        [None, None, None, None],  # 10001 [None, None, None, None]
                    ],
                    [
                        [None, None, None, None],  # 10010 [None, None, None, None]
                        [None, None, None, None],  # 10011 [None, None, None, None]
                    ],
                ],
                [
                    [
                        [None, None, None, None],  # 10100 [None, None, None, None]
                        [None, None, None, None],  # 10101 [None, None, None, None]
                    ],
                    [
                        [None, None, None, None],  # 10110 [None, None, None, None]
                        [None, None, None, None],  # 10111 [None, None, None, None]
                    ],
                ],
            ],
            [
                [
                    [
                        [None, None, None, None],  # 11000 [None, None, None, None]
                        [None, None, None, None],  # 11001 [None, None, None, None]
                    ],
                    [
                        [None, None, None, None],  # 11010 [None, None, None, None]
                        [None, None, None, None],  # 11011 [None, None, None, None]
                    ],
                ],
                [
                    [
                        [None, None, None, None],  # 11100 [None, None, None, None]
                        [None, None, None, None],  # 11101 [None, None, None, None]
                    ],
                    [
                        [None, None, None, None],  # 11110 [None, None, None, None]
                        [None, None, None, None],  # 11111 [None, None, None, None]
                    ],
                ],
            ],
        ],
    ],
]


def get_character_set():
    return sorted(
        list(
            set(
                sum(
                    [
                        list(a)
                        for a in sum(sum(sum(sum(sum(characters, []), []), []), []), [])
                        if a is not None
                    ],
                    [],
                )
                + extra_characters
            )
        )
    )
