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

Key press capturing not working

Community Beginner ,
Mar 17, 2017 Mar 17, 2017

Copy link to clipboard

Copied

Hi. I'm trying to capture some key presses but nothing seems to happen. Here's my code:

#target illustrator

var palette = new Window("palette", "Animation Settings");

var playButton = palette.add("button", undefined, "Play");

    playButton.addEventListener("keydown", function (kd) {

           testKeyPress(kd);

    });

function testKeyPress(k)

{

     $.writeln(k.keyName);

}

palette.show();

Any ideas as to why that doesn't work? I thought you could attach a keypress listener to any UI object? Attaching it to the palette doesn't work either. I'm targeting illustrator CS6

TOPICS
Scripting

Views

407

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

correct answers 1 Correct answer

Community Expert , Mar 18, 2017 Mar 18, 2017

unfortunately, there's no access to keystroke events using scripting. Except for what you tried above.

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 17, 2017 Mar 17, 2017

Copy link to clipboard

Copied

your code works perfectly. Just make sure to button is "Active" or it has the "Focus". Do that by pressing TAB key once.

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 Beginner ,
Mar 18, 2017 Mar 18, 2017

Copy link to clipboard

Copied

Hi CarlosCanto​. I see that makes sense. What I'd like to do though is be able to listen for key presses globally without having to focus on any object. Do you know how I would do that?

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 ,
Mar 18, 2017 Mar 18, 2017

Copy link to clipboard

Copied

unfortunately, there's no access to keystroke events using scripting. Except for what you tried above.

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
Valorous Hero ,
Mar 18, 2017 Mar 18, 2017

Copy link to clipboard

Copied

LATEST

The same code attached to the window object works, as long as someone 'tabs' into the window, making the button have its blue fill.

function test(){

    #target illustrator 

 

var palette = new Window("palette", "Animation Settings"); 

var playButton = palette.add("button", undefined, "Play"); 

    palette.addEventListener("keydown", function (kd) { 

           testKeyPress(kd); 

    }); 

 

  palette.onShow = function(){

    playButton.active = true;

  };

 

 

function testKeyPress(k) 

     $.writeln(k.keyName + " : " + k.target);

palette.show(); 

}

test();

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