5 Replies Latest reply on Jun 13, 2011 1:45 PM by navand

    Window.shortcutkey help!

    navand

      My extendScript Toolkit's object explorer speaks of a property called Window.shortcutKey and an associated event:


      Window.shortcutKey

      Data Type: String
      ScriptUI Classes
      The keypress combination that invokes this element's onShortcutKey() callback.

       

      Window.onShortcutKey()
      ScriptUI Classes
      In Windows only, an event-handler callback function, called a shortcut-key sequence is typed that matches the shortcutKey value for this window.

       

      Not very useful definitions, those. The "Javascript Tools Guide" barely mentions them, nothing useful. They are not in the "Photoshop Scripting Guide" nor on the "Photoshop Javascript Reference".  Now, I want something like this:

       

      myWindow.shortcutKey="ENTER";

      myWindow.onShortcutKey=function(){
           alert("it works!");
      }

       

      That of course does not. "ENTER" doesn't seem to be the right value for the thing. And all reference material is useless. I've tried capitals, lower case, ASCII values, and then other keys except Enter. I need help.

        • 1. Re: Window.shortcutkey help!
          Muppet Mark Level 5

          Do you have a scriptUI 'window' either dialog or palette open? They are not in the Photoshop guide because they belong to the toolkit and the suite as a whole like file system access and other fluff…

          • 2. Re: Window.shortcutkey help!
            Michael L Hale Level 5

            The 'enter' key is handled by the window's default element. You do something like this for other shortcutKeys

             

            // shortcutKey only works on Windows OS
            var dlg = new Window( 'dialog', 'ShortcutKey Example' );
            dlg.btnRun = dlg.add('button',undefined,'Run');// 
            dlg.btnRun.shortcutKey = 'R';
            dlg.btnRun.onClick = function(){alert('it works');};
            dlg.btnRun.onShortcutKey = dlg.btnRun.onClick;
            dlg.show();
            // pressing alt-r now does the same as clicking in the 'run' button
            

             

            On Windows systems it is a way to interact with the dialog without using a mouse.

            1 person found this helpful
            • 3. Re: Window.shortcutkey help!
              navand Level 1

              Hmm.. I dind't know shortcutKey="a" would need 'Alt+a'. Is there a way to change this so no 'Alt' is needed?

              Also, can this be used with 'enter'? I can't seem to make it work with 'enter'...

              • 4. Re: Window.shortcutkey help!
                Michael L Hale Level 5

                To have the control use the enter key you need to use the defaultElement property.

                 

                // shortcutKey only works on Windows OS
                var dlg = new Window( 'dialog', 'ShortcutKey Example' );
                dlg.btnRun = dlg.add('button',undefined,'run');
                dlg.btnRun.shortcutKey = 'R';
                dlg.btnRun.onClick = function(){alert('it works');};
                dlg.btnRun.onShortcutKey = dlg.btnRun.onClick;
                dlg.defaultElement = dlg.btnRun;
                dlg.show();
                // pressing alt-r now does the same as clicking in the 'run' button
                

                 

                I don't know of any way around using the alt. That is a standard Windows OS behavior.

                • 5. Re: Window.shortcutkey help!
                  navand Level 1

                  defaultElement!! How did I miss that?

                   

                  This solves my 'Enter' problem. Sucks that Alt can't be overriden though.

                   

                  Thanks a ton!