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



66
67
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
# File 'lib/veewee/provider/core/helper/scancode.rb', line 66

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

  until thestring.length == 0
    nospecial=true;
    @@special_keys.keys.each { |key|
      if thestring.match(/^#{key}/i)
        #take thestring
        #check if it starts with a special key + pop special string
        keycodes=keycodes+@@special_keys[key]+' ';
        thestring=thestring.slice(key.length,thestring.length-key.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