Julow / Unexpected-Keyboard

A lightweight virtual keyboard for developers.
GNU General Public License v3.0
1.37k stars 176 forks source link

How to change functionality of backspace key #513

Open JRBros2346 opened 8 months ago

JRBros2346 commented 8 months ago

I implemented Klingon quja' keyboard layout in Unexpected Keyboard, source code below vvv

This does not have a lot of symbols (I don't know the standard for placing symbols and i have just placed "some " useful ones randomly"). The problem is some characters are multi glyphs long like tlh and ng, but backspace only deletes the last glyph for example tl and n. How to change this behaviour? Google Board does this. Also, how to change keyboard font, because I and l look same

JRBros2346 commented 8 months ago
<keyboard name="quja' (tlhInghon)" script="latin">
  <row>
    <key key0="q" key1="1" key2="2"/>
    <key key0="u" key1="3" key2="4"/>
    <key key0="j" key1="5" key2="6"/>
    <key key0="a" key1="7" key2="8"/>
    <key key0="'" key1="9" key2="0"/>
    <key width="2" key0="backspace" key2="delete"/>
  </row>
  <row>
    <key key0="Q"/>
    <key key0="m"/>
    <key key0="I" key1="!"/>
     <key key0="tlh"/>
    <key key0="o"/>
    <key key0="e"/>
    <key key0="H"/>
  </row>
  <row>
    <key key0="D"/>
    <key key0="v"/>
    <key key0="l" key1="\?"/>
    <key key0="t"/>
    <key key0="b"/>
    <key key0="S"/>
    <key key0="p"/>
  </row>
  <row>
    <key key0="ch"/>
    <key key0="y"/>
    <key key0="w" key3="."/>
    <key key0="gh" key3=","/>
    <key key0="r"/>
    <key key0="n"/>
    <key key0="ng"/>
  </row>
</keyboard>
Spike-from-NH commented 8 months ago

It sounds as though Google Board's backspace is a sort of undo. (Does it know that tlh is a single character? If you put the cursor before t and use delete or right-arrow, do they also do the correct thing for Klingon?) Context to implement undo would be a massive addition I would not expect in a "lightweight" keyboard.

I'd welcome the ability to specify keyboard font, or the legend of individual keys. Surely Unicode has a glyph of I with serifs?

JRBros2346 commented 8 months ago

So, do you mean there isn't a way to override backspace functionality as of right now? I think it would be possible to implement it, tl doesn't exist in Klingon, so if i delete one of tlh, it should delete the others right?

JRBros2346 commented 8 months ago

I with serifs do exist and work, but if so, the typed charachter would be i with serif, not the plain old i, it would be hard to transcript it to ASCII file or something. Unless there is a way to show I with serif in the keyboard and print normal I

Spike-from-NH commented 8 months ago

@JRBros2346, unless Unicode has or gets a single character whose glyph is tlh, the behavior you seek would require additional coding and is certainly not a user setting. I'd be against this Do-what-I-meant: Users who don't write in this invented language would regard it as a bug if trying to rub out the g from ng rubbed out both characters.

JRBros2346 commented 8 months ago

Unicode does not have Klingon script, but Klingon does have a script implemented in ConScript Unicode Registry Private Use Area. Which means, it can be used if the font supporting CSUR exists. But changing fonts in mobile is terribly hard. I would rather prefer these Latin counterparts

JRBros2346 commented 8 months ago

is there a standard for placing symbol in user defined layouts? I have just added a few useful symbols in random locations Screenshot_2023-12-24-20-29-27-21_3aea4af51f236e4932235fdada7d1643

Spike-from-NH commented 8 months ago

In my opinion, "user-defined" means it is up to you! Such conventions would not be decided by Unexpected users but Klingon users.

By the way, I too have swipes to type multiple letters (at t and y) but I would never expect the rubout key to rub out the entire word. Screenshot_20231125-221439_Fennec

JRBros2346 commented 8 months ago

The way you use multiple letters is as "words" but i use them as "glyphs". I would like some adjustable setting that specifies this like key1="the" for words and key0="tlh gly" to mention glyphs, just like loc keyword

i see the swipe gesture layout is not standardised in unexpected users community The layout you use is more customised and user specific

JRBros2346 commented 8 months ago

There is a key to undo, addable as special keys like the copy paste ones. But it deletes the whole word, rather than last glyph. It maybe used for this matter

Spike-from-NH commented 8 months ago

The way you use multiple letters is as "words" but i use them as "glyphs".

Yes; but, again, I wouldn't expect Unexpected to make this distinction.

The layout you use is more customised and user specific

Yup, that's why they call it custom layouts. Utility to someone else is a non-issue.

The Undo gesture I understand to undo an operation on selected text, if typed immediately afterward. I've never gotten the effect I want at any other time.

JRBros2346 commented 8 months ago

The Undo gesture I understand to undo an operation on selected text, if typed immediately afterward. I've never gotten the effect I want at any other time.

The undo gesture works pretty unexpectedly. It could be tweaked well, and could be used for this situation. Its not clear what it undoes

Julow commented 8 months ago

I don't think undo is the right thing. It seems that Google's keyboard knows about the Klingon language (did you install it on your device ?) and is smart about multi-code-point characters.

I'm not against supporting this, if someone is willing to implement it. The keyboard already support different scripts (eg. changing the numpad script) but it's not aware of what it types yet (except for autocapitalisation). In order to implement this, the keyboard has to look at the text, https://github.com/Julow/Unexpected-Keyboard/issues/242.

JRBros2346 commented 8 months ago

Google keyboard does not have klingon sadly, but whenever it autocorrects, or replaces a sequence of characters with another, pressing backspace undoes the autocorrection. As far as I noticed, whenever it replaces a multicharacter latin sequence with another glyph (like tamil for example) it replaces the word with Tamil letters, but the underlying text is still latin, and backspace works as if im erasing the english text. I switched to Unexpected Keyboard because Klingon doesn't have a keyboard (available ones are for older devices) and the swipe gestures are cool.

Spike-from-NH commented 8 months ago

In order to implement this, the keyboard has to look at the text, #242.

@Julow, I think it has to look at much more. Again, if I intended to type "casino" but muscle memory made me type "casing", I don't want the rubout key to take out the "n" as well on the grounds that ng is a Klingon letter! Unexpected needs to "know" the user was typing Klingon. A stack of the characters produced by the n most recent keystrokes won't even work because if @JRBros2346 moved past a tlh typed long ago, he would still expect rubout to rub out all 3 glyphs. On the other hand, sometimes I generate "they" by using my custom the gesture then rubbing out the space; I don't always want this key to erase the entire last thing typed!

And as Klingon is an invented language based on science fiction, there is no limit to the niche information Unexpected might also be asked to accommodate!

JRBros2346 commented 8 months ago

if I intended to type "casino" but muscle memory made me type "casing", I don't want the rubout key to take out the "n" as well on the grounds that ng is a Klingon letter!

The settings shall be localised to only the klingon layout, english would be unaffected. Something like setting it in the xml code

Unexpected needs to "know" the user was typing Klingon. A stack of the characters produced by the n most recent keystrokes won't even work because if @JRBros2346 moved past a tlh typed long ago, he would still expect rubout to rub out all 3 glyphs.

Klingon doesn't have "all" english letters, and some letters never occur alone. Ill give an exhaustive list: h never occurs alone, its always in end of tlh, ch or gh. note h and H are different. g doesn't occur alone, either g is followed by h or preceded by n. c always followed by h. f, k, x and z doesn't exist. ' is a character. q and Q are two different characters, Klingon latin script is case sensitive. If any of these fail, then its not Klingon.

On the other hand, sometimes I generate "they" by using my custom the gesture then rubbing out the space; I don't always want this key to erase the entire last thing typed!

We can localise the settings to only Klingon layouts

And as Klingon is an invented language based on science fiction, there is no limit to the niche information Unexpected might also be asked to accommodate!

I only want Klingon because the other alternates are for older version of android. ASK have klingon but for older version

This could also be used for any other language that have multicharacter glyphs. It could also add potential flexibility in behaviour, and not only the layout

Julow commented 8 months ago

As far as I noticed, whenever it replaces a multicharacter latin sequence with another glyph (like tamil for example) it replaces the word with Tamil letters, but the underlying text is still latin, and backspace works as if im erasing the english text.

That's an interesting behavior but it seems bounded to autocorrect. Your Klingon use case seems to require special support.

I'm open to have the keyboard support Klingon if someone's willing to implement it. Layout specific behavior are not a problem.

The behavior of the shift key can be changed with the <modmap> element but or more practical mechanism can be invented:

<keyboard>
  <modmap>
    <!-- The shift key doesn't affect q and Q. -->
    <shift a="q" b="q"/>
    <shift a="Q" b="Q"/>
  </modmap>
  ...
</keyboard>
JRBros2346 commented 8 months ago

Thats an interesting behaviour, but as of right now, i don't see a reason to include shift key, because s does not exist, but S does. Capital characters in Klingon means it sounds different to the english s. S sounds like sh. I see that Shift key only capitalizes. So i have not included Shift key in my layout. But the modmap node can be potentially used to change any button's behaviour like Ctrl, Fn, Backspace etc., I would like to see this in Unexpected Keyboard

Spike-from-NH commented 8 months ago

The behavior of the shift key can be changed with the <modmap> element

I'm enthused to learn this! My "the " and "you" swipes will now be initial-caps, not all-caps.

Julow commented 8 months ago

The shift key is useful to select text (shift + space bar sliding) and because it's the only modifier that can be changed with <modmap>. Other modifiers can't be changed but that could be added if a usecase is found.

JRBros2346 commented 5 months ago

Is there still no way to mod backspace key?

Julow commented 5 months ago

Nothing have changed in that area. Though, no customization to the backspace key have been suggested.

The idea that backspace should remove what was typed by the previous key instead of removing just one character is interesting. Anyone is interested in working on that?