# File AgileGuiTesting.rb, line 201
def type (data)
  
  old_auto_delay = @robot.getAutoDelay
  @robot.setAutoDelay(0)
  
  data.strip!
  data.chomp!
  # puts "TYPE: #{data}"

  count = 0
  while count < data.length

    # this gets the character (a,b,c, etc.)

    the_char = data[count,1]
    
    # this very similar call returns the ascii value

    i = data[count]

    # handle the character backslash (ascii 92) sequences

    # (like \n, \t, etc.)

    if i == 92
      # get next char

      # f=102(\f=12), n=110(10), r=114(13), t=116(9)

      c = data[count+1]
      
      # TODO - refactor all these keyPress/keyRelease sequences

      # send corresponding escape sequence

      if c == 102
        @robot.keyPress(12)
        wait(15)
        @robot.keyRelease(12)
      elsif c == 110
        @robot.keyPress(10)
        wait(15)
        @robot.keyRelease(10)
      elsif c == 114
        @robot.keyPress(13)
        wait(15)
        @robot.keyRelease(13)
      elsif c == 116
        @robot.keyPress(9)
        wait(15)
        @robot.keyRelease(9)
        
      # TODO: temporary kludge

      # make \b == backspace

      elsif c == 98
        @robot.keyPress(KeyEvent::VK_BACK_SPACE)
        wait(15)
        @robot.keyRelease(KeyEvent::VK_BACK_SPACE)
      elsif c == 100
        @robot.keyPress(KeyEvent::VK_DELETE)
        wait(15)
        @robot.keyRelease(KeyEvent::VK_DELETE)
      end
      # count as two chars

      count += 2
    else
      
      # come here for "regular" keystrokes (no backslashes)

      
      # handle the "shift" key characters first

      if @shift_key_hash.has_key?(the_char)
        #puts "\nDEBUG: Got an #{a} character (#{i})"

        key_to_press = @shift_key_hash[the_char]
        keycode = key_to_press[0]
        #keycode = c.to_i

        # call our special method to type these characters

        shift_type_keycode(keycode)
      
      # need to subtract 32 b/c java takes only the 26 cap

      # char's. need to add 'shift' to really get caps tho.

      elsif i > 31 && i < 65
        # keyboard chars (32-64); by handling the shift key

        # characters first, i should just be able to type whatever

        # comes here

        type_keycode(i)
      elsif i > 64 && i < 91
        # uppercase characters (65-90)

        shift_type_keycode(i)
        #@robot.keyPress(KeyEvent::VK_SHIFT)

        #wait(10)

        #@robot.keyPress(i)

        #wait(20)

        #@robot.keyRelease(i)

        #wait(10)

        #@robot.keyRelease(KeyEvent::VK_SHIFT)

        #wait(10)

      elsif i > 90 && i < 97
        # more keyboard chars (91-96)

        type_keycode(i)
      elsif i > 122 && i < 127
        # more keyboard chars (123-126)

        type_keycode(i)
      else
        # lowercase characters

        # java really only handles uppercase characters, so convert lowercase

        # values to uppercase here

        i = i - 32 if i > 96 && i < 123
        type_keycode(i)
        #@robot.keyPress(i)

        #wait(20)

        #@robot.keyRelease(i)

      end
      count += 1
    end
    # sleep between char entries

    # (don't forget, now have autoDelay, so this can possibly go away)

    sleep 0.1
  end

  # return to the previous auto_delay

  @robot.setAutoDelay(old_auto_delay)
  
end