Class: KeyboardInput
- Inherits:
-
Object
- Object
- KeyboardInput
- Defined in:
- lib/keyboard_input.rb
Overview
does the jruby check inline
Instance Method Summary collapse
- #get_line_printout ⇒ Object
- #getch ⇒ Object
- #handle_keystroke(ch) ⇒ Object
- #handle_keystrokes_forever ⇒ Object
-
#initialize(fella) ⇒ KeyboardInput
constructor
A new instance of KeyboardInput.
- #start_thread ⇒ Object
Constructor Details
#initialize(fella) ⇒ KeyboardInput
Returns a new instance of KeyboardInput.
9 10 11 |
# File 'lib/keyboard_input.rb', line 9 def initialize fella @fella = fella end |
Instance Method Details
#get_line_printout ⇒ Object
20 21 22 23 24 |
# File 'lib/keyboard_input.rb', line 20 def get_line_printout status = @fella.status # scary hard coded values here... " " * 20 + "\b"*150 + status end |
#getch ⇒ Object
26 27 28 29 |
# File 'lib/keyboard_input.rb', line 26 def getch @getch ||= Win32API.new('crtdll', '_getch', [], 'L') @getch.call end |
#handle_keystroke(ch) ⇒ Object
40 41 42 43 |
# File 'lib/keyboard_input.rb', line 40 def handle_keystroke ch string = "" << ch @fella.keyboard_input(string) end |
#handle_keystrokes_forever ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/keyboard_input.rb', line 31 def handle_keystrokes_forever raise 'only jruby supported, as it looks just too messy in normal ruby' unless OS.java? while(ch = getch) return if ch.in? [3, 113] # ctrl+c, q -> exit # lodo handle arrow keys, too, which is a bit more complicated... handle_keystroke ch end end |
#start_thread ⇒ Object
13 14 15 16 17 18 |
# File 'lib/keyboard_input.rb', line 13 def start_thread Thread.new { loop { print get_line_printout sleep 0.1 } } end |