Recording key presses while full screen? | XM Community
Skip to main content

Hello,
I am trying to record the amount of times a key is pressed during a video that plays in full screen. I can successfully make the video play in full screen automatically and record key presses but not at the same time. It seems that the question needs to clicked upon before it starts counting the key presses which never happens when the video starts in full screen. I had to disable the controls in the video in order to prevent rewinding, therefore, I can't allow participants to open in full screen themselves. Does anyone know of any potential solutions? Below is my current code for the question containing the video.

image.pngI appreciate any help!

I think you need to listen for key presses on the iframe document, not original Qualtrics document.
BTW, 'which' is deprecated. You should use 'key' instead.


Thank you for your quick response to this. I was actually able to get the key press recorded properly by placing the code into the question before the video and having the video start automatically.
My only issue now is that it doesn't seem to allow me to record the count of multiple key presses. I am trying to record up to 4 -5 different key presses. Below is the code I've used (when I switched which to key, it seemed to stop functioning):
image.pngI've defined both variables in the survey flow. Any suggestions on how to collect both? I very much appreciate the help and patience, as I am a novice to any programming.


  1. https://community.qualtrics.com/XMcommunity/discussion/comment/45536#Comment_45536key contains the key, not the key code

  2. You should use one keydown handler

document.onkeydown = function(event) {
if(event.key.toUpperCase() == "G") {
...
}
else if(event.key.toUpperCase() == "D") {
...
}
}


This was extremely helpful. Thank you very much!


Ok last question - sorry! I resolved this too fast. Any easy way to stop the code from spilling over into other blocks? If I should re-post this as a new question, please let me know. Thanks again for the help.


https://community.qualtrics.com/XMcommunity/discussion/comment/45548#Comment_45548Add

document.onkeydown = null
to the addOnUnload function.


Perfect. Can't thank you enough!


Leave a Reply