keymapperorg / KeyMapper

An Android app that change what the buttons do on your devices!
http://docs.keymapper.club
GNU General Public License v3.0
1.02k stars 149 forks source link

Multiple trigger sequences on one hardware key doesn't work correctly #804

Open getle87 opened 2 years ago

getle87 commented 2 years ago

Developer TODO (don't remove)

Discord message link/email recipient

Describe the bug When I add multiple click seqences (click hw button one time, click hw button two times and so on) for one hardware button, all actions with lower click times are triggered.

For example I map the VolUp Key the following way:

Click 1x -> Toogle Flashlight Click 2x -> Toogle WiFi Click 3x -> Toogle Bluetooth

Now when I click 3 times, all actions are triggered, not only bluetooth. Is this a bug or a missing setting in the app on my phone?

To Reproduce Steps to reproduce the behavior: Look at my backup file

Backup of my settings: mappings_20211017-001210.zip

Expected behavior Every sequence should only be triggered if the correct amount of clicks is executed.

Screenshots Short GIF video, because videos say more than a thousand pics and words

issue

Smartphone (please complete the following information):

Additional context Add any other context about the problem here

gamesfragers commented 2 years ago

I think the solution would be to implement a configurable sleep/cool off between detecting each same key press. This way if the key is pressed and say 0.5 second passed without any repeats, then it should trigger Click 1x. If however, the same key is pressed 3 times within 0.5 then only Click 3x should trigger.

sudomain commented 1 year ago

Hmm this is possible with sxhkd which Termux has a package for. KeyMapper can trigger Termux shortcuts as actions and Termux can trigger keymaps using am. Maybe I can get sxhkd to do this since it can already handle this more advanced logic.

I'm not suggesting everyone go and get Termux and start running an X server, but the sxhkd config file syntax seems a lot simpler than adding a feature to KeyMapper. After all it's no longer developed but does what it does very well.

Edit (weeks later): I have a proof-of-concept with the described xdotool -> sxhkd but also made a version without requiring an X server: KeyMapper can trigger Termux expect scripts which can send key sequences to programs that can interpret them and then perform actions using am. These programs can be daemons you might already have running, for instance emacs or tmux, but probably the simplest solution (that i've gotten working) is having expect spawn and send the keys to a bash shell which has been configured to recieve the keys using bind -x, which in turn triggers KeyMapper actions using am