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

Creating a KeyboardEvent and sending it to a ScriptUI Control Object with dispatchEvent()

Community Expert ,
Nov 16, 2023 Nov 16, 2023

So, I looked all over the internet for an example of how to send a KeyboardEvent from within ScriptUI to another control object and didn't really find a solid answer. There are plenty mentions of the technique but no actual code, at least I couldn't find it. I was finally able to sort it out today so I am sharing it here in case anyone else needs to accomplish something similar.

 

 

// create an event
var kbEvent = ScriptUI.events.createEvent("KeyboardEvent");
// initialize the event using the format described in the docs
kbEvent.initKeyboardEvent("keydown", true, true, listBox, kd.keyName, 0, "");
// send the event to another control object with the `dispatchEvent()` method
SomeScriptUIControlObject.dispatchEvent(kbEvent);

 

 

As you can, it is pretty straight forward, you just need to initialize the event with your own values using the format below.

 

eventObj.initKeyboardEvent (eventName, bubble, isCancelable, view, keyID, keyLocation, modifiersList)

 

 

To help figure it out, I captured the details of some key events. Here are the attributes from pressing the "Down" key for reference.

 

ExtendScript Keydown Event

keyName: Down
keyIdentifier: Down
keyLocation: 0
ctrlKey: false
altKey: false
shiftKey: false
metaKey: false
DOM_KEY_LOCATION_STANDARD: 0
DOM_KEY_LOCATION_LEFT: 1
DOM_KEY_LOCATION_RIGHT: 2
DOM_KEY_LOCATION_NUMPAD: 3
view: [control object]
detail: 1
captures: true
bubbles: true
cancelable: true
currentTarget: [control object]
eventPhase: target
target:  [control object]
timeStamp: Thu Nov 16 2023 12:30:29 GMT-0500
type: keydown
NOT_DISPATCHING: 0
CAPTURING_PHASE: 1
AT_TARGET: 1
BUBBLING_PHASE: 3

 

 

Reference Material:

 

Cheers ✌️

TOPICS
Scripting
392
Translate
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
Adobe
Community Expert ,
Nov 18, 2023 Nov 18, 2023
LATEST

This is great info @jduncan. I'll try this out when I get the chance. Thanks for putting in the time to work it out!

- Mark

Translate
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