Anki 2 is a really amazing piece of software and I'd regard it as almost perfect. One of the major missing features is imho the ability to change the default keyboard shortcuts. If you want to change them or add new ones, you have to edit the source. Fortunately this process isn't too complicated because the whole application is written in Python. The disadvantage is, that you need to make the changes after each update of Anki again though, but if you memorize or write down the changes, it's not that annoying.

The change I always apply to all my Anki installations is the ability to control the reviewer via the arrow keys. So that'll serve as an example in this post.
The interface files are located in the sub-folder "aqt" of Anki's install-directory. What I'll do now is to open the file "reviewer.py". This file contains the code, that is run, when you review/study your words. To change the keys, you have to edit the keyhandler "_keyHandler". This method is run everytime you push a key on your keyboard. If you have this information, you should actually already be able to adjust the keys to your liking. The only thing, you could easily overlook is the usage of "evt.key()" vs. "key". While "evt.key()" directly compares the key events (click here for a list of all possible key events), the variable "key" contains the pressed character.

I hope, this info is useful to you and to complete this post, here's my keyhandler in the reviewer file, where it is possible to use the arrow keys to answer a card and the "arrow down"-key is used to show the next card when the answer is shown.

    def _keyHandler(self, evt):
        key = unicode(evt.text())
        if key == "e":
            self.mw.onEditCurrent()
        elif (key == " " or evt.key() in (Qt.Key_Return, Qt.Key_Enter, Qt.Key_Down)):
            if self.state == "question":
                self._showAnswerHack()
            elif self.state == "answer":
                self._answerCard(self._defaultEase())
        elif key == "r" or evt.key() == Qt.Key_F5:
            self.replayAudio()
        elif key == "*":
            self.onMark()
        elif key == "-":
            self.onBuryNote()
        elif key == "!":
            self.onSuspend()
        elif key == "V":
            self.onRecordVoice()
        elif key == "o":
            self.onOptions()
        elif key in ("1", "2", "3", "4"):
            self._answerCard(int(key))
        elif evt.key() == Qt.Key_Left:
            self._answerCard(1)
        elif evt.key() == Qt.Key_Down:
            self._answerCard(2)
        elif evt.key() == Qt.Key_Right:
            self._answerCard(3)
        elif evt.key() == Qt.Key_Up:
            self._answerCard(4)
        elif key == "v":
            self.onReplayRecorded()
        elif evt.key() == Qt.Key_Delete:
            self.onDelete()

6 Responses to “How to set custom keyboard shortcuts in Anki 2”

  1. markdaniel
    April 7th, 2013 at 01:51
    1

    The link with the key events doesn’t seem to work anymore. does anyone know the event for “cloze deletion”?

  2. Regan
    May 26th, 2013 at 22:08
    2

    How do I get to this code on a Mac? I searched for reviewer.py but nothing came up.

  3. Moritz
    August 20th, 2014 at 12:44
    3

    As far as I know the application is compressed into an archive on Mac OS and needs to be extracted first.

  4. Brad
    November 14th, 2014 at 17:10
    4

    Did not find any subfolder labeled “aqt” in the anki install directory.

    anki 2.0 – windows 7

  5. Adamaero
    November 19th, 2014 at 00:59
    5

    Why not just use the number pad? The only shortcut I use is ctrl+shift C for cloze deletion anyways.

  6. Robin
    June 10th, 2015 at 01:38
    6

    I don’t know how old this is (you should give some date information) but why don’t you create an add-on for this. Then you don’t have to worry about updates.
    In fact, some guy/girl made one to use j,k,l,; as the answer shortcuts.
    So you could just download that one and insert your code.
    https://ankiweb.net/shared/info/2090822731

Leave a Comment

I respect your privacy
I don't run any trackers on this site.

Please use the share-buttons or leave comments so I know what might be worth writing about.

Thank you.
Contact