Class: Rkremap::Uinput

Inherits:
Object
  • Object
show all
Defined in:
lib/rkremap/uinput.rb

Overview

Constant Summary collapse

UI_SET_EVBIT =
1074025828
UI_SET_KEYBIT =
1074025829
UI_SET_RELBIT =
1074025830
UI_DEV_SETUP =
1079792899
UI_DEV_CREATE =
21761
REL_CNT =
0x10

Instance Method Summary collapse

Constructor Details

#initializeUinput

Returns a new instance of Uinput.



12
13
14
15
# File 'lib/rkremap/uinput.rb', line 12

def initialize
  @dev = File.open('/dev/uinput', 'w')
  setup
end

Instance Method Details

#setupObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rkremap/uinput.rb', line 17

def setup
  @dev.ioctl(UI_SET_EVBIT, EV_KEY)
  KeyCode::KEY_CNT.times{|k| @dev.ioctl(UI_SET_KEYBIT, k)}
  @dev.ioctl(UI_SET_EVBIT, EV_REL)
  REL_CNT.times{|r| @dev.ioctl(UI_SET_RELBIT, r)}
  bustype = 0x03    # BUS_USB
  vendor = 0x1234   # てきとー
  product = 0x5678  # てきとー
  version = 1       # てきとー
  name = 'rkremap'
  ff_efects_max = 0
  setup = [bustype, vendor, product, version, name, ff_efects_max].pack("SSSSZ80L") # struct uinput_setup
  @dev.ioctl(UI_DEV_SETUP, setup)
  @dev.ioctl(UI_DEV_CREATE)
end

#write_event(type, code, value) ⇒ Object

Parameters:

  • type (Integer)

    EV_KEY/ EV_SYN

  • code (Integer)

    キーコード / SYN_REPORT

  • value (Integer)

    0:release / 1:press / 2:repeat



36
37
38
# File 'lib/rkremap/uinput.rb', line 36

def write_event(type, code, value)
  @dev.syswrite(['', type, code, value].pack('a16SSl'))
end