Module: MouseInput::Mouse
- Defined in:
- lib/mouse_input/input.rb
Overview
Mouse reader and parser
Class Method Summary collapse
-
.parse_input(char) ⇒ Array(x,y)
reads whole input sequence and returns the coords X and Y.
-
.read_input ⇒ Array(x,y)
listen input from mouse returns the coords X and Y.
Class Method Details
.parse_input(char) ⇒ Array(x,y)
reads whole input sequence and returns the coords X and Y
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mouse_input/input.rb', line 20 def self.parse_input(char) sequence = char + $stdin.read(17) # storing anything left out here sequence += $stdin.getc while $stdin.ready? input = sequence.split(";") x = input[1].to_i # for y the to_i will only take the first number from e.g "34M[0;12;0" # ignoring everything after the first non Integer y = input[2].to_i [x, y] end |
.read_input ⇒ Array(x,y)
listen input from mouse returns the coords X and Y
10 11 12 13 14 15 |
# File 'lib/mouse_input/input.rb', line 10 def self.read_input while (char = $stdin.getc) break if char == "\e" end parse_input(char) end |