Livecode Wiki

Sent when a Command key combination (Control-key on Linux or Windows) is pressed. If there is a message handler by the same name in the message path, then it will be executed.



commandKeyDown <keyName>

The parameter "keyName" is the actual character of the pressed key.

The commandKeyDown message is sent to the active (focused) control, or to the current card if no control is focused.

If the Command key is pressed along with the Return, Tab, Backspace, Delete, or Enter key, with an arrow key, or with a function key, no commandKeyDown message is sent. Instead, the returnKey, tabKey, backspaceKey, deleteKey, enterKey, arrowKey or functionKey message is sent.

On Mac OS systems, the commandKeyDown message is sent when the user presses a key while holding down the Command key. On Unix or Windows systems, the commandKeyDown message]is sent when the user presses the Control key, whether or not another key is pressed at the same time.

Message handler[]


on commandKeyDown theKey                                  -- make Command-5 go back
  if theKey is "5" then go recent card else pass commandKeyDown
end commandKeyDown

on commandKeyDown theKey
  switch theKey
    case "s"
    case "f"
    end switch
  pass commandKeyDown
end commandKeyDown

Use the commandKeyDown Message handler if you want to provide Command-key or Control-key shortcuts (other than those provided in menus and button accelerators).

Remember to Pass otherwise other combinations will be not available (as Ctrl+A to select all text).

To trap a combination such as Command-Return or Control-Return, use a returnKey handler and check the commandKey function inside the handler.

See also: controlKey, menus, functionKey, enterKey, arrowKey, deleteKey, tabKey, backspaceKey, controlKeyDown, optionKeyDown, returnKey & button