assign a Keyboard Shortcut to a User Button
assign a Keyboard Shortcut to a User Button
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
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
Re: assign a Keyboard Shortcut to a User Button
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]", ...
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
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
Re: assign a Keyboard Shortcut to a User Button
No, it does not for me. Using the latest version 21.00
Re: assign a Keyboard Shortcut to a User Button
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.
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
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. TIAhighend wrote: ↑10 Sep 2020 05:26Code: 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)
Windows 10 Pro 22H2
Re: assign a Keyboard Shortcut to a User Button
Do I have to guess what you've tried exactly?
One of my scripts helped you out? Please donate via Paypal
Re: assign a Keyboard Shortcut to a User Button
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
Re: assign a Keyboard Shortcut to a User Button
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
?
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
Re: assign a Keyboard Shortcut to a User Button
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
Windows 10 Pro 22H2
Re: assign a Keyboard Shortcut to a User Button
Is it possible to add a button in the toolbar by script?
something like
I am trying without any result to get this 
or another functional code
something like
Code: Select all
userbutton 999, 132, "Test", "::e 'Left Click!'", "::e 'Right Click!';";or another functional code
Re: assign a Keyboard Shortcut to a User Button
Ofc this doesn't work
It is possible but it would require reading the
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
Re: assign a Keyboard Shortcut to a User Button
yes, you are absolutely right, it works, but can I do this by code?
I would like to use the code to open the .ini file, add this text and save the changes in .ini
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" }¶ } "
Re: assign a Keyboard Shortcut to a User Button
Sure, this is doable but it requires some effort and enough knowledge.
- Read the whole ini file
- Get the
- Iterate over the entries, find the first one with
- Replace that with your new button code
- Replace the section, write the file back, exit and restart without saving...
- 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
XYplorer Beta Club