Can the shortcut keys of Anki be called within the Anki template? For example, in the back of Anki, when pressing ‘difficult’, can it call the shortcut key to automatically add the red flag, like how adding a red flag in Anki is ctrl 1?
I looked up something similar a short while ago because a user wanted to trigger the undo command from within the card templates.
The result of me trying and of my research suggest that shortcuts from the browser cannot be called from within a webpage (or anki template in this case). This apparently is a security feature.
Though maybe there is an API available that would still allow you to do that. Otherwise, it’s impossible to call a browser shortcut like Ctrl+1 from within the card template as far as I know.
I just want to add flag markers to the cards for convenience, without having to mark them manually. I’m not sure if there are any safety considerations. Thank you for your reply.
I was trying to say that it’s not possible.
Even if you’d set the flag programatically with js, so that you get the following correct html, anki would’t show the card as “flag 1”:
<div id="_flag" style="color: var(--flag-1);">⚑</div>
The reason is security restrictions that are build in web browsers. Anki on desktop uses a browser, too, which is based on the chromium browser.
In other words: There’s no way to achieve what you’re looking for using card templates (except if anki devs provided APIs for that, which I cannot answer as I do not know).