Same key twice

Is it possible to intercept the double pressure of the same key by using a single rule? So for example, I want something to happen when the user press "g" + "g", but I’d like to achieve that with a single instruction for all consonants at the same time, using for example “any”, but I don’t know how. I tried to write the rule any(cons) + context > ..., but it raises an error. Thank you.

Welcome to the community.

You may try index().

https://help.keyman.com/developer/language/reference/_index

Let me know if you need further assistance.

This is a little trickier because you can’t use context or index in the key part of the rule. Instead, you need to have a secondary processing group, which means you can’t quite do it in one rule – but you can do it in two rules. Note that the secondary processing group is not a “using keys” group:

  + any(cons) > index(cons, 1) use(dedup)

group(dedup)
  any(cons) context(1) > ...

Thank you very much, Marc, I saw that this rule works perfectly with normal characters, but I’m using characters of a custom alphabet, and didn’t manage to let it work, because I didn’t quite understand how groups work.

So, when I press for example the “p” key, a corresponding character of the custom alphabet is typed (that for “p” is U+E012), using the following rule:

 + any(cons) > index(f_cons, 1)

where “f_cons” is the string of the corrisponding consonants of the custom alphabet. Now, I don’t know how to change the code that you wrote, in order to let it work together with this rule.

Could you also tell me please, what the code that you wrote exactly does, or where I could find a detailed description of how the “use” statement with groups works?

Thank you.

So, by doing some tests, I managed to let it work, but for pure luck :slightly_smiling_face::

 + any(l_cons) > index(fs_cons, 1) use(gemination)

 group(gemination)
   any(fs_cons) context(1) > index(fg_cons, 1)

Now, when I type a consonant char (l_cons), this is changed into the corresponding simple consonant symbol of the custom alphabet (fs_cons) and if I press the same consonant again, it is changed into the corresponding geminated consonant symbol (fg_con). It works really fine! But now the question is… why? :slightly_smiling_face:

The output of the first group (plus the existing context in the text buffer) provides the input to the gemination group. So when you enter the second group (which does not process keystrokes, just context – because it doesn’t have the using keys clause), you can post-process the output from the first group, which is exactly what you are doing :slight_smile: .

Read more on groups.

Thank you very much.

The conversation has resolved.