asus-linux-drivers / asus-wmi-hotkeys-driver

Linux configurable driver for Asus WMI hotkeys. The driver works as middle-man, is listening for key events from specific devices and when is appropriate key event caught then may be handle by own way configured in config file.
GNU General Public License v2.0
27 stars 4 forks source link

Help for the setup part.. #14

Open akaibukai opened 3 weeks ago

akaibukai commented 3 weeks ago

Hi @ldrahnik!

Just noticed that you're also a maintainer/author here :) Thanks!

So I tried to install this in order to the my keyboard keys I have above my numpad. It seems it correctly installed what's necessary when running bash install.sh which I did by selecting the ux582z model..

However, at first it was not working.. Looking at the error messages (python) I was able to get that I needed to add the keys_wmi that was not present by default in the config file... Basically following the Setup part of the readme.. Then, using the commands to discover the keycodes/keys value, I noticed the values in the default ux582z.py were correct for me. So here is the layout.py file I updated:

# /usr/share/asus-wmi-hotkeys-driver/keys_wmi_layouts/layout.py
from libevdev import EV_KEY

KEY_WMI_SCREENPAD = 0x6A  # 106
KEY_WMI_TOUCHPAD = 0x6B  # 107

KEY_WMI_CAMERA = 0x85  # 133
KEY_WMI_MYASUS = 0x86  # 134
KEY_WMI_SWITCHWINDOWS = 0x9C  # 156
KEY_WMI_FAN = 0x9D  # 157

keys_wmi = [
    [ KEY_WMI_SCREENPAD ],
    [ KEY_WMI_SWITCHWINDOWS ],
    [ KEY_WMI_FAN ]
]

I'm only interested with those 3 keys as the others are already working in my case.

But, unfortunately, it was still not working. I tried to debug a little bit (using good old print statements lol).. And when I hit one of these keys it runs down to this part of the asus_wmi-hotkeys.py file (including relevant variables content as comments and skipping unrelevant parts)

# /usr/share/asus-wmi-hotkeys-driver/asus_wmi_hotkeys.py
L142 def handle_events(device, udev):
L143 while True:
L144         # If device (e.g. Asus WMI hotkeys) sends something
L145         for e in device.events():
...
... # e is InputEvent(EV_MSC, MSC_SCAN, 157) for example when pressing KEY_WMI_FAN)
...
L163                 find_custom_key_mapping = list(filter(lambda x: e.value in x or e.code in x or e in x, keys_wmi_layouts.keys_wmi))
# Here find_custom_key_mapping = [157]
...
L277                     try:
L278                         udev.send_events(keys_to_send_press_events)
L279                         udev.send_events(sync_event)
L280                         udev.send_events(keys_to_send_release_events)
L281                         udev.send_events(sync_event)
# with the following values:
# keys_to_send_press_events = []
# sync_event = [InputEvent(EV_SYN, SYN_REPORT, 0)]
# keys_to_send_press_events = []

So it seems that the format of find_custom_key_mapping (one dimension list) is not correct and it's not triggering the for loops we have on the lines 252, 260 and 268:

for ___ in find_custom_key_mapping[0][1:]:

Can you help me figure out what is wrong in here?

Thanks!

akaibukai commented 3 weeks ago

Little update.. When I hit a key (e.g. KEY_WMI_FAN), I got in reality a bunch of events at once:

InputEvent(EV_MSC, MSC_SCAN, 157
InputEvent(EV_KEY, KEY_UNKNOWN, 1)
InputEvent(EV_SYN, SYN_REPORT, 0)
InputEvent(EV_KEY, KEY_UNKNOWN, 0)
InputEvent(EV_SYN, SYN_REPORT, 0)

FWIW, when I hit a working key in my case (the keys that are on the Fn row like KEY_WMI_CAMERA) I got the following:

InputEvent(EV_MSC, MSC_SCAN, 133)
InputEvent(EV_KEY, KEY_CAMERA, 1)
InputEvent(EV_SYN, SYN_REPORT, 0)
InputEvent(EV_KEY, KEY_CAMERA, 0)
InputEvent(EV_SYN, SYN_REPORT, 0)

So it seems the KEY_UNKNOWN part is probably the culprit..


Also for completeness here are the other 2 keys that I wanted to get working:

# KEY_WMI_SWITCHWINDOWS
InputEvent(EV_MSC, MSC_SCAN, 156
InputEvent(EV_KEY, KEY_UNKNOWN, 1)
InputEvent(EV_SYN, SYN_REPORT, 0)
InputEvent(EV_KEY, KEY_UNKNOWN, 0)
InputEvent(EV_SYN, SYN_REPORT, 0)
# KEY_WMI_SCREENPAD
InputEvent(EV_MSC, MSC_SCAN, 106
InputEvent(EV_KEY, KEY_UNKNOWN, 1)
InputEvent(EV_SYN, SYN_REPORT, 0)
InputEvent(EV_KEY, KEY_UNKNOWN, 0)
InputEvent(EV_SYN, SYN_REPORT, 0)
ldrahnik commented 3 weeks ago

@akaibukai Hi again, code below listen for scan codes 106, 156 and 157. The code allows you to send different keys to KEY_UNKNOWN and change value of your fan thermal policy between 0,1,2 changeable for my previous temporary laptop gu603zi via file /sys/devices/platform/asus-nb-wmi/throttle_thermal_policy:

# /usr/share/asus-wmi-hotkeys-driver/keys_wmi_layouts/layout.py

from libevdev import EV_KEY

KEY_WMI_SCREENPAD = 0x6A  # 106
KEY_WMI_SWITCHWINDOWS = 0x9C  # 156
KEY_WMI_FAN = 0x9D  # 157

key_wmi_screenpad = [
    KEY_WMI_SCREENPAD, # we listen for scan code 106
    EV_KEY.KEY_TOUCHPAD_TOGGLE # and in this case will be sent touchpad toggling evdev key instead of unknown one, choose what you want
]

key_wmi_switchwindows = [
    KEY_WMI_SWITCHWINDOWS, # the same as above here, but you can send for example multiple keys together as me <left shift>+<left meta><t>
    EV_KEY.KEY_LEFTSHIFT,
    EV_KEY.KEY_LEFTMETA,
    EV_KEY.KEY_T,
]

KEY_WMI_FAN_THROTTLE_THERNAL_POLICY = '/sys/devices/platform/asus-nb-wmi/throttle_thermal_policy'
KEY_WMI_FAN_THROTTLE_THERNAL_POLICY_VALUES = [
    0,
    1,
    2
]

key_wmi_fan = [
    EV_KEY.KEY_PROG4,
    [
        KEY_WMI_FAN_THROTTLE_THERNAL_POLICY,
        KEY_WMI_FAN_THROTTLE_THERNAL_POLICY_VALUES

    ]
]

keys_wmi = [
    key_wmi_screenpad,
    key_wmi_switchwindows,
    key_wmi_fan
]

What a keys you can use as EV_KEY.xyp you can find here. For fans at first try manually in the terminal whether works echo "0" | sudo tee /sys/devices/platform/asus-nb-wmi/throttle_thermal_policy, echo "1" | sudo tee /sys/devices/platform/asus-nb-wmi/throttle_thermal_policy and echo "2" | sudo tee /sys/devices/platform/asus-nb-wmi/throttle_thermal_policy.