Go to: Synopsis. Return value. Flags. Python examples.

Synopsis

hotkey([altModifier=boolean], [autoSave=boolean], [commandModifier=boolean], [ctrlModifier=boolean], [factorySettings=boolean], [isModifier=boolean], [keyShortcut=string], [name=string], [pressCommandRepeat=boolean], [releaseCommandRepeat=boolean], [releaseName=string], [sourceUserHotkeys=boolean])

Note: Strings representing object names and arguments must be separated by commas. This is not depicted in the synopsis.

hotkey is undoable, queryable, and NOT editable.

This command sets the single-key hotkeys for the entire application.

Return value

None

In query mode, return type is based on queried flag.

Flags

altModifier, autoSave, commandModifier, ctrlModifier, factorySettings, isModifier, keyShortcut, name, pressCommandRepeat, releaseCommandRepeat, releaseName, sourceUserHotkeys
Long name (short name) Argument types Properties
altModifier(alt) boolean createquery
ctrlModifier(ctl) boolean createquery
The Ctrl key must be pressed to get the hotkey. Note that if menu item accelerator keys are being used (menuItem -ke/keyEquivalent), then the accelerator key settings override the hotkey settings.
commandModifier(cmd) boolean create
The Command key must be pressed to get the hotkey. This is only available on systems which have a separate command key. Note that if menu item accelerator keys are being used (menuItem -ke/keyEquivalent), then the accelerator key settings override the hotkey settings.
isModifier(mod) boolean create
The hotkey is a modifier itself.
keyShortcut(k) string create
Specify what key is being set. The key must be either a single ascii character (capital and lowercase can be set independently) or one of the keyword strings for the special keyboard characters. The valid keywords are:
Up, Down, Right, Left,
Home, End, Page_Up, Page_Down, Insert
Return, Space
F1 to F12
name(n) string createquery
The name of the namedCommand object that will be executed when the key is pressed.
releaseName(rn) string createquery
The name of the namedCommand object that will be executed when the key is released.
autoSave(autoSave) boolean create
If set to true then the hotkeys will always be saved when you quit. If false then the hotkeys are not saved unless "savePrefs -hotkeys" is used.
factorySettings(fs) boolean create
Resets the hotkeys back to the initial defaults.
sourceUserHotkeys(suh) boolean create
This command reads the userHotkey file
pressCommandRepeat(pcr) boolean create
Specify true and the command may be repeated by executing the command repeatLast. This flag is false by default.
releaseCommandRepeat(rcr) boolean create
Specify true and the command may be repeated by executing the command repeatLast. This flag is false by default.

Flag can appear in Create mode of command Flag can appear in Edit mode of command
Flag can appear in Query mode of command Flag can have multiple arguments, passed either as a tuple or a list.

Python examples

import maya.cmds as cmds

# Here's an example of how to create a namedCommand
# object and then map it to a key.
#
cmds.nameCommand( 'circleToolNamedCommand', annotation='Select Circle Tool', command='setToolTo circleContext')
cmds.hotkey( k='F5', alt=True, name='circleToolNamedCommand' )


# Here are more examples of how to use the hotkey command.
#
cmds.hotkey( k='d', name='Delete_Command' )
cmds.hotkey( k='d', name='' ) # unsets the above command

cmds.hotkey( k='d', name='Delete_Command' )
cmds.hotkey( k='d', releaseName='After_Delete_Command' )
cmds.hotkey( k='d', name='' ) #only unsets the key press name
cmds.hotkey( k='d', releaseName='' ) #only unsets the key release name
cmds.hotkey( k='d', n='', rn='' ) #unsets both the key press and release name

#    Determine if a command is attached to either the press or release
#    of the "z" hotkey.
#
cmds.hotkey( 'z', query=True )

#    Likewise, for the modified variations of the "z" key.
#
cmds.hotkey( 'z', query=True, alt=True )
cmds.hotkey( 'z', query=True, ctl=True )
cmds.hotkey( 'z', query=True, alt=True, ctl=True )

#    Determine the press command attached to the "z" key.
#
cmds.hotkey( 'z', query=True, name=True )

#    To query the "-" hotkey use the string "Dash" instead.
#
cmds.hotkey( 'Dash', query=True )