Created
March 7, 2009 06:52
-
-
Save careo/75255 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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