I’m using Anki mainly for language learning. My cards layout looks like this:
- Front: TL word
- Back: TL word definition, example and hidden translation.
I have 3 fields which are hint fields. I don’t use {{hint}} field, I wrote my own fields which by default are not visible, and I can show them or hide them when I:
- Press X key on PC keyboard
- Click or tap on the field on PC or iOS
- Press X button on Bluetooth controller on iOS.
Since last update everything worked fine, but now I have problem with third method using Bluetooth controller - pressing X button now does nothing (first and second method works still fine).
The device itself works properly. On Anki iOS I can associate buttons with some actions, in my case replaying audio with another button works correctly. I was checking the device with websites like gamepadtester[.]com and each button works fine.
I have no idea where I can fix the problem.
<span class="NL_Hint">{{NL_Translation}}</span>
<style>
.NL_Hint
{
opacity: 0;
transition: opacity 0.3s;
}
</style>
<script>
(function()
{
let isAnswerVisible = false;
let buttonPreviouslyPressed = false;
function getAnswers()
{
return document.querySelectorAll('.NL_Hint');
}
function toggleAnswer()
{
isAnswerVisible = !isAnswerVisible;
getAnswers().forEach(function(el)
{
el.style.opacity = isAnswerVisible ? '0.6' : '0';
});
}
// ###################
// PC KEYBOARD - X KEY
// ###################
document.addEventListener('keydown', function(event)
{
if (event.key === 'x' || event.key === 'X')
{
toggleAnswer();
}
});
// ###################
// IOS TAP or PC CLICK
// ###################
document.body.addEventListener('click', function()
{
toggleAnswer();
});
// ###############################
// BLUETOOTH CONTROLLER - X BUTTON
// ###############################
function checkGamepad()
{
const gamepads = navigator.getGamepads();
if (gamepads[0])
{
const gp = gamepads[0];
const buttonPressed = gp.buttons[2]?.pressed;
if (buttonPressed && !buttonPreviouslyPressed)
{
toggleAnswer();
}
buttonPreviouslyPressed = buttonPressed;
}
requestAnimationFrame(checkGamepad);
}
window.addEventListener("gamepadconnected", function(e)
{
console.log("Gamepad connected:", e.gamepad);
requestAnimationFrame(checkGamepad);
});
requestAnimationFrame(checkGamepad);
})();
</script>