Skip to main content
femkeblanco
Legend
January 26, 2021
Answered

"keydown" and "keyup" events not recognised in AI CS6

  • January 26, 2021
  • 5 replies
  • 873 views

"keydown" and "keyup" events do not seem to be recognised in AI CS6.  The snippet below works fine in AI CS4.  It is just me or is this across the board?  What's the case in CC?  Is there a way around this?  Thanks in advance. 

 

var window1 = new Window("dialog");
    var ed1 = window1.add("edittext", undefined, "0");
    var change = function (e) {
        if (e.keyName == "Up") {ed1.text = Number(ed1.text)+1};
        if (e.keyName == "Down") {ed1.text = Number(ed1.text)-1};
    }
    ed1.addEventListener("keydown", function (e) {change(e)});
window1.show();

 

This topic has been closed for replies.
Correct answer CarlosCanto

I noticed that the Arrow keys and the Function keys don't work. All other keys work fine. I wonder if that has anything to do with the "Function" key that allows us to have two different set of function on the same key ie my Left Arrow and Home use the same key.

 

if using other keys works for you, you can try this. I'm using "comma" and "point" keys instead of "up" and "down"

// https://community.adobe.com/t5/illustrator/quot-keydown-quot-and-quot-keyup-quot-events-not-recognised-in-ai-cs6/m-p/11785169?page=1#M261383
// "keydown", "keyup" event don't work on CS6

var w = new Window ("dialog"),
ed = w.add ("edittext", undefined, 0),
oldText = Number(ed.text);

ed.characters = 6;
ed.active = true;
ed.onChanging = function(){changed()};

w.show();

function changed() {
     if (ed.text.match(/,/) != null){
         ed.text = oldText + 1;
         oldText = Number(ed.text);
         return;
     }
      if (ed.text.match(/\./) != null){
         ed.text = oldText - 1;
         oldText = Number(ed.text);
         return;
     }
     oldText = Number(ed.text);
}

5 replies

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
January 27, 2021

I noticed that the Arrow keys and the Function keys don't work. All other keys work fine. I wonder if that has anything to do with the "Function" key that allows us to have two different set of function on the same key ie my Left Arrow and Home use the same key.

 

if using other keys works for you, you can try this. I'm using "comma" and "point" keys instead of "up" and "down"

// https://community.adobe.com/t5/illustrator/quot-keydown-quot-and-quot-keyup-quot-events-not-recognised-in-ai-cs6/m-p/11785169?page=1#M261383
// "keydown", "keyup" event don't work on CS6

var w = new Window ("dialog"),
ed = w.add ("edittext", undefined, 0),
oldText = Number(ed.text);

ed.characters = 6;
ed.active = true;
ed.onChanging = function(){changed()};

w.show();

function changed() {
     if (ed.text.match(/,/) != null){
         ed.text = oldText + 1;
         oldText = Number(ed.text);
         return;
     }
      if (ed.text.match(/\./) != null){
         ed.text = oldText - 1;
         oldText = Number(ed.text);
         return;
     }
     oldText = Number(ed.text);
}
femkeblanco
Legend
January 28, 2021

In the cold light of day, the arrow keys not working isn't that big of a deal to me.  However, your solution is ingenious.  Thank you.  

CarlosCanto
Community Expert
Community Expert
January 26, 2021

same here it's not working on CS6, but it does work on CC2021

pixxxelschubser
Community Expert
Community Expert
January 26, 2021

Strange.

Works for me in all newer versions.

pixxxelschubser
Community Expert
Community Expert
January 26, 2021

Hi @chanaart 

I don't think that Customer Care will be helpful in Illustrator Scripting questions. Sorry

 

@femkeblanco 

Please try the following (I haven't CS6 for testing):

var window1 = new Window("dialog");
    var ed1 = window1.add("edittext", undefined, "0");
    ed1.active = true;
    var change = function (e) {
        if (e.keyName == "Up") {ed1.text = Number(ed1.text)+1};
        if (e.keyName == "Down") {ed1.text = Number(ed1.text)-1};
    }
    ed1.addEventListener("keydown", function (e) {change(e)});
window1.show();

 

If that works for you

have fun

😉

femkeblanco
Legend
January 26, 2021

Thanks.  I tired that too.  But no luck.

Silly-V
Legend
January 26, 2021

Try on "keypress" ? 

femkeblanco
Legend
January 26, 2021

Thanks.  I tried "keypress".  I didn't work in either CS6 or CS4.

chanaart
Community Expert
Community Expert
January 26, 2021

Please contact Customer Care: http://helpx.adobe.com/contact.html They can login to your system.

Maybe they can help.