Accelerator tricks

Posted by Larkin on Mon 31 Jan 2011 08:12 PM — 3 posts, 20,196 views.

#0
I'm trying to set up my keypad to change commands based on certain things, and then I want to delete the accelerators or revert them to what they were before. This seems especially tricky, so I'm wondering if I'm missing something here. Keep in mind that this script will be used by others, and I want to keep it general enough to play nice with whatever accelerators they have configured.

1. I have my keypad configured in the Configuration -> Input -> Keypad, but those are not real accelerators. They don't show in AcceleratorList, so I don't know how to grab the commands and save them to be restored later.

2. There seems to be no way to delete an accelerator, such as setting it to nil, and when I use an empty string, it doesn't do anything, though the documentation says it will revert to what it was previously (how does it know?).

3. I have to loop on all the accelerators to get the value for any one macro? Why no lookup table functionality?

I know I can hardcode the keypad accelerators to what I want, but I'm trying to be efficient and user friendly, so any advice?

Thanks.
Australia Forum Administrator #1
  1. You can find current keypad values with ExportXML. The names to enter to this function will be the ones which appear in the world file XML. Also see table "strKeypadNames" in prefspropertypages.cpp as described below.
  2. Doing what the documentation says removes the "special" accelerator, returning the function of that key to what it originally did. So the simple case would be just to use AcceleratorList to find what ones you added, and just set those ones back to an empty string. If you think this doesn't work can you produce a test case?
  3. The macros are predefined (see the world file). The list will never infrequently change. The actual names are in the source here:

    https://github.com/nickgammon/mushclient/blob/master/dialogs/world_prefs/prefspropertypages.cpp

    Currently around line 1929, or search for "strMacroDescriptions".

USA #2
Larkin said:
1. I have my keypad configured in the Configuration -> Input -> Keypad, but those are not real accelerators. They don't show in AcceleratorList, so I don't know how to grab the commands and save them to be restored later.

I believe you can use ExportXML(5, "") to get the keypad settings as XML. Then if you're using Lua you can use utils.xmlread() to turn it into a nested Lua table. It should be reasonably easy to turn that back into XML and pass it to ImportXML().

Larkin said:
2. There seems to be no way to delete an accelerator, such as setting it to nil, and when I use an empty string, it doesn't do anything, though the documentation says it will revert to what it was previously (how does it know?).

"what it was previously" likely refers to the keybinding's default, if any. For example, Ctrl+C's default is to copy, and Ctrl+S saves the world.