Here is an example for using an ALT toggle instead of a ALT holddown …
class ToolTest
if Sketchup.platform == :platform_win
WIN = true
require 'win32ole'
else
WIN = false
end
NORM_MODE ||= 'Do something ... | Click ALT for nifty mode'
ALT_MODE ||= 'Do something ... | Click ALT for normal mode'
def self.use
Sketchup.focus if Sketchup.respond_to?(:focus)
Sketchup.active_model.select_tool(self.new)
end
def initialize(*args)
@alt_mode = false
@shell = WIN32OLE.new('WScript.Shell') if WIN
end
def activate
set_status_text()
Sketchup.active_model.active_view.invalidate
end
def onCancel(reason, view)
# Gets called before onKeyUp when ESC key is pressed.
# Gets called after onKeyDown if it does not return true.
puts "\n#{self.class}: onCancel was called."
end
def onKeyUp(key, repeat, flags, view)
result = false
case key
when ALT_MODIFIER_KEY
puts "\n#{self.class}: ALT was pressed and released"
# Toggle alternative mode:
@alt_mode = !@alt_mode
set_status_text()
# Send an ESC key to SketchUp on Windows platform. This will
# clear the menu selection, and onCancel will NOT fire.
@shell.SendKeys('{ESC}') if WIN
result = true # to prevent SketchUp from processing the event
when 9
puts "\n#{self.class}: TAB key clicked"
# do something else ...
else
# whatever ...
puts "\n#{self.class}: onKeyUp: key = #{key}"
end
puts " flags = %B" % flags
return result
end
def set_status_text
Sketchup.status_text=( @alt_mode ? ALT_MODE : NORM_MODE )
end
end
P.S. - I’m not sure why the Windows Scripting Host SendKeys method also sends a É (144) character after the ESC. But it should be ignored (if you don’t write a when clause for it.)
The Tab key is obviously problematic. I’m going to test out some of this code with the Alt key and see what I can do with it.
P.S.
Adding the single line “return true” seems to fix the problem with the Alt key pausing SketchUp. It looks like the Alt key will now be my new secondary hotkey goto when I’ve already commandeered the Control key.
Thank-you Dezmo on this very simple hint but solution. I just need to have my Mac users test it for me to verify that it works as intended on MacOS.
I did not notice any difference myself with return value.
I found that if the ESC key is not sent (to clear the menu focus,) then the status bar is not updated and is actually wiped blank.