assign a Keyboard Shortcut to a User Button

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
WWL
Posts: 16
Joined: 10 Sep 2020 00:24

assign a Keyboard Shortcut to a User Button

Post by WWL »

I have created a User Button executing a custom script; I would like to assign a Keyboard Shortcut to this User Button. Is this possible? Thanks

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: assign a Keyboard Shortcut to a User Button

Post by highend »

Code: Select all


01. Either:
    Menu - Tools - Customize Toolbar... (hold CTRL when you click on the "Customize Toolbar..." entry!)
    or
    Press and hold the CTRL key (for all the following clicks!) - Right click any button on the toolbar and choose "Customize Toolbar..." from the context menu

    Look at the identifier inside the square brackets at the end of a button you want to assign the keyboard shortcut to
        E.g. "[ctb1]", "[undo]", ...


02. Menu - User - Manage Commands...
    Category:
        Run Script

    Commands:
        Button "New..."
            Context menu: Add New Command
                Command Properties:
                    Action : Run specified script.
                    Caption: E.g.: Execute user button 1
                    Script : button "ctb1";

                    Notes: You can access every button by using its identifier regardless if it's on the toolbar or not!
                           Look up the script command "button" in the help file to see all of its possible mouse click types

                    Button "Assign Keyboard Shortcut..."
                        Choose a keyboard shortcut to be able to emulate the button click here...

    Button "OK" (to close the "Manage User-Defined Commands" window)

One of my scripts helped you out? Please donate via Paypal

WWL
Posts: 16
Joined: 10 Sep 2020 00:24

Re: assign a Keyboard Shortcut to a User Button

Post by WWL »

Thanks for the quick response. Your instruction works.
Interestingly, based on your instructions below, the identifier inside the square brackets does not show at the end of a button when doing 'Menu - Tools - Customize Toolbar... (or: Right click any button on the toolbar while holding CTRL and choose "Customize Toolbar..." from the context menu)'.
The only way to show the identifier for me is to right click the User Button (the one I created) and choose "Customize Toolbar..."


Menu - Tools - Customize Toolbar... (or: Right click any button on the toolbar while holding CTRL and choose "Customize Toolbar..." from the context menu)
Look at the identifier inside the square brackets at the end of a button you want to assign the keyboard shortcut to
E.g. "[ctb1]", "[undo]", ...

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: assign a Keyboard Shortcut to a User Button

Post by highend »

Holding CTRL while clicking any icon on the toolbar (not necessarily the one you've defined) does not show the identifiers?
One of my scripts helped you out? Please donate via Paypal

WWL
Posts: 16
Joined: 10 Sep 2020 00:24

Re: assign a Keyboard Shortcut to a User Button

Post by WWL »

No, it does not for me. Using the latest version 21.00

WWL
Posts: 16
Joined: 10 Sep 2020 00:24

Re: assign a Keyboard Shortcut to a User Button

Post by WWL »

So, I did more testing…
Holding CTRL while clicking on the "Customize Toolbar..." button will show the identifiers.
No matter how you get to "Customize Toolbar...", you will need to hold down CTRL while clicking on "Customize Toolbar..." to show the identifiers.

kiwichick
Posts: 648
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Re: assign a Keyboard Shortcut to a User Button

Post by kiwichick »

highend wrote: 10 Sep 2020 05:26

Code: Select all


01. Either:
    Menu - Tools - Customize Toolbar... (hold CTRL when you click on the "Customize Toolbar..." entry!)
    or
    Press and hold the CTRL key (for all the following clicks!) - Right click any button on the toolbar and choose "Customize Toolbar..." from the context menu

    Look at the identifier inside the square brackets at the end of a button you want to assign the keyboard shortcut to
        E.g. "[ctb1]", "[undo]", ...


02. Menu - User - Manage Commands...
    Category:
        Run Script

    Commands:
        Button "New..."
            Context menu: Add New Command
                Command Properties:
                    Action : Run specified script.
                    Caption: E.g.: Execute user button 1
                    Script : button "ctb1";

                    Notes: You can access every button by using its identifier regardless if it's on the toolbar or not!
                           Look up the script command "button" in the help file to see all of its possible mouse click types

                    Button "Assign Keyboard Shortcut..."
                        Choose a keyboard shortcut to be able to emulate the button click here...

    Button "OK" (to close the "Manage User-Defined Commands" window)

Hi highend, I know this thread is over a year old now but I tried this on several custom buttons and it doesn't work for me. I tried it on a standard and it worked for that. I would welcome any suggestions you might have. TIA :)
Windows 10 Pro 22H2

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: assign a Keyboard Shortcut to a User Button

Post by highend »

Do I have to guess what you've tried exactly?
One of my scripts helped you out? Please donate via Paypal

kiwichick
Posts: 648
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Re: assign a Keyboard Shortcut to a User Button

Post by kiwichick »

highend wrote: 01 Oct 2021 23:32 Do I have to guess what you've tried exactly?
No you don't have to guess. I've tried what you said in the quoted instructions. Not sure what else you'd like me to say but I'm happy to provide any other information you want :)
Windows 10 Pro 22H2

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: assign a Keyboard Shortcut to a User Button

Post by highend »

Show screenshots of

1. The customize toolbar (with visible ids!) window with the custom button that you've added (visible in the right pane)
2. The window of that button definition

?
One of my scripts helped you out? Please donate via Paypal

kiwichick
Posts: 648
Joined: 08 Aug 2012 04:14
Location: Windows 10 Pro 22H2, 150% scaling

Re: assign a Keyboard Shortcut to a User Button

Post by kiwichick »

highend wrote: 02 Oct 2021 10:50 Show screenshots of

1. The customize toolbar (with visible ids!) window with the custom button that you've added (visible in the right pane)
2. The window of that button definition

?
Sorry, highend, but it seems I have wasted your time. Last night I tried it on 4 different buttons and it didn't work but this morning I've created the UDCs again and they're working just fine :appl: Goodness knows what what was going on before :? Thanks for the great info!!! :biggrin:
Windows 10 Pro 22H2

atisoro
Posts: 29
Joined: 27 Jan 2025 16:27

Re: assign a Keyboard Shortcut to a User Button

Post by atisoro »

Is it possible to add a button in the toolbar by script?
something like

Code: Select all

userbutton 999, 132, "Test", "::e 'Left Click!'", "::e 'Right Click!';";
I am trying without any result to get this :blackstorm:

or another functional code

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: assign a Keyboard Shortcut to a User Button

Post by highend »

Ofc this doesn't work
userbutton emulates a click on a custom toolbar button^^

It is possible but it would require reading the [CustomButtons] section in the .ini file, do the changes there and then quit & restart XY without saving settings...
One of my scripts helped you out? Please donate via Paypal

atisoro
Posts: 29
Joined: 27 Jan 2025 16:27

Re: assign a Keyboard Shortcut to a User Button

Post by atisoro »

yes, you are absolutely right, it works, but can I do this by code?

Code: Select all

[CustomButtons]
Version=1
Count=1
1=""new script launcher|:up|0|0" $allScripts = listfolder(<xyscripts>, "*.xys");  ¶	    $count_xys = gettoken($allScripts, "count", ",");¶	¶	    if ($count_xys) {¶	    $allScripts = replace(report("{basename} - ({comment})|",$allScripts)," - ()");¶	    $selectedscript = inputselect("Select one script to execute",$allScripts,,32);¶	        If ($selectedscript>"") ¶	           {¶	        $selectedscript = regexreplace($selectedscript, "(.+) -.+", "$1");¶	        load $selectedscript; ¶	           }¶	        } else {¶	    $mycom = "This is a autocreated script";¶	    writefile("<xyscripts>\hello.xys", " msg ""Your scripts folder not contain any script (*.xys)!<br>Warning:$mycom!<br>Script location is <xyscripts>"",48,,""$mycom"";");¶	    tag $mycom, "<xyscripts>\hello.xys", 2;¶	    load "<xyscripts>\hello.xys" }¶	    }		"
I would like to use the code to open the .ini file, add this text and save the changes in .ini

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: assign a Keyboard Shortcut to a User Button

Post by highend »

Sure, this is doable but it requires some effort and enough knowledge.

- Read the whole ini file readfile()
- Get the [CustomButtons] section content getsectionlist()
- Iterate over the entries, find the first one with ^<number>=""$ (e.g. via regex) => A non-used one
- Replace that with your new button code
- Replace the section, write the file back, exit and restart without saving...
One of my scripts helped you out? Please donate via Paypal

Post Reply