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

app.addEventListener("keydown" ... fails. Is there a way?

Explorer ,
Dec 10, 2019 Dec 10, 2019

Copy link to clipboard

Copied

app.addEventListener("keydown", function (kd) { pressed(kd) });
app.activeDocument.addEventListener("keydown", function (kd) { pressed(kd) });
 
 
both fail -- "keydown" is not a recognized event type
 
Is there a way to add a keydown event listener at the app level?
(Trying to write a script that will process keystrokes sent by an external app...)
TOPICS
Scripting

Views

1.2K

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
Community Expert ,
Dec 12, 2019 Dec 12, 2019

Copy link to clipboard

Copied

Hi akiva_atwood,

what is the external app?

 

As far as I know "keydown" or "keyup" as event type can only be added successfully to event listeners with ScriptUI window elements like EditText in InDesign. See Marc Autret's answer in this thread:

 

Where is there a list of InDesign Event types?
Dick_Kain, Jan 05, 2017

https://community.adobe.com/t5/indesign/where-is-there-a-list-of-indesign-event-types/m-p/8851632

 

Regards,
Uwe Laubender

( ACP )

 

 

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 ,
Dec 12, 2019 Dec 12, 2019

Copy link to clipboard

Copied

Hi Uwe

Streamdeck -- it's a remote conrols hardware device.

It can send text strings to any app.

(It can also communicate via HTTP -- but I haven't managed to get ID to work as a HTTP Server (I'm on a mac))

I want to write a monitor script that looks for certain text strings coming in (for example "CSBold" and then assigns the "Bold" character style)

This avoids needing to set up keyboard shortcuts in each doc

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 ,
Dec 12, 2019 Dec 12, 2019

Copy link to clipboard

Copied

Apparently keydown events only work with dialog windows -- if I change my code to make it a palette it doesn't catch the event even if the palette has the focus...

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
Community Expert ,
Dec 13, 2019 Dec 13, 2019

Copy link to clipboard

Copied

Hi akiva_atwood,

I had mixed results with dialog type "palette" in CS6.

With InDesign 2020 and dialog type "window" I have to do some more tests.

It's working differently than with CS6.

 

All tests with the German version of InDesign on Windows 10.

 

Regards,
Uwe Laubender

( ACP )

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 ,
Dec 14, 2019 Dec 14, 2019

Copy link to clipboard

Copied

LATEST

Hi Uwe

 

Using the following code with diag=true the keydown events are caught. 

When it's false they aren't

 

#targetengine "streamdeck";

var diag=false;

    var w = diag ? new Window("dialog"):new Window("palette");
    var edit = w.add("edittext");
    edit.active = true;
edit.characters = 30;
var runButton = w.add('button {text: "test"}');
runButton.onClick = function () {
    $.writeln("test");
}
    $.writeln(1)
w.addEventListener("keydown", function (kd) { pressed(kd) });
edit.addEventListener("keydown", function (kd) { pressed(kd) });
    $.writeln(2)
    function pressed(k) {
        $.writeln(k.keyName);
        $.writeln(k.keyIdentifier);
        $.writeln(k.shiftKey ? "Shift pressed" : "Shift not pressed");
        $.writeln(k.altKey ? "Alt pressed" : "Alt not pressed");
        $.writeln(k.ctrlKey ? "Ctrl pressed" : "Ctrl not pressed");
    }
    w.show();
 

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