# Include the gem library require 'net/vnc' # Monkey patch the vnc require 'net/vnc/vnc.rb' module Veewee module Provider module Core module BoxCommand def vnc_type(sequence,host,display=20) counter=0 env.logger.info "Opening VNC #{host} on display #{display}" vnc=Net::VNC.open("#{host}:#{display}",{:wait => 0.001}) sequence.each { |s| counter=counter+1 env.ui.info "Typing:[#{counter}]: "+s keycodes=string_to_vnccode(s) keycodes.each do |keycode| if keycode==:wait sleep 1 else send_vnc_keycode(vnc,keycode) end end } vnc.close env.ui.info "Done typing." env.ui.info "" end def send_vnc_keycode(vnc,keycode) if keycode.is_a?(Symbol) vnc.key_press keycode sleep 1 else vnc.type_string keycode,{:wait => 0.1} end end def string_to_vnccode(thestring) # http://code.google.com/p/ruby-vnc/source/browse/trunk/data/keys.yaml special=Hash.new # Specific veewee special[''] = :wait # VNC Codes special[''] = :return special[''] = :return special[''] = :escape # These still need some work! special[''] = :backspace special[''] = ' ' special[''] = :tab # Hmm, what would the equivalent be here special[''] = '1d 38 0e'; special[''] = :up special[''] = :down special[''] = :page_up special[''] = :page_down special[''] = :end special[''] = :insert special[''] = :delete special[''] = :left special[''] = :right special[''] = :home special[''] = :f1 special[''] = :f2 special[''] = :f3 special[''] = :f4 special[''] = :f5 special[''] = :f6 special[''] = :f7 special[''] = :f8 special[''] = :f9 special[''] = :f10 keycodes=Array.new thestring.gsub!(/ /,"") until thestring.length == 0 nospecial=true; special.keys.each { |key| if thestring.start_with?(key) #take thestring #check if it starts with a special key + pop special string keycodes<