• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to dispatch a keyboard event?

Explorer ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

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

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

Views

1.1K

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
Explorer ,
Jun 04, 2020 Jun 04, 2020

Copy link to clipboard

Copied

NT Productions recently uploaded this tutorial that might help https://www.youtube.com/watch?v=UBqdWdDmvao

Votes

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
Explorer ,
Jun 04, 2020 Jun 04, 2020

Copy link to clipboard

Copied

Thanks for the great reference. This person's channel looks like it will be useful. Unfortunately this particular video only addresses handling keyboard events, not firing keyboard events.

Votes

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
Explorer ,
Jun 05, 2020 Jun 05, 2020

Copy link to clipboard

Copied

I don't think you can fire keyboard events otherwise you might be able to do nefarious things to peoples computers.

Votes

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
Explorer ,
Jun 05, 2020 Jun 05, 2020

Copy link to clipboard

Copied

LATEST

According to documentation, the keyboard events have targets, like Script UI controls, not necessarily the system as a whole. What is mysterious is if it weren't possible, why are methods like initKeyboardEvent documented?

If Nefarious things were a concern, they wouldn't have made scripts have direct access to the file system, or make it possible to enable Chromium extensions with NodeJS, or to allow calls to system.callSystem()...

Votes

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