18
19
20
21
22
23
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
|
# File 'lib/dispel/keyboard.rb', line 18
def self.output(options={}, &block)
@sequence = []
@started = Time.now.to_f
timeout = options[:timeout]
if timeout && SEQUENCE_TIMEOUT > timeout
raise "Timeout must be higher then SEQUENCE_TIMEOUT (#{SEQUENCE_TIMEOUT})"
end
loop do
@now = Time.now.to_f
@elapsed = @now - @started
key = fetch_user_input
if @sequence.any? and @elapsed > SEQUENCE_TIMEOUT
sequence_to_keys(@sequence).each(&block)
@sequence = []
end
if key @started = @now
@sequence << key
elsif timeout and @elapsed > timeout
@started = @now
yield :timeout
else
sleep SEQUENCE_TIMEOUT end
end
end
|