Dynamically disable shortcuts for specific decks during review?

Hi everyone,

I’m developing an addon that allows users to type in their cloze deletions, and I want to add a feature where hitting “Return” focuses on the text input field. However, this conflicts with Anki’s default “flip card” shortcut. I know about addons like “Customize Keyboard Shortcuts” that can disable this globally, but I only want to disable the Return shortcut when users are reviewing cards from one specific deck - not system-wide.

My understanding is that Anki shortcuts are typically initialized at launch, and addons like Customize Keyboard Shortcuts work by rebuilding Anki’s shortcuts object with custom values. Is there a way to modify shortcuts dynamically when a user enters a review session for a specific deck, and then restore the original shortcuts when they’re done?

Thanks!

For your specific case, you can patch Reviewer.onEnterKey. Example:

from typing import Callable

from anki.hooks import wrap
from aqt.reviewer import Reviewer


def on_enter_key(reviewer: Reviewer, _old: Callable) -> None:
    if is_specific_deck(reviewer.card.did):
        # TODO: your logic here
        pass
    else:
        _old(reviewer)


Reviewer.onEnterKey = wrap(
    Reviewer.onEnterKey,
    on_enter_key,
    "around",
)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.