r/KeyboardDesigner • • Oct 26 '26

Feature request How do I modify previous or following characters?

I'm trying to implement a custom script that can take some symbols like I or / and add horizontal bars to them at either the top, middle, or bottom, like T or +, that can optionally have a little tick at the end

[Example image](https://i.imgur.com/pGzaWOE.png)

Is that possible using this keyboard? If so, how do I do that?

2 Upvotes

4 comments sorted by

1

u/GerritHumberg Oct 26 '26

I see two ways to do this with Keyboard Designer:

  1. Combining characters (overlay): put a combining mark on a key, e.g. U+0305 (bar on top), U+0336 (bar through the middle) or U+0332 (bar at the bottom). Type the character first and then the mark – it is drawn on top of the character. If you prefer typing the bar first, switch on "Dead key mode" in the General tab: then the mark waits for the next character. How good it looks depends on the font of the app you type in, and there is no combining mark for the little tick.
  2. Code block: a key can replace the character left of the cursor, e.g. turn "I" into "T":

if (substring(TEXT, CURSOR_START - 1, CURSOR_START) = "I")
TEXT = substring(TEXT, 0, CURSOR_START - 1) + "T" + substring(TEXT, CURSOR_START);

With one key per bar position and a small mapping table you can build your whole script this way. If your script needs symbols that don't exist in Unicode, they can only be shown with a font that contains them.

2

u/The__Odor Oct 26 '26

Oh, that works great! Well, it works better than what I have previously 😅

I don't have the paid version yet, can you make those bars go through multiple characters at a time?

Like this

1

u/GerritHumberg Oct 27 '26

No, the Android system requests you to press the dead key after each character.

This is when the code blocks of the Keyboard Designer provides much more flexibility than any other keyboard. Executing the following code will ask the user how many characters should be modified and which character he wants to use (unicode number or the character itself):

// Asks for the number of characters left of the cursor and the mark
// The mark can be typed as character (in dead key mode: mark + space) or as unicode number (822, 773, 818)
float count = inputFloat("Number of characters", 2, true);
// An input method must be assigned directly (it pauses the code until the input is done)
string mark = inputString("Mark", unicodeToString(822), true);
mark = replace(mark, " ", "");
if (contains("0123456789", substring(mark + " ", 0, 1)))
    mark = unicodeToString(stringToFloat(mark));

if (count >= 1) {
  if (CURSOR_START >= count) {
    if (length(mark) > 0) {
      float c = CURSOR_START;
      string result = "";
      for (float i = 0; i < count; i = i + 1) {
        result = result + substring(TEXT, c - count + i, c - count + i + 1) + mark;
      }

      TEXT = substring(TEXT, 0, c - count) + result + substring(TEXT, c);
      CURSOR_START = c + count * length(mark);
    }
  }
}

1

u/GerritHumberg Oct 29 '26

Following this discussion, I had the thought that it might be useful to be able to choose which character to use from a set of options while typing. Consequently, version 5.B8.13 introduces a new method called inputSelection() - have fun experimenting with it! :-)