[FR] Keyboard shortcuts for javascript tools  SOLVED

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: Daniel - PDF-XChange, PDF-XChange Support, Vasyl - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

Post Reply
Mathew
User
Posts: 564
Joined: Thu Jun 19, 2014 7:30 pm

[FR] Keyboard shortcuts for javascript tools

Post by Mathew »

I didn't want to continue hijacking viewtopic.php?t=41332 so created a new topic. I know this topic has been brought up before in various threads, but I couldn't find a specific one. Tracker did massively improve the usability of custom tools by adding the option to add custom buttons to the ribbon UI. However the ability to add keyboard shortcuts, and change the position of custom buttons is not available.
MedBooster wrote: Wed Nov 20, 2024 12:31 pm Anyway......
these Javascript tools confuse me, and what still is a bummer; that you can't place shortcuts to it or bind keyboard shortcuts through the traditional keyboard shortcut menu freely like with native commenting types.
I think it would be problematic if the script assigned the shortcut, because that shortcut may be used somewhere else. I really like the idea of a way within the current Customize Toolbars to also be able to customize both keyboard shortcuts and the location of the custom menu.

If I go to Customize Toolbars and get the properties of an installed tool:
image.png
It does give a properties dialog, but the button is given an arbitrary id. Based on the javascript API, the cName parameter is supposed to be a unique language-independent identifier (shown on the properties dialog as "Adobe Name"). If PXCE saved this tool ID as --for example-- 'js.cmd.drawRoundedRect' it could save position, keyboard shortcuts, etc for it, and override any position the script tries to assign next time it loads?
image(1).png
I imagine this could create quite a bit of clutter if tools are no longer used, but one approach to deciding whether to keep the information between sessions: If a tool is in the menu during application shutdown, then keep its settings?

[It would be possible to create a javascript that would take over adding menu items, and allow the locations to be adjusted by a user, but that is a whole new interface that would never be as good as the built-in one, and still does not address keyboard shortcuts.]
Last edited by Mathew on Thu Nov 21, 2024 12:17 am, edited 2 times in total.
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 10910
Joined: Wed Jan 03, 2018 6:52 pm

Re: [FR] Keyboard shortcuts for javascript tools

Post by Daniel - PDF-XChange »

Hello, Mathew

I will pass on the idea to see if we can use/retain and assign such shortcuts based on the tool ID, but to my knowledge, we do not offer this due to the fact that JS items are all loaded individually on startup, and are not retained session to session, which complicates retention.

With that said, I should note that every tool on our toolbars does by default have a "key-combination" assigned in some way. Specifically if you tap Alt you can see the keytips, and use them to navigate to your JS tools. If they are located in the same position with every start, than they should retain the same key combination for activation as well.

[Edit]
A late update, we did end up making a ticket for this request!
RT#7203: FR: Allow hotkeys for JS added tools.
Though I still cannot offer a timeline.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Mathew
User
Posts: 564
Joined: Thu Jun 19, 2014 7:30 pm

Re: [FR] Keyboard shortcuts for javascript tools

Post by Mathew »

TrackerSupp-Daniel wrote: Wed Nov 20, 2024 7:40 pm JS items are all loaded individually on startup, and are not retained session to session, which complicates retention.
Absolutely, understood. Retention would need some way to decide whether the tool might be loaded again at the next application startup, hence the check at application quit that I was suggesting...

I know this is a longshot, but it definitely would help with productivity for those of us who use the application a lot.
Last edited by Mathew on Wed Nov 20, 2024 10:28 pm, edited 1 time in total.
MedBooster
User
Posts: 1372
Joined: Mon Nov 15, 2021 8:38 pm

Re: [FR] Keyboard shortcuts for javascript tools

Post by MedBooster »

image.png
it would be great to have scripts you have in %appdata% to somehow appear here... but I guess it might be difficult for the program menu to understand which functions to bind keyboard shortcuts to... unless there were a specific phrase or something to be read that would refer to this.
My wishlist https://forum.pdf-xchange.com/viewtopic.php?p=187394#p187394
Disable SPACE page navigation, fix kb shortcut for highlighting advanced search tool search field, bookmarks with numbers, toolbar small icon size, AltGr/Ctrl+Alt keyboard issues
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 10910
Joined: Wed Jan 03, 2018 6:52 pm

Re: [FR] Keyboard shortcuts for javascript tools

Post by Daniel - PDF-XChange »

Hello, MedBooster

That one is less likely to happen, as this menu is intended more for locating and adding new tools to your bars, and tool position for Js items is strictly defined as part of the script, this would not be able to offer that functionality and it would simply be more confusion.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2444
Joined: Thu Jun 30, 2005 4:11 pm

Re: [FR] Keyboard shortcuts for javascript tools

Post by Vasyl - PDF-XChange »

Hi Mattew.

I think the new cHotkey-parameter for app.addToolButton/app.addMenuItem will solve this problem, when it is available.

And about saving menu/toolbar items added by JS between sessions: we do not save them currently. We only save changes the end-user makes, not by script or 3rd-party dev through SDK.

Cheers.
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Mathew
User
Posts: 564
Joined: Thu Jun 19, 2014 7:30 pm

Re: [FR] Keyboard shortcuts for javascript tools

Post by Mathew »

Vasyl-Tracker Dev Team wrote: Thu Nov 21, 2024 12:57 am I think the new cHotkey-parameter for app.addToolButton/app.addMenuItem will solve this problem.
Hi Vasyl,
Sorry if I'm being dense, but I didn't see any information about that parameter? Do I just provide a string?
/////////////////////////////////////////////////////////////////////////
// Functions:
/////////////////////////////////////////////////////////////////////////

// app.addSubMenu:
// std. params: cName, cUser, cParent, nPos
// adv. params: cRbParent, nRbPos, bNewRbGroup, nRbGroupStyle, bPrepend
// see: https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#addsubmenu

// app.addMenuItem:
// std. params: cName, cUser, cParent, nPos, cExec, cEnable, cMarked, bPrepend
// adv. params: cRbParent, nRbPos, oIcon, cIconID, nRbSepStyle
// see: https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#addmenuitem

// app.addToolButton:
// std. params: cName, oIcon, cExec, cEnable, cMarked, cTooltext, nPos, cLabel
// adv. params: cRbParent, nRbPos, nRbSepStyle, bPrepend, cIconID
// see: https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#addtoolbutton

/////////////////////////////////////////////////////////////////////////
// Advanced parameters/values:
/////////////////////////////////////////////////////////////////////////

// cName:
// standard non-optional parameter, specifies the unique ID of button/menu-item/buttons-group/toolbar/ribbon-tab
// - specify "-" to add separator to the menu/toolbar when cParent/cRbParent specifies the toolbar/buttons-group/menu/ribbon-tab
// functions: addSubMenu, addMenuItem, addToolButton

// cRbParent:
// optional parameter, specifies the unique ID or language independed name of target parent element in Ribbon UI where the new tab/toolbar/button-groups/menu/button should be added.
// - if not specified then cParent parameter will be used instead.
// - specify "" to add new ribbon-tab.
// - specify "-" to do not add new item to the ribbon UI.
// - you may specify "JS:Addon", "JS:QuickLaunch", "JS:QuickAccess", "JS:QuickFind" to get access to the corresponding special toolbars.
// functions: addSubMenu, addMenuItem, addToolButton

// nRbPos:
// optional parameter is used to specify insert position for new tabs, toolbars, toolbar's button-groups, and buttons in Ribbon UI.
// - specifies a number-position or language-independed ID/name of existing menu-item/button/buttons-group/toolbar/tab where the new item should be inserted
// - if not specified then standard nPos parameter will be used to insert new item to the Ribbon UI.
// - the bPrepend parameter also can be used to insert before or after the nRbPos/nPos.
// Note: for addSubMenu/addToolButton the bPrepend is true by default, but for addMenuItem bPrepend is false by default.
// functions: addSubMenu, addMenuItem, addToolButton

// bNewRbGroup:
// optional parameter is used to add new toolbars in Ribbon UI or to add new button-groups into toolbars
// 1. in Ribbon UI, to add new toolbar to the ribbon-tab the cRbParent should contain the ID/name of the tab.
// 2. to add new buttons-group into toolbar the cRbParent/cParent should contain the ID of the toolbar.
// functions: addSubMenu

// nRbGroupStyle flags:
// optional parameter to specify style of new group of buttons inside the toolbar.
// 1 - small buttons
// 2 - medium buttons
// 4 - buttons layout is horizontal "from left to right and from top to bottom",
// otherwise, if not specified, then "from top to bottom and from left to right", by default
// 8 - group has no visual separator before
// some flags can be combined together, for example:
// 5 - group contains horizontal rows of small buttons
// 14 - group has no separator before and contains horizontal rows of medium buttons
// functions: addSubMenu

// nRbSepStyle flags:
// optional parameter to specify style of new separator item
// 1 - non-break separator, can be used to "glue" some adjacent buttons together to visually keep them in one line when buttons are arranged horizontally
// 2 - hard-break separator, can be used to start new row in horizontal layout of buttons or new column in vertical layout
// 4 - invisible separator
// some flags can be combined together, for example:
// 5 - the invisible separator that glues together two adjacent buttons around itself
// functions: addMenuItem, addToolButton

// cIconID:
// optional parameter that specifies a special unique ID for an existing vector icon in Editor.
// example: "ico.plugin", "ico.pencil", "ico.pageWhite", "ico.delete", "ico.moreColors", "ico.preset", "ico.find", "ico.folder" ...
Mathew
User
Posts: 564
Joined: Thu Jun 19, 2014 7:30 pm

Re: [FR] Keyboard shortcuts for javascript tools

Post by Mathew »

Ignore that; I understand: that parameter will solve it (when it's included)
MedBooster
User
Posts: 1372
Joined: Mon Nov 15, 2021 8:38 pm

Re: [FR] Keyboard shortcuts for javascript tools

Post by MedBooster »

Vasyl-Tracker Dev Team wrote: Thu Nov 21, 2024 12:57 am Hi Mattew.

I think the new cHotkey-parameter for app.addToolButton/app.addMenuItem will solve this problem.

And about saving menu/toolbar items added by JS between sessions: we do not save them currently. We only save changes the end-user makes, not by script or 3rd-party dev through SDK.

Cheers.
what does this mean? That keyboard shortcuts and shortcut buttons (for the Javascript tools) can be placed anywhere like native ones, but can't be backed up or imported?
My wishlist https://forum.pdf-xchange.com/viewtopic.php?p=187394#p187394
Disable SPACE page navigation, fix kb shortcut for highlighting advanced search tool search field, bookmarks with numbers, toolbar small icon size, AltGr/Ctrl+Alt keyboard issues
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 10910
Joined: Wed Jan 03, 2018 6:52 pm

Re: [FR] Keyboard shortcuts for javascript tools

Post by Daniel - PDF-XChange »

Hello, MedBooster

This wont affect the button placement, it simply means that JS writers can add a hotkey into their JS button as part of its own code. As before, because the JS is loaded dynamically on every application start, we can only place these items where the script says they need to go. Manually changing that as the user through the UI is not possible, as there is no way to retain such changes. Even if we allowed you to move things, they would snap back every time you close and reopen the software.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Mathew
User
Posts: 564
Joined: Thu Jun 19, 2014 7:30 pm

Re: [FR] Keyboard shortcuts for javascript tools

Post by Mathew »

:?
Well, I won't look a gift horse in the mouth - but I think finding a way to save changes or shortcuts assigned by a user through the UI would be best. The difficulty with the script writer assigning a keyboard shortcut is that it could clobber one that a user wants to keep for something else.
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2444
Joined: Thu Jun 30, 2005 4:11 pm

Re: [FR] Keyboard shortcuts for javascript tools

Post by Vasyl - PDF-XChange »

We may think about it... Looks like we can allow end-user customization for menu/toolbar items added via AppLevel scripts, but not for DocLevel scripts. So user will be able to reorder them on toolbars/menus and set custom shortcuts.
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Mathew
User
Posts: 564
Joined: Thu Jun 19, 2014 7:30 pm

Re: [FR] Keyboard shortcuts for javascript tools

Post by Mathew »

:shock: Wow great news :D
Mathew
User
Posts: 564
Joined: Thu Jun 19, 2014 7:30 pm

Re: [FR] Keyboard shortcuts for javascript tools

Post by Mathew »

I just tried this in build 393 and you can both assign a keyboard shortcut through the UI, and it sticks through restarts! Fantastic! :D
MedBooster
User
Posts: 1372
Joined: Mon Nov 15, 2021 8:38 pm

Re: [FR] Keyboard shortcuts for javascript tools

Post by MedBooster »

Care to explain shortly @Mathew? How to assign it (in the command menu or in the javascript code) or is it explained in the manual?
My wishlist https://forum.pdf-xchange.com/viewtopic.php?p=187394#p187394
Disable SPACE page navigation, fix kb shortcut for highlighting advanced search tool search field, bookmarks with numbers, toolbar small icon size, AltGr/Ctrl+Alt keyboard issues
Mathew
User
Posts: 564
Joined: Thu Jun 19, 2014 7:30 pm

Re: [FR] Keyboard shortcuts for javascript tools  SOLVED

Post by Mathew »

To assign a keyboard shortcut to a script in the Javascripts folder that has a menu item (requires PDF XChange build 393 or later):
  • The script must have been loaded at application startup from the Javascripts folder
  • Select "Customize Toolbars…" from the Quick launch bar
    image.png
    image.png (9.86 KiB) Viewed 1827 times
  • Right click on the toolbar button you want to add a keyboard shortcut to and select "Properties…"
    image(1).png
    image(1).png (21.88 KiB) Viewed 1827 times
  • Enter the keyboard shortcut you want in the "Keys:" field and press the check box on the right to add it
    image(2).png
  • Press "OK" and close the "Customize Toolbars" dialog. The keyboard shortcut is now assigned to the script.
Last edited by Mathew on Thu Mar 06, 2025 6:18 pm, edited 1 time in total.
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2444
Joined: Thu Jun 30, 2005 4:11 pm

Re: [FR] Keyboard shortcuts for javascript tools

Post by Vasyl - PDF-XChange »

JFYI: in Build 10.5.0.393 we added this:
image.png
So now you can specify the shortcut to JS-command directly in the script.

Here is sample script that shows how to add custom Tabs/Groups/Menus/Buttons to the Ribbon/Classic UI, with the custom shortcuts specified.
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Mathew
User
Posts: 564
Joined: Thu Jun 19, 2014 7:30 pm

Re: [FR] Keyboard shortcuts for javascript tools

Post by Mathew »

Vasyl - PDF-XChange wrote: Wed Jan 15, 2025 6:44 pm So now you can specify the shortcut to JS-command directly in the script.
That's great :D

I assume that when it says custom shortcuts are processed before "standard" ones that if I assign a shortcut in a script, and a user has changed it, then their shortcut will override (?) I wouldn't want to clobber a users custom shortcuts by adding the same one in a script, or even override their choice of shortcut for that script.
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2444
Joined: Thu Jun 30, 2005 4:11 pm

Re: [FR] Keyboard shortcuts for javascript tools

Post by Vasyl - PDF-XChange »

Currently:
- if you add cmd by JS with specified shortcut and then user customized shortcut for that cmd - the user's shortcut will be used then.
- but exists another problem: again, you added the cmd by JS with shortcut, let's say "Ctrl+Shift+A" and then later the user specified *the same* "Ctrl+Shift+A" shortcut for *another* cmd - then priority will be 'undefined'. For some pairs of commands the "Ctrl+Shift+A" may launch your cmd, but for other pairs - the cmd customized by the user. We know about this issue and will try to fix it soon. So in any case, the user's preference/customization will have higher priority.
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Post Reply