Question
How to dispatch a keyboard event?
I am submitting this question a second time because my first question was marked as spam for some reason.
The tools guide (page 152) documents how to create and dispatch a keyboard event, using initKeyboardEvent. I have been unable to get that to work, and I haven't been able to find working sample on the internet.
// This test is in the onChanging event to eliminate lack of focus as the source of the problem
var odd = false;
editText.onChanging = function editText_onChanging() {
// This odd is here just to prevent a looping problem if keyboard event starts to work and triggers onChanging again
odd = !odd;
if (!odd) {
return;
}
var keyboardEvent = ScriptUI.events.createEvent('KeyboardEvent');
// Tried with and without keydown, and with and without bubble.
// In addition to 'r' I have tried 'R' and 0x52 (which is VK_R).
// I have also tried using 'w' as my view (the main window).
keyboardEvent.initKeyboardEvent('keydown', false, false, editText, 'r', keyboardEvent.DOM_KEY_LOCATION_STANDARD, '');
keyboardEvent.initKeyboardEvent('keyup', false, false, editText, 'r', keyboardEvent.DOM_KEY_LOCATION_STANDARD, '');
editText.dispatchEvent(keyboardEvent);
}
Is the keyboard dispatching stuff no longer working?
Thanks
