Class: Twiddler::Config::KeyChord

Inherits:
Chord
  • Object
show all
Defined in:
lib/twiddler/config.rb

Constant Summary collapse

ModKeys =
%w{RGui RAlt RSft RCtl LGui LAlt LSft LCtl}

Instance Attribute Summary collapse

Attributes inherited from Chord

#mods, #rows

Instance Method Summary collapse

Methods inherited from Chord

#extract_key, #keydata=, #render, #render_keys

Constructor Details

#initializeKeyChord

Returns a new instance of KeyChord.



277
278
279
280
# File 'lib/twiddler/config.rb', line 277

def initialize
  super
  @keystrokes = []
end

Instance Attribute Details

#keystrokesObject (readonly)

Returns the value of attribute keystrokes.



282
283
284
# File 'lib/twiddler/config.rb', line 282

def keystrokes
  @keystrokes
end

Instance Method Details

#[](idx) ⇒ Object



284
285
286
# File 'lib/twiddler/config.rb', line 284

def [](idx)
  @keystrokes[idx]
end

#add_keystroke(mod_bits, idx) ⇒ Object



292
293
294
295
# File 'lib/twiddler/config.rb', line 292

def add_keystroke(mod_bits, idx)
  mods = ModKeys.zip(mod_bits.split('')).delete_if{|mod,bit| bit != "1"}.map{|mod,bit| mod}
  @keystrokes << [idx, mods]
end

#keytableObject



297
298
299
# File 'lib/twiddler/config.rb', line 297

def keytable
  Config.keytable
end

#render_actionObject



301
302
303
304
305
306
307
308
# File 'lib/twiddler/config.rb', line 301

def render_action
  output = []
  (@keystrokes || []).each do |code, mods|
    output << keytable[code, mods]
  end

  return output.join()
end

#single?Boolean

Returns:

  • (Boolean)


288
289
290
# File 'lib/twiddler/config.rb', line 288

def single?
  @keystrokes.length == 1
end