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
unfortunately, there's no access to keystroke events using scripting. Except for what you tried above.
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.
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?
Copy link to clipboard
Copied
unfortunately, there's no access to keystroke events using scripting. Except for what you tried above.
Copy link to clipboard
Copied
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();