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

Community Beginner ,
Oct 08, 2018 Oct 08, 2018

Copy link to clipboard

Copied

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!

TOPICS
Acrobat SDK and JavaScript

Views

85

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Most Valuable Participant , Oct 08, 2018 Oct 08, 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 no...

Likes

Translate

Translate
Most Valuable Participant ,
Oct 08, 2018 Oct 08, 2018

Copy link to clipboard

Copied

LATEST

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines