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 |
# File 'lib/rkremap/evdev.rb', line 13 def initialize(path) @path = path @io = nil @capa = nil @uinput = nil @grab = false 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
49 50 51 52 53 54 55 56 |
# File 'lib/rkremap/evdev.rb', line 49 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
43 44 45 |
# File 'lib/rkremap/evdev.rb', line 43 def close @io&.close end |
#eql?(other) ⇒ Boolean
25 26 27 |
# File 'lib/rkremap/evdev.rb', line 25 def eql?(other) other.is_a?(Evdev) && self.path == other.path end |
#grab ⇒ Object
83 84 85 86 |
# File 'lib/rkremap/evdev.rb', line 83 def grab io.ioctl(EVIOCGRAB, 1) @grab = true end |
#grab? ⇒ Boolean
89 90 91 |
# File 'lib/rkremap/evdev.rb', line 89 def grab? @grab end |
#inspect ⇒ Object
21 22 23 |
# File 'lib/rkremap/evdev.rb', line 21 def inspect "#<Rkremap::Evdev: #{name} (#{path})>" end |
#io ⇒ IO
30 31 32 33 |
# File 'lib/rkremap/evdev.rb', line 30 def io return @io if @io @io = File.open(@path) end |
#keyboard? ⇒ Boolean
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rkremap/evdev.rb', line 59 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
108 109 110 111 112 113 114 |
# File 'lib/rkremap/evdev.rb', line 108 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
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rkremap/evdev.rb', line 72 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
36 37 38 39 40 41 |
# File 'lib/rkremap/evdev.rb', line 36 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;
;
100 101 102 103 104 105 |
# File 'lib/rkremap/evdev.rb', line 100 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 |