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

Keyboard Shortcut Conflicts

Community Expert ,
May 22, 2017 May 22, 2017

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!

TOPICS
SDK

Views

2.5K

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
Explorer ,
May 22, 2017 May 22, 2017

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

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 ,
May 30, 2017 May 30, 2017

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

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
Enthusiast ,
May 31, 2017 May 31, 2017

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:

CSInterface.registerKeyEventsInterest Takes a JSON String

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));

KeyCode Registration is Different Between Mac/Win

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.

You May Be Experiencing A Bug

There are actually two possible bugs that are biting you right now.

  • Panels Stop Registering Keys Altogether - I've had a rough go of it with getting keyboard input handling to work. The one thing I've yet to try is resetting my computer (or killing all Adobe processes...).
    • EDIT: It turns out this was caused by a bug in my code. I'm leaving it here as a reference in case others encounter a similar issue by trying to use multi-line strings, rather than JSON.stringify-ing an object literal (or equivalent).
  • CEP Fails to Register the Command Key on macOS - I've confirmed with the Adobe team that there is a bug with CEP failing to register key interest for the Command key on the mac - it simply fails to so. Apparently this is being tracked in their internal bug tracker as issue CEP-445. In the meantime, I would highly suggest using the ctrlKey rather than the metaKey on macOS as well (as suggested in the example code).

I hope this is helpful.

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 ,
May 31, 2017 May 31, 2017

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!

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
Adobe Employee ,
May 31, 2017 May 31, 2017

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).

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
Enthusiast ,
May 31, 2017 May 31, 2017

Copy link to clipboard

Copied

LATEST

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?

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