def METHOD_NAME(window, key, scancode, action, mod):
    key, text = input_state.process_key(key)
    if action == glfw.PRESS:
        down = True
    elif action == glfw.RELEASE:
        down = False
    else:
        return
    input_state.process_mod(key, down=down)
    # NOTE: GLFW only provides localized characters via _on_key_char, so if
    # this event contains a character we store all other data and dispatch
    # it once the final unicode character is sent shortly after.
    if text != "" and action == glfw.PRESS:
        input_state.next_key_events.append((action, key, input_state.modifiers))
    else:
        if key in input_state.next_key_text:
            text = input_state.next_key_text[key]
            del input_state.next_key_text[key]
        # Not a char event, call the event normally
        event = PseudoKeyEvent(key, input_state.modifiers, text)
        kev = KeyEvent(event, action == glfw.PRESS)
        p5.sketch._enqueue_event(
            "key_pressed" if action == glfw.PRESS else "key_released", kev
        )