Highlighted

How to dispatch a keyboard event?

Explorer ,
Jun 03, 2020

Copy link to clipboard

Copied

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

Topics

Error or problem, FAQ, How to, Scripting, SDK

Views

152

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

How to dispatch a keyboard event?

Explorer ,
Jun 03, 2020

Copy link to clipboard

Copied

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

Topics

Error or problem, FAQ, How to, Scripting, SDK

Views

153

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

Have something to add?

Join the conversation