asus-linux-drivers / asus-numberpad-driver

Maintained feature-rich linux driver for NumberPad(2.0) on Asus laptops. NumberPad(2.0) is illuminated numeric keypad integrated to touchpad which appears when is done tap on top right corner of touchpad for atleast 1s by default (configurable) or slide gesture from top right/left corner to the center, the left shows calc app aswell (configurable).
GNU General Public License v2.0
257 stars 19 forks source link

[Feature Request] Use events/signals to detect numlock key press #173

Closed kamack38 closed 6 months ago

kamack38 commented 6 months ago

Short Description

Currently, when clicking the numlock button on the touchpad it counts the time between the touch and key lift. This means that for the numpad to be enabled, the user has to lift the finger without knowing whether the required amount of time has passed. Using events or something similar (asynchronous events) would mean that after the required time has passed, the numpad would light up even if the user would still be holding his finger on the touchpad, which would give an instant feedback.

New dependencies

No response

Additional Info

No response

kamack38 commented 6 months ago

Using chatgpt I've achieved something similar:

import threading
import time

def print_hello():
    print("Hello")

def delayed_hello():
    timer = threading.Timer(2, print_hello)
    timer.start()
    cancel_event = threading.Event()
    cancel_thread = threading.Thread(target=cancel_delayed_hello, args=(timer, cancel_event))
    cancel_thread.start()

def cancel_delayed_hello(timer, cancel_event):
    input("Press Enter to cancel...")
    cancel_event.set()
    timer.cancel()

if __name__ == "__main__":
    delayed_hello()
ldrahnik commented 6 months ago

@kamack38 I was thinking about that but I intentionally allowed only one finger as protection against accidental activation / deactivation.

kamack38 commented 6 months ago

Here's a simpler piece of code

import threading
import time

def print_hello():
    print("Hello")

def delayed_hello():
    timer = threading.Timer(2, print_hello)
    timer.start()
    return timer

def cancel_delayed_hello(timer):
    timer.cancel()

if __name__ == "__main__":
    timer = delayed_hello()
    cancel_delayed_hello(timer)
kamack38 commented 6 months ago

@kamack38 I was thinking about that but I intentionally allowed only one finger as protection against accidental activation / deactivation.

I'm not talking about removing this protection. I'm simply asking for an instant feedback, as it is done in the original driver. This doesn't change anything about how multiple fingers work.

ldrahnik commented 6 months ago

@kamack38 Could be refactored to listen gesture start and gesture end event (so code measuring the slide gesture start/end time could be removed) but I thjnk I did research and these events were not stable yet.

kamack38 commented 6 months ago

@kamack38 Could be refactored to listen gesture start and gesture end event (so code measuring the slide gesture start/end time could be removed) but I thjnk I did research and these events were not stable yet.

Above I've shown how it could be done using threads

kamack38 commented 6 months ago

The only case that would change is when the user holds the finger on the numlock key for LONGER than the activation time and then presses a numpad key while still holding the finger on the numlock key. Currently, the numpad wouldn't turn on, but after the change it would actually press the key, because the numpad would be enabled. However, it works the same way in the official driver on Windows, and before I've switched to Linux I've used it for a very long time and have never came across such issue.

ldrahnik commented 6 months ago

@kamack38 Ah, sorry, I understand. Endless cycle for brightness change (top left icon) works already in the same way as you are suggesting.

kamack38 commented 6 months ago

@kamack38 Ah, sorry, I understand. Endless cycle for brightness change (top left icon) works already in the same way as you are suggesting.

This means that this feature will be implemented? I think using the threading lib it's very simple, and I think I can do it. It would really change only 3 - 5 lines of code.

ldrahnik commented 6 months ago

@kamack38 Changes done in this branch should be enough. This was intended too but you are right, let control this by config value when is done untouch is not good idea. Let me know I understood you well.

kamack38 commented 6 months ago

It's quite late for me, so I'll get to it tomorrow morning and test it.

ldrahnik commented 6 months ago

@kamack38 I did a few more changes and now works like suggested behavior slide gestures from top even right, NumLock top right icon press and any other NumLock key pressed in layout.