wbolster / evcape

simulate other keys when modifier keys are pressed on their own
37 stars 7 forks source link

Improve modifier handling #9

Open mherzberg opened 5 years ago

mherzberg commented 5 years ago

I have rules that have actions for both the simple press of a key and also the modified (e.g., by leftshift) press of a key. When trying to activate the longer of the two rules, however, the shorter one also gets activated since it also matches the input sequence. In addition, depending how exactly I specify the rules, I cannot simply keep the modifier pressed to execute the rule multiple times.

An example: Let's say I want 'a' to generate another 'b', and 'A' to generate another 'B', so just by entering 'aaaAAA' (I press leftshift before the first 'A' and release after the third) I would like to end up with 'abababABABAB'. I tried: python3 evcape.py "press:a,release:a=press:b,release:b" "press:leftshift,press:a,release:a,release:leftshift=press:leftshift,press:b,release:b,release:leftshift", which results in 'ababAbAbAb', and python3 evcape.py "press:a,release:a=press:b,release:b" "press:leftshift,press:a,release:a=press:leftshift,press:b,release:b,release:leftshift", which results in 'abababAbBAbAb', and python3 evcape.py "press:a,release:a=press:b,release:b" "press:leftshift,press:a,release:a=press:leftshift,press:b,release:b", which results in 'abababAbBABAB', which also keeps leftshift active for all following inputs.

After looking into your code, I suspect my only solution is to separate modifiers from your rules and handle them separately, like I have done in my fork. Is there something I'm missing here?

PS: Thanks for your useful script :-)

wbolster commented 5 years ago

heh, you're welcome.

no, you're not missing anything, you're just pushing my hack way beyond its architectural limits. :)

evcape is rather simplistic. it does not keep real state like active modifiers and so on (only the "trail" of the last key events), it doesn't even inhibit key presses but only injects extra ones when a condition matches. luckily, this approach is just enough to do a dual ctrl/escape key (and similar patterns like a dual shift/backspace key). the only additional "smart" trick is the timeout, but that's really all there is.

anything beyond that is not easily achievable, and to be honest i don't have spare brain cycles to spend on making evcape more generically useful. (it solves the main use case rather well.)