Skip to content

Commit

Permalink
add handling for mouse events with linux emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
ahtn committed Jun 6, 2019
1 parent 9b2c4af commit f6a7fee
Show file tree
Hide file tree
Showing 24 changed files with 614 additions and 375 deletions.
2 changes: 1 addition & 1 deletion host-software/keyplus-cli
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ class ProgramCommand(GenericDeviceCommand):
try:
settings_data = kp_layout.build_settings_section(device_target)
layout_data = kp_layout.build_layout_section(device_target)
except Exception as err:
except KeyplusError as err:
print_error(err)
exit(EXIT_BAD_FILE)

Expand Down
2 changes: 2 additions & 0 deletions host-software/keyplus/constants/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,5 @@ def report_mode_to_str(mode):
}

INTERNAL_SCAN_METHOD_TABLE = inverse_map(INTERNAL_SCAN_METHOD_NAME_TABLE)

VIRTUAL_MAP_TABLE_SIZE = 0x300
2 changes: 1 addition & 1 deletion host-software/keyplus/device_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def to_bytes(self):
)
result += self._pin_map_to_bytes();
elif self.internal_scan_method == MATRIX_SCANNER_INTERNAL_VIRTUAL:
assert(len(self.key_number_map) <= 512)
assert(len(self.key_number_map) <= VIRTUAL_MAP_TABLE_SIZE)
result += bytearray(self.key_number_map)
else:
raise KeyplusSettingsError(
Expand Down
26 changes: 26 additions & 0 deletions host-software/keyplus/io_map/virtual.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,32 @@
'RIGHT_ALT' : 0xe6, 'RALT' : 0xe6,
'RIGHT_GUI' : 0xe7, 'RGUI' : 0xe7, 'RMETA' : 0xe7, 'RWIN' : 0xe7,
# /* reserved e8-ffff */

'SYS_POWER' : 0x101, # 0x81: HID_DESKTOP_SYSTEM_POWER_DOWN
'SYS_SLEEP' : 0x102, # 0x82: HID_DESKTOP_SYSTEM_SLEEP
'SYS_WAKEUP' : 0x103, # 0x83: HID_DESKTOP_SYSTEM_WAKE_UP
'SYS_CONTEXT_MENU' : 0x104, # 0x84: HID_DESKTOP_SYSTEM_CONTEXT_MENU
'SYS_MENU' : 0x105, # 0x85: HID_DESKTOP_SYSTEM_MAIN_MENU
'SYS_APP_MENU' : 0x106, # 0x86: HID_DESKTOP_SYSTEM_APP_MENU
'SYS_HELP' : 0x107, # 0x87: HID_DESKTOP_SYSTEM_MENU_HELP
'SYS_EXIT' : 0x108, # 0x88: HID_DESKTOP_SYSTEM_MENU_EXIT
'SYS_SELECT' : 0x109, # 0x89: HID_DESKTOP_SYSTEM_MENU_SELECT
'SYS_RIGHT' : 0x10a, # 0x8a: HID_DESKTOP_SYSTEM_MENU_RIGHT
'SYS_LEFT' : 0x10b, # 0x8b: HID_DESKTOP_SYSTEM_MENU_LEFT
'SYS_UP' : 0x10c, # 0x8c: HID_DESKTOP_SYSTEM_MENU_UP
'SYS_DOWN' : 0x10d, # 0x8d: HID_DESKTOP_SYSTEM_MENU_DOWN
'SYS_COLD_RESTART' : 0x10e, # 0x8e: HID_DESKTOP_SYSTEM_COLD_RESTART
'SYS_WARM_RESTART' : 0x10f, # 0x8f: HID_DESKTOP_SYSTEM_WARM_RESTART

'BTN1' : 0x110, # Left Mouse Button
'BTN2' : 0x111, # Right Mouse Button
'BTN3' : 0x112, # Middle Mouse Button
'BTN4' : 0x113, # Mouse Button 4
'BTN5' : 0x114, # Mouse Button 5
'BTN6' : 0x115, # Mouse Button 6
'BTN7' : 0x116, # Mouse Button 7
'BTN8' : 0x117, # Mouse Button 8

}


Expand Down
2 changes: 1 addition & 1 deletion host-software/keyplus/layout/scan_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def generate_pin_mapping(self, dev_target):
)
elif self.mode == VIRTUAL:
keys = io_mapper.get_pin_numbers(self.keys)
key_number_map = [0xff] * 512
key_number_map = [0xff] * VIRTUAL_MAP_TABLE_SIZE

for (key_num, key) in enumerate(keys):
key_number_map[key] = key_num
Expand Down
140 changes: 111 additions & 29 deletions layouts/virtual.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,36 @@
report_mode: nkro

devices:
virtual_map_test:
# virtual_map_test:
# id: 0
# scan_mode:
# mode: virtual
# # hid_vid: 0x1209
# # hid_pid: 0x1209
# # hid_name: hello
# # hid_serial: "123456abcdef"
# keys: [
# F1,

# TAB, Q , W , E , R , T , Y , U , I , O , P , "[" , "]" , "\\" , INS, HOME, PGUP,
# CAPS, A , S , D , F , G , H , J , K , L , ";" , "'" , ENT , DEL, END , PGDN,
# LSFT, Z , X , C , V , B , N , M , ",", ".", "/" , RSFT, UP,
# LWIN, LEFT, DOWN, RIGHT
# ]
# layout: colemak

mouse_map_test:
id: 0
scan_mode:
mode: virtual
# hid_vid: 0x1209
# hid_pid: 0x1209
# hid_name: hello
# hid_serial: "123456abcdef"
# keys: [A, S, D, F, G, H, J, K, L, ";", "'"]
keys: [
F1,

TAB, Q , W , E , R , T , Y , U , I , O , P , "[" , "]" , "\\" , INS, HOME, PGUP,
CAPS, A , S , D , F , G , H , J , K , L , ";" , "'" , ENT , DEL, END , PGDN,
LSFT, Z , X , C , V , B , N , M , ",", ".", "/" , RSFT, UP,
LWIN, LEFT, DOWN, RIGHT
BTN1, BTN2, BTN3, BTN4, BTN5, BTN6, BTN7
]
layout: 1key
layout: mouse

keycodes:
SFTEnt:
Expand Down Expand Up @@ -65,27 +77,97 @@ keycodes:
- system_cold_restart
- system_warm_restart

# Default key repeat rate is too fast for changing tabs,
# so this macro lets the keyboard control it
slow_tab_change_left:
keycode: macro
commands:
- set_clear_rate(10)
- set_rate(200)
- repeat(0)
- c-pgup
- none
- end_repeat()
commands_release:
- release(c-pgup)

slow_tab_change_right:
keycode: macro
commands:
- set_clear_rate(10)
- set_rate(200)
- repeat(0)
- c-pgdn
- none
- end_repeat()
commands_release:
- release(c-pgdn)

# Close tab, no repeat
close_tab:
keycode: macro
commands:
- c-w

rapid_click:
keycode: macro
commands:
- set_rate(8)
- repeat(0) # repeat forever
- press(lmsb)
- release(lmsb)
- end_repeat()
commands_release:
- release(lmsb)

gesture:
keycode: mouse_gesture
left: slow_tab_change_left
right: slow_tab_change_right
up: ca-up
down: ca-down
up_right: home
down_right: end
up_left: rapid_click
down_left: close_tab

# tap: TODO
#
threshold: 110
threshold_diag: 65
# threshold_tap: 30
threshold_tap: 0

layouts:
1key:
mouse:
layers: [
[ # layer 0 (base)
[
M1,

tab, Q , W , F , P , G , J , L , U , Y , ";" , "[" , "]" , "\\" , INS , HOME , PGUP,
lctrl, A , R , S , T , D , H , N , E , I , O , "'" , ENT , DEL , END , PGDN,
s_lsft, Z , X , C , V , B , K , M , ",", ".", "/" , s_rsft, UP ,
L1, LEFT, DOWN, RIGHT
]
],
[ # layer 1 (base)
[
M1,

tab, PSCR,MPLY,VOLU,MSTP, G , J , L , U , Y , ";" , "[" , "]" , "\\" , INS , BTN3, WH_U,
lctrl, MUTE,MNXT,VOLD,MPRV, D , H , N , E , I , O , "'" , ENT , BTN1, BTN2, WH_D,
s_lsft, Z , X , C , V , B , K , M , ",", ".", "/" , s_rsft, ms_u ,
L1, ms_l, ms_d, ms_r
]
[ # Layer 0
[ # Mouse
1, 2, gesture, BTN4, BTN5, BTN6, BTN7
],
],
]

# colemak:
# layers: [
# [ # layer 0 (base)
# [
# M1,

# tab, Q , W , F , P , G , J , L , U , Y , ";" , "[" , "]" , "\\" , INS , HOME , PGUP,
# lctrl, A , R , S , T , D , H , N , E , I , O , "'" , ENT , DEL , END , PGDN,
# s_lsft, Z , X , C , V , B , K , M , ",", ".", "/" , s_rsft, UP ,
# L1, LEFT, DOWN, RIGHT
# ]
# ],
# [ # layer 1 (base)
# [
# M1,

# tab, PSCR,MPLY,VOLU,MSTP, G , J , L , U , Y , ";" , "[" , "]" , "\\" , INS , BTN3, WH_U,
# lctrl, MUTE,MNXT,VOLD,MPRV, D , H , N , E , I , O , "'" , ENT , BTN1, BTN2, WH_D,
# s_lsft, Z , X , C , V , B , K , M , ",", ".", "/" , s_rsft, ms_u ,
# L1, ms_l, ms_d, ms_r
# ]
# ],
# ]
2 changes: 2 additions & 0 deletions ports/linux/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ TEST_CONFIG_BIN ?= ./test_conf.bin

USE_HID = 1
USE_USB = 0
USE_MOUSE = 1
USE_SCANNER = 0
USE_MOUSE_GESTURE = 1

USE_VIRTUAL_MODE = 1

Expand Down
Loading

0 comments on commit f6a7fee

Please sign in to comment.