I was thinking about this for a long time and I think I have fiddled out, how to make setting shortcuts programmeable.
For that there are already a number of functions present in the C++-API:
DeleteActionShortcut
GetActionShortcutDesc
DoActionShortcutDialog
CountActionShortcuts
which can be used in conjunction with StuffMIDIMessage to set new shortcuts.
Means: I use DoActionShortcutDialog, sent the keyboard/midi-shortcut via StuffMIDIMessage and click the OK-button.
But there is one last function missing: a function that returns the code of actually set shortcuts.
In the kb.ini, shortcuts are represented using two numbers in the KEY-entries. The same goes, when I sent a shortcut via StuffMIDIMessage, where the first two bytes signal the actual shortcut.
Now, if I want to set shortcuts, I would love to know, if a certain shortcut is already set.
Especially if I want to delete the old binding of a shortcut before setting it to a new action to avoid the "shortcut already set"-dialog.
I could try to make this with GetActionShortcutDesc, but I fear, that the description returns the shortcut localized, means: german keymap -> german description.
So what I need is something, that is more "internationalized".
And these are actually the two numbers in the KEY-entries as well as the first two bytes in StuffMIDIMessage.
So: I would like to propose a function, that returns the kb.ini-KEY-numbers as well as the StuffMIDIMessage-bytes associated with the shortcut.
Code:
integer kbini_1, integer kbini_2, integer smidim_1, integer smidim_2 = reaper.GetShortcutCode(integer commandid, integer shortcut_idx)
The first ones return the two kb.ini-related KEY-numbers, while the second two the two integer that could be used for StuffMIDIMessage. (I found in my research, that the numbers in the KEY-entries seem to differ from their StuffMIDIMessage-counterparts, that's why I think both are needed...)
In addition to that, it would be nice to have a function for enumerating all existing shortcuts for their codes:
Code:
string shortcut_desc = reaper.EnumShortcutCode_KBini(integer code1, integer code2)
string shortcut_desc = reaper.EnumShortcutCode_StuffMIDIMEssage(integer code1, integer code2)
and for reverse-lookup, to which action a certain shortcut-code is already associated(without the need of parsing the kb.ini for that)
Code:
integer command_id, integer shortcut_idx = reaper.ReverseLookupShortcutCode(integer code1, integer code2)
The reason I'm asking it for is, that it would allow having things like switchable keyboard-layouts for different usecases.
So I could have a script, that displays the keymap to the user and by clicking on a key, you can bind an action selected in the actionlist(the actionlist does it the other way round).
And if you store multiple of them, you could switch between them via script, which is a feature that had been asked numerous times in the past.
The EnumShortcutCode-functions would also allow to localize the keyboard-names. So in english keymaps, it would return "Ctrl", while on german keymaps, it would return "Strg".
So displaying localised keynames in such a keymap-script would be easy to do.
This would be a huge leap forward in terms of workflow-management for many users, if we could write something like that(no matter if it's as script or maybe even in SWS).