mirror of
https://github.com/erjiang/huion-keys.git
synced 2026-03-23 21:54:53 +03:00
Create default config file if not exists
This commit is contained in:
parent
84ed4a3195
commit
3e2b04ef5a
@ -2,35 +2,9 @@ import os
|
|||||||
|
|
||||||
from _xdo_cffi import ffi, lib
|
from _xdo_cffi import ffi, lib
|
||||||
|
|
||||||
BUTTON_BINDINGS = [
|
CONFIG_FILE_PATH = os.path.expanduser('~/.config/huion_keys.conf')
|
||||||
# left side, top to bottom
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
|
|
||||||
None,
|
BUTTON_BINDINGS = {}
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
|
|
||||||
# right side, top to bottom
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
|
|
||||||
# scroll strip, up/down
|
|
||||||
# even though the Kamvas 22 (2019) has two scroll strips, they both send
|
|
||||||
# the same button codes
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
]
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
xdo = lib.xdo_new(ffi.NULL)
|
xdo = lib.xdo_new(ffi.NULL)
|
||||||
@ -38,12 +12,15 @@ def main():
|
|||||||
if hidraw_path is None:
|
if hidraw_path is None:
|
||||||
print("Could not find tablet hidraw device")
|
print("Could not find tablet hidraw device")
|
||||||
print("Found tablet at " + hidraw_path)
|
print("Found tablet at " + hidraw_path)
|
||||||
read_config(os.path.expanduser('~/.config/huion_keys.conf'))
|
if os.path.isfile(CONFIG_FILE_PATH):
|
||||||
|
read_config(CONFIG_FILE_PATH)
|
||||||
|
else:
|
||||||
|
write_default_config(CONFIG_FILE_PATH)
|
||||||
hidraw = open(hidraw_path, 'rb')
|
hidraw = open(hidraw_path, 'rb')
|
||||||
while True:
|
while True:
|
||||||
btn = get_button_press(hidraw)
|
btn = get_button_press(hidraw)
|
||||||
print("Got button %d" % (btn,))
|
print("Got button %s" % (btn,))
|
||||||
if BUTTON_BINDINGS[btn]:
|
if btn in BUTTON_BINDINGS:
|
||||||
print("Sending %s" % (BUTTON_BINDINGS[btn],))
|
print("Sending %s" % (BUTTON_BINDINGS[btn],))
|
||||||
lib.xdo_send_keysequence_window(
|
lib.xdo_send_keysequence_window(
|
||||||
xdo, lib.CURRENTWINDOW, BUTTON_BINDINGS[btn], 10)
|
xdo, lib.CURRENTWINDOW, BUTTON_BINDINGS[btn], 10)
|
||||||
@ -77,13 +54,30 @@ def read_config(config_file):
|
|||||||
# button bindings are 0-indexed so need to subtract one
|
# button bindings are 0-indexed so need to subtract one
|
||||||
BUTTON_BINDINGS[int(setting)-1] = value.encode('utf-8')
|
BUTTON_BINDINGS[int(setting)-1] = value.encode('utf-8')
|
||||||
elif setting == 'scroll_up':
|
elif setting == 'scroll_up':
|
||||||
BUTTON_BINDINGS[16] = value.encode('utf-8')
|
BUTTON_BINDINGS['scroll_up'] = value.encode('utf-8')
|
||||||
elif setting == 'scroll_down':
|
elif setting == 'scroll_down':
|
||||||
BUTTON_BINDINGS[17] = value.encode('utf-8')
|
BUTTON_BINDINGS['scroll_down'] = value.encode('utf-8')
|
||||||
else:
|
else:
|
||||||
print("[WARN] unrecognized setting '%s'" % (setting,))
|
print("[WARN] unrecognized setting '%s'" % (setting,))
|
||||||
|
|
||||||
|
|
||||||
|
def create_default_config(config_file):
|
||||||
|
with open(config_file, 'w') as config:
|
||||||
|
config.write("""
|
||||||
|
# use one line for each button you want to configure
|
||||||
|
# buttons that aren't in this file will be ignored by this program
|
||||||
|
# (but may be handled by another driver)
|
||||||
|
4=ctrl+s
|
||||||
|
5=ctrl+z
|
||||||
|
6=ctrl+shift+equal
|
||||||
|
7=ctrl+minus
|
||||||
|
# etc. up to the highest button number
|
||||||
|
16=tab
|
||||||
|
scroll_up=bracketright
|
||||||
|
scroll_down=bracketleft
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
BUTTON_BITS = {
|
BUTTON_BITS = {
|
||||||
0x01: 0,
|
0x01: 0,
|
||||||
0x02: 1,
|
0x02: 1,
|
||||||
@ -124,10 +118,10 @@ def get_button_press(hidraw):
|
|||||||
# value means they scrolled down
|
# value means they scrolled down
|
||||||
if scroll_pos > SCROLL_STATE:
|
if scroll_pos > SCROLL_STATE:
|
||||||
SCROLL_STATE = scroll_pos
|
SCROLL_STATE = scroll_pos
|
||||||
return 17 # scroll down
|
return 'scroll_down'
|
||||||
elif scroll_pos < SCROLL_STATE:
|
elif scroll_pos < SCROLL_STATE:
|
||||||
SCROLL_STATE = scroll_pos
|
SCROLL_STATE = scroll_pos
|
||||||
return 16
|
return 'scroll_up'
|
||||||
else:
|
else:
|
||||||
SCROLL_STATE = scroll_pos
|
SCROLL_STATE = scroll_pos
|
||||||
continue
|
continue
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user