module Veewee module Provider module Core module Helper class Scancode #http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html # keycode hash, seeded with 'Tab' - which is special as it's longer than 1 char @@keys = { 'Tab' => '0f 8f' } # add keycodes # "pure" keys (no modifier keys) { '1234567890-=' => 0x02, 'qwertyuiop[]' => 0x10, 'asdfghjkl;\'`' => 0x1e, '\\zxcvbnm,./' => 0x2b }.each do |keys, offset| keys.split('').each_with_index do |key, idx| @@keys[key] = sprintf('%02x %02x', idx + offset, idx + offset + 0x80) end end # upcase keys (with shift) { '!@#$%^&*()_+' => 0x02, 'QWERTYUIOP{}' => 0x10, 'ASDFGHJKL:"~' => 0x1e, '|ZXCVBNM<>?' => 0x2b }.each do |keys, offset| keys.split('').each_with_index do |key, idx| @@keys[key] = sprintf('2a %02x aa %02x', idx + offset, idx + offset + 0x80) end end @@special_keys=Hash.new; @@special_keys[''] = '1c 9c'; @@special_keys[''] = '0e 8e'; @@special_keys[''] = '39 b9'; @@special_keys[''] = '1c 9c' @@special_keys[''] = '01 81'; @@special_keys[''] = '0f 8f'; @@special_keys[''] = '1d 38 0e b8'; @@special_keys[''] = 'wait'; @@special_keys[''] = '48 c8'; @@special_keys[''] = '50 d0'; @@special_keys[''] = '49 c9'; @@special_keys[''] = '51 d1'; @@special_keys[''] = '4f cf'; @@special_keys[''] = '52 d2'; @@special_keys[''] = '53 d3'; @@special_keys[''] = '4b cb'; @@special_keys[''] = '4d cd'; @@special_keys[''] = '47 c7'; # F1 .. F10 (1..10).each { |num| @@special_keys[""] = sprintf('%02x', num + 0x3a) } # VT1 - VT12 (Switch to Virtual Terminal #. e.g Alt+F1) (1..12).each { |num| @@special_keys[""] = sprintf('38 %02x b8 %02x', num + 0x3a, num + 0xba) } # the us keymap is used def self.string_to_keycode(thestring) keycodes='' thestring.gsub!(/ /,"") 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 end #Class end #Module end #Module end #Module end #Module