Count the number of Keystrokes | XM Community
Skip to main content

Hi all,
I have an essay question in a Qualtrics survey and want to be able to record--unbeknownst to respondents--the total number of keystrokes (ideally as embedded data) used to type into the text box.
I want to know, for instance, if someone typed in "hello" whether they typed that word (

keystrokes
= 5) or if they copy>pasted "hello" (
keystrokes
= 1 or 2). In fact, if someone wrote "hellos" then deleted the "s", I'd want that recorded too (
keystrokes
= 7). Does anyone know if this is possible?
Similarly, is there code that will automatically count the number of characters (so that anyone who writes "hello" would get a score of
characters
= 5 whether they copy>pasted, typed it perfectly, or had a typo that they corrected)?
Thanks!

Yes, for the first scenario you can have keydown event on .InputText and increment a counter in it.
Then, on click of NextButton you can set a ED with that counter value. Similarly for second scenario you can check the length of only character using regex and set it's value in another ED.


Hi rondev ,
Thanks for this quick response! I'm afraid I'm new to JS and don't have the skills to implement your proposed solutions (either the .InputText or the length-checker), or to save them as ED on the click of NextButton.
I tried hunting around the Qualtrics Community for relevant posts but couldn't find any. Do you know where code of this sort exists?
You're the best!

FWIW, HERE is the closest I've found.


Create two ED(CharacterCount, KeyStrokeCount ) at the beginning of survey flow and then paste below code in the JS of Essay question

var k =0;
var that = this;
jQuery("#"+ that.questionId+" .InputText ").on('keyup',function(){
k++;
});
jQuery("#NextButton").on('click',function(){
  Qualtrics.SurveyEngine.setEmbeddedData("KeyStrokeCount", k);
  Qualtrics.SurveyEngine.setEmbeddedData("CharacterCount", jQuery("#"+ that.questionId+" .InputText ").val().replace(/ /g,'').length);
  });


rondev Thanks so much!


Leave a Reply