def check_key(key):
    """
    Check if key pressed/released is a char, others or ESC key.

    Parameters:
        key (pynput.keyboard.KeyCode): Key code captured.

    Returns:
        str: The key code as string if not ESC, otherwise False.
    """
    checked = None
    try:
        checked = key.char
    except AttributeError:
        # not a char, then remove Key. from e.g. Key.up
        checked = key
        checked = str(checked).split(".")[1]
    if checked != "esc":
        return checked
    else:  # ESC key pressed, aka keyboard.Key.esc
        # stop listener, also stop pushing samples
        return False