# How to assign a shortcut for a button of extra fields?

**URL:** <https://forums.ankiweb.net/t/how-to-assign-a-shortcut-for-a-button-of-extra-fields/6516>\
**Category:** Card Design\
**Created:** [January 14, 2021, 12:06pm UTC](https://forums.ankiweb.net/t/how-to-assign-a-shortcut-for-a-button-of-extra-fields/6516 "2021-01-14T12:06:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lingthusiast](https://avatars.discourse-cdn.com/v4/letter/l/258eb7/32.png) [@lingthusiast](https://forums.ankiweb.net/u/lingthusiast)\
**Post date:** [January 14, 2021, 12:06pm UTC](https://forums.ankiweb.net/t/how-to-assign-a-shortcut-for-a-button-of-extra-fields/6516/1 "2021-01-14T12:06:42Z")

</div>

I am preparing a language deck which contains two buttons for extra information. One of them contains an example sentence and the other the translation of the example sentence.

So, I was wondering if there was any way to assign some shortcut keys for these buttons.

You can find the code of the buttons here:

```
<div id="buttonsBox">

<button onmouseover="showExs()">Exam</button>
<button onmouseover="showTra()">Trans</button>

</div>

<!------------------------------------------------> 

<script>

function showExs() {
  document.getElementById("showExs").style.display = "";
  document.getElementById("showTra").style.display = "none";
}

function showTra() {
  document.getElementById("showExs").style.display = "none";
  document.getElementById("showTra").style.display = "";
  
}

</script>

<div id="showExs" style="display:none">
{{Exs}}
{{Sentence audio}}
</div>
<!------------------------------------------------>
<div id="showTra" style="display:none">
{{Tra}}

```

Thank you in advance

---

<div class="post-metadata">

**Author:** ![hkr](https://avatars.discourse-cdn.com/v4/letter/h/c6cbf5/32.png) [@hkr](https://forums.ankiweb.net/u/hkr)\
**Post date:** [January 14, 2021, 1:09pm UTC](https://forums.ankiweb.net/t/how-to-assign-a-shortcut-for-a-button-of-extra-fields/6516/2 "2021-01-14T13:09:06Z")

</div>

Try adding the following code at the end of the `<script>` tag.

```auto
// Remove the event listener registered on the previous card
if (typeof myKeyboardEventHandler !== 'undefined') {
    document.removeEventListener('keydown', myKeyboardEventHandler);
}

function myKeyboardEventHandler(event) {
    if (event.key === 'F7') {
        showExs();
    } else if (event.key === 'F8') {
        showTra();
    }
}

document.addEventListener('keydown', myKeyboardEventHandler);

```

If you are using an older version of Anki 2.1, [Refocus Card when Reviewing (2.1)](https://ankiweb.net/shared/info/1642550423) add-on is required for shortcut keys to work. In addition, keys already assigned by Anki itself or add-ons cannot be used.

---

<div class="post-metadata">

**Author:** ![lingthusiast](https://avatars.discourse-cdn.com/v4/letter/l/258eb7/32.png) [@lingthusiast](https://forums.ankiweb.net/u/lingthusiast)\
**Post date:** [January 14, 2021, 1:53pm UTC](https://forums.ankiweb.net/t/how-to-assign-a-shortcut-for-a-button-of-extra-fields/6516/3 "2021-01-14T13:53:39Z")

</div>

It works, thank you very much.

The problem is that you need to click on somewhere on the flashcard first. It is like when you have two different tabs in front of you and you cannot switch between them unless you click.

But I guess there is no way to fix it?

---

<div class="post-metadata">

**Author:** ![hkr](https://avatars.discourse-cdn.com/v4/letter/h/c6cbf5/32.png) [@hkr](https://forums.ankiweb.net/u/hkr)\
**Post date:** [January 14, 2021, 2:14pm UTC](https://forums.ankiweb.net/t/how-to-assign-a-shortcut-for-a-button-of-extra-fields/6516/4 "2021-01-14T14:14:30Z")

</div>

Updating to the latest version of Anki, or installing `Refocus Card when Reviewing (2.1)` addon (as i mentioned above) should probably fix the issue.

---

<div class="post-metadata">

**Author:** ![lingthusiast](https://avatars.discourse-cdn.com/v4/letter/l/258eb7/32.png) [@lingthusiast](https://forums.ankiweb.net/u/lingthusiast)\
**Post date:** [January 14, 2021, 4:30pm UTC](https://forums.ankiweb.net/t/how-to-assign-a-shortcut-for-a-button-of-extra-fields/6516/5 "2021-01-14T16:30:45Z")

</div>

Updating from 2.1.35 to 2.1.38 solved the problem. Thank you.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [May 1, 2023, 7:42am UTC](https://forums.ankiweb.net/t/how-to-assign-a-shortcut-for-a-button-of-extra-fields/6516/6 "2023-05-01T07:42:01Z")

</div>

Closed on May 1, 2023, 7:42am UTC


