I can't figure out why my function isn't working to trigger the audio. Any suggestions would be very much appreciated.
tags$div(
tags$audio(id = 'targetAudio',src = sprintf("audioResources/%s.wav", trialName), type = 'audio/wav'),
tags$button(onclick="document.getElementById('targetAudio').play()",
type = 'button', '',
img(src = paste0(image, 'targetIcon.png'), width = 80, height = 80)),
tags$script("
var target = document.getElementById('targetAudio');
target.onkeydown = function(e) {
if (e.KeyCode === 49) {
target.play();
}
}
")
)
The button correctly works to trigger the audio, but I would also want to trigger the audio by using the number '1' (keycode = 49) on the keyboard.