Module: WR::ModHotKey

Defined in:
lib/wrb/toplevelcommon.rb

Constant Summary collapse

MOD_ALT =
0x0001
MOD_CONTROL =
0x0002
MOD_SHIFT =
0x0004
MOD_WIN =
0x0008
MOD_NOREPEAT =
0x4000
Modifier =
{"Shift" => MOD_SHIFT, "Ctrl" => MOD_CONTROL, "Alt" => MOD_ALT}

Class Method Summary collapse

Class Method Details

.parse_hotkey(txt, no_repeat = true) ⇒ Object



347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/wrb/toplevelcommon.rb', line 347

def self.parse_hotkey(txt, no_repeat=true)
  return nil if !txt || txt.empty?
  modifier = no_repeat ? MOD_NOREPEAT : 0
  key = nil
  ar = txt.strip.split(/\+/)
  if (str=ar.pop).length > 1
    unless vk=ModKeyAccel::VFuncKey[str]
      raise "Illegal key `#{str}'"
    end
  else
    vk = str.upcase.unpack('c')[0]
  end
  ar.each{|ii|
    raise "Illegal key `#{ii}'" unless n=Modifier[ii]
    modifier |= n 
  }
  [modifier, vk]
end