Skip to main content
Participating Frequently
October 8, 2018
Answered

Deliberately inserting a keystroke "bug" into a text field.

  • October 8, 2018
  • 1 reply
  • 479 views

I'd like to program a "bug" into a proofreading test form I'm working on. The form is just a text field and my idea is that every so often, when a character is pressed on the keyboard, the field will select a different character to input into the field rather than the one pressed based on the character count.

Input example: The quick brown fox jumps over the lazy dog.

Output example: The quick lrown fox tumps overjthe lazy nog.

In the output example, every 10th keystroke is replaced by a letter 10 places after the letter pressed on the keyboard.

(A-Z & space = 1 through 27)

I'm not a whiz with JavaScript, but not entirely uneducated either. The only part that's eluding me is the "I'm pressing 'A'! Why is the &$+!?#@ field printing a 'K'?!" effect. Can such a thing be done?

Thanks in advance!

This topic has been closed for replies.
Correct answer try67

Sure, it's possible, and it's a fun exercise in coding... I've cobbled this code together to replace every 10th character with a random one:

if (event.change && AFMergeChange(event).length>0 && AFMergeChange(event).length%10==0) {

    var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

    var randomLetter = letters.charAt(Math.floor(Math.random() * letters.length));

    event.change = randomLetter;

}

Apply it as the field's custom Keystroke script. Note that it might appear as if nothing was entered after you click OK, but that's fine, it's just a bug in the application.

It should still work.

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
October 8, 2018

Sure, it's possible, and it's a fun exercise in coding... I've cobbled this code together to replace every 10th character with a random one:

if (event.change && AFMergeChange(event).length>0 && AFMergeChange(event).length%10==0) {

    var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

    var randomLetter = letters.charAt(Math.floor(Math.random() * letters.length));

    event.change = randomLetter;

}

Apply it as the field's custom Keystroke script. Note that it might appear as if nothing was entered after you click OK, but that's fine, it's just a bug in the application.

It should still work.