Adobe-CEP / CEP-Resources

Tools and documentation for building Creative Cloud app extensions with CEP
https://www.adobe.io/apis/creativecloud/cep.html
1.63k stars 829 forks source link

Are keyboard shortcuts possible for a CEP panel? #238

Open sean256 opened 5 years ago

sean256 commented 5 years ago

Use case

We have a panel which performs "action a" when user clicks on a button in the panel. Our users would like a keyboard shortcut which is always available to do "action a".

What we tried so far

registerKeyEventsInterest

This is a funny one. It works if the panel has focus, which requires the users to click into the panel so this doesn't work as a global keyboard shortcut. If the panel needs focus what is even the point of having us use registerKeyEventsInterest? I could see an interface like registerKeyEventsInterest making sense if we want to capture key events outside of our panel focus.

Panel Menus + Edit -> Keyboard Shortcuts...

Screen Shot 2019-06-13 at 10 09 54 AM

Options?

Is there any option available to us and our users to give them globally available keyboard shortcuts?

samsamm777 commented 5 years ago

+1 This would be really helpful for us.

lacroixthomas commented 5 years ago

+1 This would be really nice

As a workaround you can create a script to dispatch an event with new CSXSEvent() to be able to catch it from your CEP Panel An automate script which you can bind to a keyboard shortcut, but you loose a bit the point of the CEP Panel

prernavij commented 5 years ago

Hi @sean256 , when are you registering for the shortcut in your workflow? According to the documentation , you should be able to register. Please note, it says:

"This function works with modeless extensions and panel extensions. Generally all the key events will be sent to the host application for these two extensions if the current focused element is not text input or dropdown.

If you want to intercept some key events and you want them to be handled in the extension, please call this function in advance to prevent them being sent to the host application."

sean256 commented 5 years ago

@prernavij I register key events immediately and it works, but only if the panel has focus. If it is supposed to behave in any other way then it's bugged.

There is another open issue where people are having multiple issues with the registration of key events. Most of the thread is about OS key codes being different but there are a few who spotted that it also needs focus which defeats the purpose. https://github.com/Adobe-CEP/CEP-Resources/issues/165

sean256 commented 5 years ago

I got a bit of a convoluted hack working.

Create a JSX script and save it somewhere.

function sendEvent(type) {
    new ExternalObject('lib:\PlugPlugExternalObject'); // The next line fails unless this is called
    var event = new CSXSEvent();
    event.type = type;
    event.dispatch();
}

sendEvent('some-event-name-hotkey-thing');

In the Panel

csInterface.addEventListener('some-event-name-hotkey-thing', () => {
     // do something here
})

Photoshop (or other supporting app)

  1. Create an action which runs the above JSX script (using record, File->Scripts->Browse...)
  2. Attach hotkey to action
MaxJohnson commented 5 years ago

I got a bit of a convoluted hack working.

Create a JSX script and save it somewhere.

function sendEvent(type) {
    new ExternalObject('lib:\PlugPlugExternalObject'); // The next line fails unless this is called
    var event = new CSXSEvent();
    event.type = type;
    event.dispatch();
}

sendEvent('some-event-name-hotkey-thing');

If you wanted to have the hotkey more customizable, you could copy it to the photoshop scripts folder and hotkey to the File->Scripts->SomeEventHotkey.jsx directly.

More importantly, I wonder if it would be possible to use this to pass focus to your panel so other hotkeys would then work?

michael-dm commented 4 years ago

Anyone found a workaround for keyboard events when the panel is not focused ?

omarboulbaze commented 6 months ago

Anyone found a workaround for keyboard events when the panel is not focused ?

Same here, it would be appreciated if anyone has any ideas regarding this