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

Passing keyboard presses while panel is active

Community Beginner ,
Mar 02, 2017 Mar 02, 2017

Copy link to clipboard

Copied

Is it possible to pass keyboard/shortcut presses onto Premiere when the panel is active?

When I click a button on my panel and hit 'spacebar' (to play the timeline) since the panel is active, and not the timeline, I get an error noise. I then have to click back over to the timeline to reactivate the timeline, then hit spacebar to continue playing.

It would be awesome if when I have the panel active, and press a key, that it passes the key press to premiere to do it's usual thang.

TOPICS
SDK

Views

1.3K

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

correct answers 1 Correct answer

Participant , Mar 06, 2017 Mar 06, 2017

I see, yea, I misunderstood the initial question. I think it might be difficult since key strokes are targeted at the active panel. Since none of the host app's own panels is active, I assume it´s technically not easy to bypass key strokes because the question is: where should the keystroke be directed to? To the metadata, sequence or project panel?

So if you desire a certain effect to happen like "play the active sequence when space is pressed", then I suggest to register the spacebar in your pa

...

Votes

Translate

Translate
Engaged ,
Mar 02, 2017 Mar 02, 2017

Copy link to clipboard

Copied

It should work (certainly works for me) ... try telling the button to lose focus after it's clicked eg $(this).blur()

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 Beginner ,
Mar 02, 2017 Mar 02, 2017

Copy link to clipboard

Copied

I didn't know about .blur(). Thank you, Andy!

Unfortunately it'll happen when I click any part of the panel, button or not.

Interesting thing though, when I click the title of the panel (upper left) the panel will still be active, but key presses go through.

So I must have something that is intercepting key presses. I'm building my panel from the PProPanel sample. How about you?

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
Participant ,
Mar 03, 2017 Mar 03, 2017

Copy link to clipboard

Copied

You need to register for keyboard press events. The panel is not doing it by default (except if you´re typing sth into a textfield). Have you tried the following:

register_key_events = function() {

    var keyEventsInterest;

    var os = 'win';


    if (os === 'win') {

        keyEventsInterest = JSON.stringify([

            {"keyCode": 32} // Spacebar

        ]);

    } else {

        // mac

        keyEventsInterest = JSON.stringify([

            {"keyCode": 49} // Spacebar

        ]);

    }

    window.__adobe_cep__.registerKeyEventsInterest(keyEventsInterest);

}

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
Engaged ,
Mar 04, 2017 Mar 04, 2017

Copy link to clipboard

Copied

Hey Thomas

If I understand it correctly, registering an interest in key events is intended to prevent the registered key event from being sent to the host application. Is that right? I'm pretty green at this and trying to learn. If so, I think Bryson is asking for the opposite.

In Bryson's case (and in mine as it turns out) ... and with Bruce's PPro panel ... it seems that keyboard presses are not passed to the host application (Premiere) by default. Open the sample PPro Panel, then press the spacebar... does your computer 'beep' back at you, or does the spacebar action get passed to Premiere and thus the application starts/stops sequence playback? On my machine I just hear a 'beep' and the playhead stays put.

As Bryson describes, if I click anywhere in the panel's title area then 'spacebar' keyboard events are passed to Premiere (which is why I though it was working) ... but if I click anywhere within the body of the panel itself then 'spacebar' keyboard events are apparently intercepted and are not automatically passed to Premiere (although I can capture them with a window keypress listener if necessary and programmatically trigger a play/pause action using ExtendScript).

I seem to recall there was a change in behaviour with regards to keyboard events and panels a year or so ago (CC2015.1?) and the default behaviour changed such that thereafter the host captured pretty much all key events unless you specifically registered for them (or something like that) ... and then at some later date it seems like that default behaviour changed again (I only surmise this because I had just cobbled together my first attempt at a panel a few days before the 2015.1 update which rather broke it...   and then I discovered it had magically started working again at some later point though I have no idea when). I just started dabbling in panel building again a couple of months ago, so as noted, still very green.

Not entirely sure what is best practice is at this point.

Thanks in advance for any wisdom you can offer.

Andy

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
Participant ,
Mar 06, 2017 Mar 06, 2017

Copy link to clipboard

Copied

I see, yea, I misunderstood the initial question. I think it might be difficult since key strokes are targeted at the active panel. Since none of the host app's own panels is active, I assume it´s technically not easy to bypass key strokes because the question is: where should the keystroke be directed to? To the metadata, sequence or project panel?

So if you desire a certain effect to happen like "play the active sequence when space is pressed", then I suggest to register the spacebar in your panel, add a keyboard event listener that handles spacebar presses and execute a function that toggles play/pause of the sequence. Don´t rely on the host app to do the magic for you. Once your panel is active, you´re responsible for what happens with keyboard events - there is no passthrough feature.

I hope this helps.

Thomas

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 Beginner ,
Mar 06, 2017 Mar 06, 2017

Copy link to clipboard

Copied

Thank you Thomas,

Basically I'd like to have the panel handle keyboard events the same way other Premiere panels handle keyboard events, by passing them through to the active sequence.

Here is a video of what I'm trying to get at.

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
Participant ,
Mar 07, 2017 Mar 07, 2017

Copy link to clipboard

Copied

Ok I think I already answered your question above: there is no feature that bypasses the keyboard event!

Here is what needs to be done in order to make the space work like in other panels:

1. register your interest for the spacebar key event. See the code that I posted in answer #3.

2. next you need to check whether the host is Premiere or After Effects:

var host_env = JSON.parse(window.__adobe_cep__.getHostEnvironment());

var ppro = host_env.appId === "PPRO" || host_env.appName === "PPRO";

var aeft = this.host_env.appId === "AEFT" || this.host_env.appName === "AEFT";

3. listen for keyboard press events

<body onkeydown="keyDownInBody">

4. create a function that handles the event

function keyDownInBody(event) {

     var key_code = evt.keyCode; // returns an integer number representation of the pressed key

     // check if it's win or mac

     // check if key_code === spacebar

     if (ppro) {

          // toggle active sequence. you need to do some hackery to figure out if it´s currently playing

          app.enableQE();

          var seq = qe.project.getActiveSequence();

          if (seq) {

               seq.player.play();

          }

     }

     else if (aeft) {

          // toggle active comp

     }

That´s basically it.

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
New Here ,
Oct 04, 2020 Oct 04, 2020

Copy link to clipboard

Copied

LATEST

Hi @Thomas_Szabo , I am trying to implement your solution but I'm having some trouble. 

 

In my JS file I registered the key events like this

 

 

register_key_events = function() {
   var keyEventsInterest;
   var os = 'win';
   if (os === 'win') {
      keyEventsInterest = JSON.stringify([
         {"keyCode": 32} // Spacebar
      ]);
   } else {
   // mac
      keyEventsInterest = JSON.stringify([
         {"keyCode": 49} // Spacebar
      ]);
   }
   window.__adobe_cep__.registerKeyEventsInterest(keyEventsInterest);
}

 

 

Then later in the same JS file, I'm trying to listen for the event:

 

window.addEventListener('keydown', (event) => {
    var key_code = event.keyCode;
    var os = 'win';
    if (os === 'win') {
        if (key_code === 32) {
        playPause();
        } //will add more else if conditions for other keys and functions
    } else {
        // mac
        if (key_code === 49) {
            playPause();
            } //will add more else if conditions for other keys and functions
    }
});

 

 

However, it doesn't work in Premiere Pro. (I also tried document.addEventListener). How do I call "register_key_events" function? Is that what's missing? Am I missing any other piece of code somewhere? 

 

Thank you for taking a look!

 

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