jtroo / kanata

Improve keyboard comfort and usability with advanced customization
GNU Lesser General Public License v3.0
3.21k stars 131 forks source link

Bug: "switch" & "not" operator not working #1187

Closed santhoshr closed 3 months ago

santhoshr commented 3 months ago

Requirements

Describe the bug

"not" operator doesn't work with list of keys, for e.g.

(defcfg
  process-unmapped-keys yes
  concurrent-tap-hold yes
)

(defsrc caps)
(deflayer default
    @swh
)

(defalias
  swh (switch
    ((not a b c )) S-a break
    () XX break
  )
)

curiously not works with input real ((not (input real a))) S-a break

Is there a way to check previous key input? for e.g. to check if I have pressed any of given list of keys and they can be pressed individually or in combination, for e.g. if a-z letters are configured and when switch returns I can either press escape or press return based on switch evaluation? Key-history will not work because it will take single key and one should also give recency, if I'm typing any word then I cannot predict where 'a' comes also I need list of keys. Key-timing will not work because if I use switch for processing keys while holding some other key, if I hold alt key and use this logic key-timing will take alt key into account.

Relevant kanata config

No response

To Reproduce

Given as part of description

Expected behavior

"not" operator working

Kanata version

1.6.1

Debug logs

No response

Operating system

Windows 10

Additional context

No response

jtroo commented 3 months ago

Try (not (or a b c))

jtroo commented 3 months ago

Random thought, perhaps or should have the alternate name "any", likewise and could have the alternate name "all"

santhoshr commented 3 months ago

I realized "not" works on "key press", any way to make it work on key release?

santhoshr commented 3 months ago

Random thought, perhaps or should have the alternate name "any", likewise and could have the alternate name "all"

any / all & or / and won't make much difference "all" could even cause confusion

jtroo commented 3 months ago

I realized "not" works on "key press", any way to make it work on key release?

It's not clear to me exactly what you mean. My guess is you're looking for (on-release tap-vkey vk-switch) where vk-switch is defined to be the switch action you want.

santhoshr commented 3 months ago

With key-history I was able to achieve pseudo condition to implement kind-of quasimode (introduced by Jef Raskin).

Bit of explanation below, Quasimode keys works like shift, one key is held while typing other keys. So I want some of my keys to have this behaviour, one such functionality is Search, on pressing capslock and typing I want to search, and on release it should trigger enter or escape based on whether I typed or not, since we are working with keyboard we can't check application input box if it is empty or not to trigger enter or escape. Running the below code and opening a browser page, holding capslock will allow for kind-of quasimode search, and on release, it would trigger escape or return.

(defcfg
    process-unmapped-keys yes
    concurrent-tap-hold yes)

(defsrc 
                    caps)
(deflayer default
                    @fin)

(defalias
    fin (multi (on-press tap-vkey cf) (on-release tap-vkey fc)))

(defvirtualkeys
    cf  C-f
    es  esc
    en  ret
    fc (switch
             ((key-history f 1)) esc break
             ((key-history ret 1)) esc break
             () ret break)
    no (switch
             ((key-history f 1)) esc break
             ((not a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 lsft rsft)) esc break
             ((key-history ret 1)) esc break
             () ret break))

In the above,