Class: TDriver::KeymapUtilities
- Defined in:
- lib/tdriver/util/keymap/keymap.rb
Class Method Summary collapse
Class Method Details
.fetch_keycode(keycode, keymap_hash) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/tdriver/util/keymap/keymap.rb', line 24 def self.fetch_keycode( keycode, keymap_hash ) # retrieve default keymap name from hash keymap = keymap_hash[ :default_keymap ] # convert symbol to string representation for further processing keycode_string = keycode.to_s # collect all loaded keymaps, exclude :default_keymap key from hash keymaps = keymap_hash.keys.select{ | item | ![ :default_keymap, :all ].include?( item ) } begin # check if environment defined in keycode, e.g. :qt_kDown if keycode_string.include?( '_' ) if /(#{ keymaps.collect{ | env | "#{ env.to_s }_" }.join('|') })(.+)/i.match( keycode_string ) # set new keymap value and convert to symbol, e.g. :qt from :qt_kDown keymap = $1.chop.to_sym # set correct keycode value and convert to symbol, e.g. :kDown from :qt_kDown keycode = $2.to_sym end # retrieve symbol from keymap keymap_hash[ keymap ][ keycode ] else begin # try to retrieve from default keymap; raises exception if key not found keymap_hash[ keymap ][ keycode ] rescue # if we didn't find the key, let's try finding from mixed keymap; mixed keymap has all loaded keycodes # keycodes are merged to existing hash when loading new keymap on top # raises exception if key not found keymap_hash[ :all ][ keycode ] end end rescue raise ArgumentError, "Scan code for #{ keycode.inspect } not defined in #{ keymap } keymap" end end |