Class: Veewee::Provider::Core::Helper::Scancode

Inherits:
Object
  • Object
show all
Defined in:
lib/veewee/provider/core/helper/scancode.rb

Constant Summary collapse

@@keys =

keycode hash, seeded with 'Tab' - which is special as it's longer than 1 char

{ 'Tab' => '0f 8f' }
@@special_keys =
Hash.new

Class Method Summary collapse

Class Method Details

.string_to_keycode(thestring) ⇒ Object

the us keymap is used


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/veewee/provider/core/helper/scancode.rb', line 68

def self.string_to_keycode(thestring)
  keycodes=''
  thestring.gsub!(/ /,"<Spacebar>")

  until thestring.length == 0
    nospecial=true;
    @@special_keys.each { |key, value|
      if
        result = thestring.match(/^#{key}/i)
      then
        #take thestring
        #check if it starts with a special key + pop special string
        keycodes += value + result.captures.join(",") + ' '
        thestring = thestring.slice(result.to_s.length, thestring.length-result.to_s.length)
        nospecial = false;
        break;
      end
    }
    if nospecial
      code=@@keys[thestring.slice(0,1)]
      if !code.nil?
        keycodes=keycodes+code+' '
      else
        ui.error "no scan code for #{thestring.slice(0,1)}"
      end
      #pop one
      thestring=thestring.slice(1,thestring.length-1)
    end
  end

  return keycodes
end