-
-
Save kelciour/3fe292bf15f3ec09dee44d9459e33ca7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# Name: Handy Answer Keys Shortcuts | |
# Copyright: Vitalie Spinu | |
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html | |
# | |
# Bind 'j', 'k', 'l', ';' to card answering actions. This allows answering with | |
# right hand, keeping your thumb on SPC (default action) and other fingers on | |
# 'j', 'k', 'l', ';'. If the number of buttons is less than 4, 'l' and ';' will | |
# do the right thing - choose the maximal ease level. | |
# | |
# If you are in the "question" state (no answer is yet visible) these keys | |
# bypass the display of the answer and automatically set the ease level. So if | |
# you press ';', the note is automatically marked with the highest ease level | |
# (last button in answer state), if you press 'k' or 'l', the note is marked by | |
# the default ease level ("good"), if you press 'j', the note is marked as hard | |
# (first button). | |
# | |
# As a bonus 'z' is bound to undo. | |
from aqt import mw | |
from aqt.reviewer import Reviewer | |
from anki.hooks import wrap | |
def keyHandler(self, evt, _old): | |
key = unicode(evt.text()) | |
if key == "z": | |
try:# throws an error on undo -> do -> undo pattern, otherwise works fine | |
mw.onUndo() | |
except: | |
pass | |
elif key == "t": | |
self.onMark() | |
elif key in ["j", "k", "l", ";", "3"]: | |
cnt = mw.col.sched.answerButtons(mw.reviewer.card) # Get button count | |
isq = self.state == "question" | |
if isq: | |
self._showAnswerHack() | |
if key == "j": | |
self._answerCard(1) | |
elif key == "k": | |
if isq: | |
self._answerCard(self._defaultEase()) | |
else: | |
self._answerCard(2) | |
elif key == "l": | |
if isq: | |
self._answerCard(self._defaultEase()) | |
else: | |
self._answerCard(3 if cnt >= 3 else cnt) | |
elif key == ";" or key == "3": | |
self._answerCard(cnt) | |
else: | |
return _old(self, evt) | |
else: | |
return _old(self, evt) | |
Reviewer._keyHandler = wrap(Reviewer._keyHandler, keyHandler, "around") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment