[Example] Send Escape Key - Cancel Operation script
This example adds a “Cancel Operation” menu item to the Edit menu.
Once this is added a user can assign any shortcut they wish to:
- cancel an operation
- reset a tool to it’s initial state
- exit the current editing context
So for example, once loaded the user can set the HOME key to this menu command by opening …
Window > Preferences > Shortcuts
… then scroll down to Edit/Cancel Operation
and select it …
… the click in the Add Shortcut box …
… and type the key chord you want to fire the menu command …
… then click the + button
… then click OK button.
Example_SendEscapeKey.rb (1.1 KB)
# encoding: UTF-8
#
module Example
module SendEscape
extend self
MENU_TEXT = Hash[
'en-us', 'Cancel Operation',
'es', 'Cancelar Operación',
'fr', "Annuler l'Opération",
'it', 'Annulla Operazione',
'ja', '操作をキャンセル',
'ko', '작업 취소',
'de', 'Vorgang Abbrechen',
'nl', 'Bewerking Annuleren',
'no', 'Avbryt Driften',
'pl', 'Anuluj Operację',
'pt-br', 'Cancelar Operação',
'ru', 'Отмена операции',
'sv', 'Avbryt Funktionen',
'zh-cn', '取消操作',
'zh-tw', '取消操作'
].fetch(Sketchup.get_locale.downcase,'Cancel Operation')
WIN = Sketchup::platform == :platform_win
if WIN
require 'win32ole'
SHELL ||= WIN32OLE::new('WScript.Shell')
def send_escape()
SHELL.SendKeys('{ESC}')
end
else # MacOS
def send_escape()
Sketchup::send_action('cancelOperation:')
end
end
if !@loaded
UI.menu('Edit').add_item(MENU_TEXT) { send_escape() }
@loaded = true
end
end # SendEscape
end # toplevel module