Skip to content

Instantly share code, notes, and snippets.

@careo
Created March 7, 2009 06:52
Show Gist options
  • Select an option

  • Save careo/75255 to your computer and use it in GitHub Desktop.

Select an option

Save careo/75255 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'eventmachine'
module Dtach
def post_init
puts "starting"
end
def receive_data data
puts "received: #{data}"
end
def unbind
puts "unbound"
p get_status.inspect
#puts "unbound with exit status: #{get_status.exitstatus}"
#puts "get_status.inspect: #{get_status.inspect}"
#EM.stop
end
end
#module MyKeyboardHandler
# def receive_data keystrokes
# puts "I received the following data from the keyboard: #{keystrokes}"
# end
#end
#
EM.run {
dtach = EM.connect_unix_domain("#{File.dirname(__FILE__)}/thing.dtach",Dtach) { |t|
# magic thing I copied and pasted from a dummy dtach server
t.send_data "\001\000L\366\377\277D\366\377\277\004\000\030\000P\0000\002\230\001"
}
#kb = EM.open_keyboard(MyKeyboardHandler)
EM.add_timer(5) {
EM.stop
}
}
require 'rubygems'
require 'eventmachine'
module MyKeyboardHandler
def receive_data keystrokes
puts "I received the following data from the keyboard: #{keystrokes.inspect}"
end
end
EM.run {
EM.open_keyboard(MyKeyboardHandler)
}
# I type:
# ad\n
#output:
# I received the following data from the keyboard: "a"
# I received the following data from the keyboard: "d"
# I received the following data from the keyboard: "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment