Copy link to clipboard
Copied
Is there a way to override Premiere Pro shortcuts when your custom CEP Panel is in focus? For instance, I'm trying to get the Cmd+Z and Cmd+Shift+Z shortcut for a text field in my panel, but it keeps triggering the Premiere Pro undo command instead.
$("#editor").on("keyup", function(e){
e.preventDefault();
if(e.keyCode == 91 && e.keyCode == 90)
{
undoEdit();
}
});
I know the code works since I tested it with each key individually, and I believe e.preventDefault() is supposed to allow this, but it's not working in my case. Any thoughts are appreciated. Thanks!
Copy link to clipboard
Copied
Hi J2T,
have you told CEP that you are interested in those particular keycodes?
By default, only keypresses when an input field is focused, are sent to your panel extension.
At all other times, keypresses go to the host application i.e. they are treated as Premiere keyboard shortcuts.
Look for "Register an interest in specific key events" in the CEP 6.1 cookbook:
CEP-Resources/CEP_6.1_HTML_Extension_Cookbook.pdf at master · Adobe-CEP/CEP-Resources · GitHub
JT
Copy link to clipboard
Copied
jingtaotan​ Thanks for the help, that method seems pretty straightforward, however for some reason it's not recognizing my events. The commands are still going to Premiere and skipping my panel. Have you had success with this? I'm trying to catch the Command + Z keystroke:
var csInterface = new CSInterface();
csInterface.registerKeyEventsInterest(
[{
"keyCode": 90,
"metaKey": true
}]
);
Thanks,
Justin
Copy link to clipboard
Copied
justin2taylor wrote
for some reason it's not recognizing my events. The commands are still going to Premiere and skipping my panel. Have you had success with this?
There are several issues here of which you should be aware:
According to the documentation (as well as successful tests), you must pass a JSON stringified version of the keyEventsInterest object into the registerKeyEventsInterest function. This would turn your code into the following:
var csInterface = new CSInterface();
var keyEvents = [{
"keyCode": 90,
"metaKey": true
}];
// Pass a JSON-ified version.
csInterface.registerKeyEventsInterest(JSON.stringify(keyEvents));
The HTML key input events report identical KeyCodes regardless of the host OS. One list of KeyCodes for HTML callbacks can be found here. This is not the case for the registerKeyEventsInterest function, however! Rather annoyingly, KeyCodes sent to Adobe applications are platform-specific. A list of KeyCodes for MAC can be found here. A list of KeyCodes for WIN can be found here (I believe these are identical to the HTML spec). Thus, to register for both Windows and Mac platforms, your code would look like this:
// Is Platform Mac or Win?
var isMac = (navigator.userAgent.indexOf("Mac") != -1);
// Register for interest.
var csInterface = new CSInterface();
var keyEvents = [];
if (isMac)
{
keyEvents.push({
"keyCode": 6, // Z - in hex: 0x06 (or 0x6).
"metaKey": true // WARNING: This is probably buggy.
//"ctrlKey": true // <-- SUGGESTION: Use this instead of metaKey.
});
}
else
{
keyEvents.push({
"keyCode": 90, // Z - in hex: 0x5A.
"ctrlKey": true // Use CTRL on Windows.
});
}
// Register with Premiere. Pass a JSON-ified version.
csInterface.registerKeyEventsInterest(JSON.stringify(keyEvents));
// Register with HTML.
$("#editor").on("keyup", function(e){
e.preventDefault();
if(e.keyCode == 90) // Z.
{
if ((isMac && event.metaKey) || // WARNING: This is probably buggy.
//((isMac && event.ctrlKey) || // <-- SUGGESTION: Use this instead of metaKey.
(!isMac && event.ctrlKey))
{
undoEdit();
}
}
});
NOTE: You can use hexadecimal numbers in your JavaScript for both the HTML event handlers and the registerKeyEventsInterest function.
There are actually two possible bugs that are biting you right now.
I hope this is helpful.
Copy link to clipboard
Copied
sberic​ Really appreciate your in-depth response! I've tried your code and several variations, but I still can't get my Panel to recognize the Command (MetaKey) when using Cmd+Z etc, it just keeps going straight to the application. Using Ctrl+Z works just fine. Seems strange since the CEP documentation shows that the MetaKey can be used, and it's even recognized in the CEP Test Panel.
Bruce Bullis​ Are you aware of any temporary workarounds for using the Command (MetaKey) in our Panels, or do we need wait for the CEP-445 bug to get fixed? Thanks!
Copy link to clipboard
Copied
I know of no temporary workarounds.
In case it's of interest, here are some references Zac Lam has provided in the past, to panel developers.
Here's some sample code I was working on for AE, which gets basic keystrokes working for registered key events: https://github.com/Adobe-CEP/Samples/blob/AE_Key_Events/AfterEffectsPanel/ext.js
Note that key codes vary depending on type of keyboard. You could check the code for your keyboard using the Mac app called "Key Codes" on the Mac App Store: (https://itunes.apple.com/us/app/key-codes/id414568915?mt=12).
Copy link to clipboard
Copied
justin2taylor wrote
Seems strange since the CEP documentation shows that the MetaKey can be used, and it's even recognized in the CEP Test Panel.
That test panel screenshot you took appears to look at metaKey usage while clicking, not responding to key events. Probably handled differently on the Adobe app side...
Unless you've tested KeyCodes in that panel yourself?