Class: Keyboard

Inherits:
Object show all
Defined in:
lib/ruco/keyboard.rb

Constant Summary collapse

ENTER =
13
IS_18 =
RUBY_VERSION =~ /^1\.8/
SEQUENCE_TIMEOUT =
0.01
NOTHING =

getch returns this as ‘nothing’ on 1.8 but nil on 1.9.2

4294967295
A_TO_Z =
('a'..'z').to_a

Class Method Summary collapse

Class Method Details

.input(&block) ⇒ Object



10
11
12
# File 'lib/ruco/keyboard.rb', line 10

def self.input(&block)
  @input = block
end

.outputObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ruco/keyboard.rb', line 14

def self.output
  @sequence = nil
  @started = Time.now.to_f

  loop do
    key = fetch_user_input
    if sequence_finished?
      if needs_paste_fix?(@sequence)
        yield bytes_to_string(@sequence)
      else
        bytes_to_key_codes(@sequence).each{|c| yield c }
      end
      @sequence = nil
    end
    next if key == NOTHING
    start_or_append_sequence key
  end
end