CEP-Resources icon indicating copy to clipboard operation
CEP-Resources copied to clipboard

Are keyboard shortcuts possible for a CEP panel?

Open sean256 opened this issue 5 years ago • 8 comments

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?

sean256 avatar Jun 13 '19 17:06 sean256

+1 This would be really helpful for us.

samsamm777 avatar Jul 08 '19 12:07 samsamm777

+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

lacroixthomas avatar Jul 08 '19 14:07 lacroixthomas

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

prernavij avatar Jul 09 '19 12:07 prernavij

@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 avatar Jul 09 '19 15:07 sean256

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

sean256 avatar Jul 26 '19 20:07 sean256

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?

MaxJohnson avatar Jul 26 '19 20:07 MaxJohnson

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

michael-dm avatar Sep 07 '20 09:09 michael-dm