WoW:API SetBinding
Binds a key or button press to a command. Unbinds the key or button if the command argument is nil.
There does not appear to be a limit to the number of keys you can bind to a command. The GUI key binding window will only show you the first two. But if you set 5 different keys to the same command, they will all work.
A single key can only be bound to one command. Binding a key to a command that is already bound to another command will result in un-binding the key from the previous command.
If the function succeeds, the keys are usable immediately in game and will appear in the GUI key bindings window. However, they are not written to disk unless SaveBindings() is called. SaveBindings() is not called as part of the normal Logout procedure, so you either have to call it manually or open the GUI key binding window and click Okay.
- Arguments
- (String key, String command)
- key
- (string) Key name of the key to bind (e.g. W, CTRL-F, BUTTON2). As of 1.6 there is now error checking on this value so random strings for key names won't work anymore.
- command
- (string) Command name to execute when the key is pressed (e.g. MOVEFORWARD, TOGGLECHARACTER0). This argument is optional. If not included, the function will un-bind the key argument. Also, using an invalid command will also un-bind the key specified.
- Example
-- Set the default behavior for the right mouse button SetBinding("BUTTON2","TURNORACTION"); -- Set the W key to move forward SetBinding("W", "MOVEFORWARD"); -- Unset the key combination Ctrl+F SetBinding("CTRL-F");
- Returns
- success
- 1 if the binding succeeded. nil if it failed or the key was unbound.