Get the command currently assigned to a keyboard shortcut
-
kiwichick
- Posts: 732
- Joined: 08 Aug 2012 04:14
- Location: Pahiatua, New Zealand
Get the command currently assigned to a keyboard shortcut
Is it possible to use scripting to get the command for a specific keyboard shortcut? For example: get the command currently assigned to F6. If it is possible, can I create a script to get a list of commands for specified shortcuts? For example: get the commands currently assigned to F6, F9, Ctrl+F3, Shift+F12. I am constantly forgetting which commands are assigned to some shortcuts so it would be really helpful to be able to use a script to get them.
Windows 10 Pro 22H2
Scaling 150%
Scaling 150%
-
jupe
- Posts: 3569
- Joined: 20 Oct 2017 21:14
- Location: Win10 22H2 120dpi
Re: Get the command currently assigned to a keyboard shortcut
If you just open the
dialog and type the keyboard shortcut it will tell you what it does
Otherwise yes you can get them by scripting via
Help | List All Commands
dialog and type the keyboard shortcut it will tell you what it does
Otherwise yes you can get them by scripting via
get("ListOfCommands");-
kiwichick
- Posts: 732
- Joined: 08 Aug 2012 04:14
- Location: Pahiatua, New Zealand
Re: Get the command currently assigned to a keyboard shortcut
Yes, I know about those options but I don't want a list of all the commands, only certain ones.
Windows 10 Pro 22H2
Scaling 150%
Scaling 150%
-
jupe
- Posts: 3569
- Joined: 20 Oct 2017 21:14
- Location: Win10 22H2 120dpi
Re: Get the command currently assigned to a keyboard shortcut
Well then parse the list.
-
kiwichick
- Posts: 732
- Joined: 08 Aug 2012 04:14
- Location: Pahiatua, New Zealand
Re: Get the command currently assigned to a keyboard shortcut
Thanks, but I don't know how to do that.
Edited to add: I should say I know what parsing a list is but I don't know how I would do it to get the shortcut commands.
Windows 10 Pro 22H2
Scaling 150%
Scaling 150%
-
jupe
- Posts: 3569
- Joined: 20 Oct 2017 21:14
- Location: Win10 22H2 120dpi
Re: Get the command currently assigned to a keyboard shortcut
I misunderstood again, since asking if its possible didn't seem the same as write a script for me, anyway maybe something like this could work:
Code: Select all
$k = "F6|F9|Ctrl+F3|Shift+F12"; text regexmatches(<get listofcommands 2>, "^.+\t(" . replace($k, "+", "\+") . ")$", <crlf>);-
kiwichick
- Posts: 732
- Joined: 08 Aug 2012 04:14
- Location: Pahiatua, New Zealand
Re: Get the command currently assigned to a keyboard shortcut
No, you didn't misunderstand. I wasn't clear about what I needed. Thanks for the code. I can definitely work with that but I was hoping to get a list that's a bit tidier to look at. So, maybe with the keyboard shortcut first and then the command, with no other info included (ie: the menu entries for the commands).
Windows 10 Pro 22H2
Scaling 150%
Scaling 150%
-
highend
- Posts: 15016
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Get the command currently assigned to a keyboard shortcut
Code: Select all
$keys = "F6|F9|Ctrl+F3|Shift+F12";
$matches = regexmatches(<get listofcommands 2>, "^.+\t(" . replace($keys, "+", "\+") . ")$", <crlf>);
$reorder = regexreplace($matches, "^(.*?\t)(.*?)$", "$2<>$1");
text regexreplace($reorder, "^(.*?)<>.*\|[ ]+(.*?)\t+$", "$1 = $2");
One of my scripts helped you out? Please donate via Paypal
-
jupe
- Posts: 3569
- Joined: 20 Oct 2017 21:14
- Location: Win10 22H2 120dpi
Re: Get the command currently assigned to a keyboard shortcut
Alternative below, in case you might want it in a filterable list:
Code: Select all
$keys = "F6|F9|Ctrl+F3|Shift+F12";
$cmds = regexmatches(<get listofcommands 2>, "^.+\s+(" . replace($keys, "+", "\+") . ")$", <crlf>);
inputselect(, regexreplace($cmds, "^.+\|(.+?)\t(.+?)$", "$2<tab 2>$1"), <crlf>, 0);
-
phred
- Posts: 705
- Joined: 26 Dec 2021 02:10
- Location: XY 64bit on Win10 at 100% from Boston USA
Re: Get the command currently assigned to a keyboard shortcut
Both scripts by highend and jupe are helpful. I'm struggling with how to modify either one so that it returns all keyboard shortcuts that are currently assigned.
Thanks.
Thanks.
-
jupe
- Posts: 3569
- Joined: 20 Oct 2017 21:14
- Location: Win10 22H2 120dpi
Re: Get the command currently assigned to a keyboard shortcut
@phred: Below would be one way that should work, output into a filterable list, depending on your requirements you might want the output tidied up more.
edit: Output sanatized version:
Code: Select all
inputselect(, regexreplace(formatlist(<get listofcommands 2>, f, <crlf>, "!*<tab>"), "^.+\|(.+?)\t(.+?)$", "$2<tab 2>$1"), <crlf>, 0);
Code: Select all
$out = "";
$cmds = regexreplace(<get listofcommands 2>, "^.+\t(\r\n|$)");
$cmds = regexreplace($cmds, "^.+\|(.+?)\t(.+?)$", "$2<tab>$1");
foreach($t, $cmds, <crlf>) { $l = strlen(gettoken($t, 1, <tab>)); $max = $l > $max ? $l : $max; }
foreach($l, $cmds, <crlf>) {
$key = gettoken($l, 1, <tab>);
$out .= "$key<pad $max>" . gettoken($l, -1, <tab>) . <crlf>;
}
inputselect(, formatlist($out, "ne", <crlf>), <crlf>, 4096+16384);
-
RalphM
- Posts: 2143
- Joined: 27 Jan 2005 23:38
- Location: Cairns, Australia
Re: Get the command currently assigned to a keyboard shortcut
Great little script, thanks 
Ralph 
(OS: W11 26H2 Home x64 - XY: Current x64 beta - Office 2024 64-bit - Display: 1920x1080 @ 125%)
(OS: W11 26H2 Home x64 - XY: Current x64 beta - Office 2024 64-bit - Display: 1920x1080 @ 125%)
-
phred
- Posts: 705
- Joined: 26 Dec 2021 02:10
- Location: XY 64bit on Win10 at 100% from Boston USA
-
kiwichick
- Posts: 732
- Joined: 08 Aug 2012 04:14
- Location: Pahiatua, New Zealand
Re: Get the command currently assigned to a keyboard shortcut
Thank you!! Is it possible for the output to be listed in the same order as written in $keys? No matter what order I put them in the output is Shift+F12, Ctrl+F3, F9, F6. Also, if I change $keys to F1|F2|F3|F4|F5|F6|F7|F8|F9|F10|F11|F12, why isn't F12 included in the output?highend wrote: ↑01 Oct 2026 11:13Code: Select all
$keys = "F6|F9|Ctrl+F3|Shift+F12"; $matches = regexmatches(<get listofcommands 2>, "^.+\t(" . replace($keys, "+", "\+") . ")$", <crlf>); $reorder = regexreplace($matches, "^(.*?\t)(.*?)$", "$2<>$1"); text regexreplace($reorder, "^(.*?)<>.*\|[ ]+(.*?)\t+$", "$1 = $2");
Windows 10 Pro 22H2
Scaling 150%
Scaling 150%
-
kiwichick
- Posts: 732
- Joined: 08 Aug 2012 04:14
- Location: Pahiatua, New Zealand
Re: Get the command currently assigned to a keyboard shortcut
Thank you!! Is it possible for the output to be listed in the same order as written in $keys? No matter what order I put them in the output is Shift+F12, Ctrl+F3, F9, F6. Also, if I change $keys to F1|F2|F3|F4|F5|F6|F7|F8|F9|F10|F11|F12, why isn't F12 included in the output?jupe wrote: ↑01 Oct 2026 21:33 Alternative below, in case you might want it in a filterable list:Code: Select all
$keys = "F6|F9|Ctrl+F3|Shift+F12"; $cmds = regexmatches(<get listofcommands 2>, "^.+\s+(" . replace($keys, "+", "\+") . ")$", <crlf>); inputselect(, regexreplace($cmds, "^.+\|(.+?)\t(.+?)$", "$2<tab 2>$1"), <crlf>, 0);
Windows 10 Pro 22H2
Scaling 150%
Scaling 150%
XYplorer Beta Club