Class: Rkremap::Evdev
- Inherits:
-
Object
- Object
- Rkremap::Evdev
- Defined in:
- lib/rkremap/evdev.rb
Overview
Constant Summary collapse
- EVIOCGBIT_ANY =
EVIOCGBIT(0, 1)
2147566880- EVIOCGBIT_EV_KEY =
EVIOCGBIT(EV_KEY, (KEY_CNT-1)/8+1)
2153792801- EVIOCGRAB =
1074021776- EVIOCGNAME =
EVIOCGNAME(256)
2164278534
Instance Attribute Summary collapse
- #path ⇒ String readonly
Instance Method Summary collapse
- #capable?(key) ⇒ Boolean
- #close ⇒ Object
- #eql?(other) ⇒ Boolean
- #grab ⇒ Object
- #grab? ⇒ Boolean
-
#initialize(path) ⇒ Evdev
constructor
A new instance of Evdev.
- #inspect ⇒ Object
- #io ⇒ IO
- #keyboard? ⇒ Boolean
- #match?(pattern) ⇒ Boolean
- #mouse? ⇒ Boolean
- #name ⇒ String
-
#read_event ⇒ Rkremap::Event
struct input_event { struct timeval time; unsigned short type; unsigned short code; unsigned int value; };.
Constructor Details
#initialize(path) ⇒ Evdev
Returns a new instance of Evdev.
13 14 15 16 17 18 19 20 |
# File 'lib/rkremap/evdev.rb', line 13 def initialize(path) @path = path @io = nil @capa = nil @uinput = nil @grab = false io end |
Instance Attribute Details
#path ⇒ String (readonly)
10 11 12 |
# File 'lib/rkremap/evdev.rb', line 10 def path @path end |
Instance Method Details
#capable?(key) ⇒ Boolean
50 51 52 53 54 55 56 57 |
# File 'lib/rkremap/evdev.rb', line 50 def capable?(key) unless @capa buf = ' ' * ((KeyCode::KEY_MAX-1)/8+1) io.ioctl(EVIOCGBIT_EV_KEY, buf) @capa = buf.unpack('C*') end @capa[key/8][key%8] != 0 end |
#close ⇒ Object
44 45 46 |
# File 'lib/rkremap/evdev.rb', line 44 def close @io&.close end |
#eql?(other) ⇒ Boolean
26 27 28 |
# File 'lib/rkremap/evdev.rb', line 26 def eql?(other) other.is_a?(Evdev) && self.path == other.path end |
#grab ⇒ Object
84 85 86 87 |
# File 'lib/rkremap/evdev.rb', line 84 def grab io.ioctl(EVIOCGRAB, 1) @grab = true end |
#grab? ⇒ Boolean
90 91 92 |
# File 'lib/rkremap/evdev.rb', line 90 def grab? @grab end |
#inspect ⇒ Object
22 23 24 |
# File 'lib/rkremap/evdev.rb', line 22 def inspect "#<Rkremap::Evdev: #{name} (#{path})>" end |
#io ⇒ IO
31 32 33 34 |
# File 'lib/rkremap/evdev.rb', line 31 def io return @io if @io @io = File.open(@path) end |
#keyboard? ⇒ Boolean
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rkremap/evdev.rb', line 60 def keyboard? return @is_keyboard unless @is_keyboard.nil? @is_keyboard = false return false if name =~ /\Arkremap\0*\z/ buf = +'' io.ioctl(EVIOCGBIT_ANY, buf) return false if buf.unpack1('C')[EV_KEY] == 0 @is_keyboard = capable?(KeyCode::KEY_0) && capable?(KeyCode::KEY_9) && capable?(KeyCode::KEY_A) && capable?(KeyCode::KEY_Z) && capable?(KeyCode::KEY_SPACE) end |
#match?(pattern) ⇒ Boolean
109 110 111 112 113 114 115 |
# File 'lib/rkremap/evdev.rb', line 109 def match?(pattern) return true if pattern == true return true if pattern == :keyboard && keyboard? return true if pattern == :mouse && mouse? return true if pattern.is_a?(Regexp) && pattern =~ name return false end |
#mouse? ⇒ Boolean
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rkremap/evdev.rb', line 73 def mouse? return @is_mouse unless @is_mouse.nil? @is_mouse = false return false if name =~ /\Arkremap\0*\z/ buf = +'' io.ioctl(EVIOCGBIT_ANY, buf) return false if buf.unpack1('C')[EV_KEY] == 0 @is_mouse = capable?(KeyCode::BTN_MOUSE) end |
#name ⇒ String
37 38 39 40 41 42 |
# File 'lib/rkremap/evdev.rb', line 37 def name return @name if @name buf = +'' io.ioctl(EVIOCGNAME, buf) @name = buf.sub(/\0+$/, '') end |
#read_event ⇒ Rkremap::Event
struct input_event
struct timeval time;
unsigned short type;
unsigned short code;
unsigned int value;
;
101 102 103 104 105 106 |
# File 'lib/rkremap/evdev.rb', line 101 def read_event raw = io.sysread(24) # sizeof(struct input_event) sec, usec, type, code, value = raw.unpack('Q!Q!SSl') time = Time.at(sec, usec) Event.new(self, time, type, code, value) end |