[Example] Send Escape Key - Cancel Operation script

[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()
    else # MacOS
      def send_escape()

    if !@loaded
      UI.menu('Edit').add_item(MENU_TEXT) { send_escape() }
      @loaded = true

  end # SendEscape
end # toplevel module


Wow, it look like perfect : )

I tried to install it as Extension. but I failed…
File name extension should be “rbz” ? but … not work…
How to import the script ? Is it extension ?

Thank you ,DanRathbun .
it must be good !

It is just a .rb script (for now.)
You can send it to a ZIP file, then rename the .zip to .rbz, and then it’ll install for you.

It’s perfect !!

Thank you, I can enjoy your script forever : )

1 Like