Skip to main content
Justin Taylor-Hyper Brew
Community Expert
Community Expert
May 22, 2017
Frage

Keyboard Shortcut Conflicts

  • May 22, 2017
  • 1 Antwort
  • 3292 Ansichten

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!

Dieses Thema wurde für Antworten geschlossen.

1 Antwort

jingtaotan
Inspiring
May 23, 2017

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

Justin Taylor-Hyper Brew
Community Expert
Community Expert
May 30, 2017

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

sberic
Legend
May 31, 2017

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.