Page 1 of 2

assign a Keyboard Shortcut to a User Button

Posted: 10 Sep 2020 00:40
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

Re: assign a Keyboard Shortcut to a User Button

Posted: 10 Sep 2020 05:26
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)


Re: assign a Keyboard Shortcut to a User Button

Posted: 10 Sep 2020 18:10
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]", ...

Re: assign a Keyboard Shortcut to a User Button

Posted: 10 Sep 2020 18:18
by highend
Holding CTRL while clicking any icon on the toolbar (not necessarily the one you've defined) does not show the identifiers?

Re: assign a Keyboard Shortcut to a User Button

Posted: 10 Sep 2020 20:08
by WWL
No, it does not for me. Using the latest version 21.00

Re: assign a Keyboard Shortcut to a User Button

Posted: 10 Sep 2020 20:38
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.

Re: assign a Keyboard Shortcut to a User Button

Posted: 01 Oct 2021 23:26
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 :)

Re: assign a Keyboard Shortcut to a User Button

Posted: 01 Oct 2021 23:32
by highend
Do I have to guess what you've tried exactly?

Re: assign a Keyboard Shortcut to a User Button

Posted: 02 Oct 2021 10:39
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 :)

Re: assign a Keyboard Shortcut to a User Button

Posted: 02 Oct 2021 10:50
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

?

Re: assign a Keyboard Shortcut to a User Button

Posted: 02 Oct 2021 21:38
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:

Re: assign a Keyboard Shortcut to a User Button

Posted: 04 Feb 2025 10:04
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

Re: assign a Keyboard Shortcut to a User Button

Posted: 04 Feb 2025 10:25
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...

Re: assign a Keyboard Shortcut to a User Button

Posted: 04 Feb 2025 10:39
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

Re: assign a Keyboard Shortcut to a User Button

Posted: 04 Feb 2025 10:52
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...