I use EventMachine LineText2 protocol and I would like to fire receive_line
method everytime I press a character on my keyboard and not just when I enter a new line. Is there a way to change that default behaviour?
class KeyboardHandler < EM::Connection
include EM::Protocols::LineText2
def initialize(q)
@queue = q
end
def receive_line(data)
@queue.push(data)
end
end
EM.run {
q = EM::Queue.new
callback = Proc.new do |line|
# puts on every keypress not on "\n"
puts line
q.pop(&callback)
end
q.pop(&callback)
EM.open_keyboard(KeyboardHandler, q)
}