OSDN Git Service

Replaced mongrel with thin
[redminele/redminele.git] / ruby / lib / ruby / gems / 1.8 / gems / eventmachine-0.12.10-x86-mswin32-60 / docs / KEYBOARD
diff --git a/ruby/lib/ruby/gems/1.8/gems/eventmachine-0.12.10-x86-mswin32-60/docs/KEYBOARD b/ruby/lib/ruby/gems/1.8/gems/eventmachine-0.12.10-x86-mswin32-60/docs/KEYBOARD
new file mode 100644 (file)
index 0000000..f1e10e5
--- /dev/null
@@ -0,0 +1,38 @@
+EventMachine (EM) can respond to keyboard events. This gives your event-driven programs the ability to respond to input from local users.\r
+\r
+Programming EM to handle keyboard input in Ruby is simplicity itself. Just use EventMachine#open_keyboard, and supply the name of a Ruby module or class that will receive the input:\r
+\r
+ require 'rubygems'\r
+ require 'eventmachine'\r
\r
+ module MyKeyboardHandler\r
+       def receive_data keystrokes\r
+               puts "I received the following data from the keyboard: #{keystrokes}"\r
+       end\r
+ end\r
\r
+ EM.run {\r
+       EM.open_keyboard(MyKeyboardHandler)\r
+ }\r
+\r
+\r
+If you want EM to send line-buffered keyboard input to your program, just include the LineText2 protocol module in your handler class or module:\r
+\r
+\r
+\r
+ require 'rubygems'\r
+ require 'eventmachine'\r
\r
+ module MyKeyboardHandler\r
+       include EM::Protocols::LineText2\r
+       def receive_line data\r
+               puts "I received the following line from the keyboard: #{data}"\r
+       end\r
+ end\r
\r
+ EM.run {\r
+       EM.open_keyboard(MyKeyboardHandler)\r
+ }\r
+\r
+As we said, simplicity itself. You can call EventMachine#open_keyboard at any time while the EM reactor loop is running. In other words, the method invocation may appear anywhere in an EventMachine#run block, or in any code invoked in the #run block.\r
+\r