Copy link to clipboard
Copied
"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();
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/
...
Copy link to clipboard
Copied
Try on "keypress" ?
Copy link to clipboard
Copied
Thanks. I tried "keypress". I didn't work in either CS6 or CS4.
Copy link to clipboard
Copied
Please contact Customer Care: http://helpx.adobe.com/contact.html They can login to your system.
Maybe they can help.
Copy link to clipboard
Copied
Hi @chanaart
I don't think that Customer Care will be helpful in Illustrator Scripting questions. Sorry
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
😉
Copy link to clipboard
Copied
Thanks. I tired that too. But no luck.
Copy link to clipboard
Copied
Strange.
Works for me in all newer versions.
Copy link to clipboard
Copied
same here it's not working on CS6, but it does work on CC2021
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
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.