Deadkeys (combos) don't work properly. #79

Open
outsideMyBox opened this Issue Jun 21, 2012 · 17 comments

Projects

None yet

3 participants

@outsideMyBox

Hi,
First thanks for this great library. It's (almost:)) what I was looking for for my project.
I think the mechanism to enter diacritics should be revised as it has annoying side effects at the moment.

For example if you take the international keyboard from the demo (http://mottie.github.com/Keyboard/index.html)
Entering '^' + 'e' displays 'ê' (which is fine) but if I type 'e' and then add a '^' before '^e' is also transformed, which shouldn't be the case.
In general the code replaces all the strings it finds that match keyboard.comboRegex, so it's basically impossible to enter the string "^e".
A more suitable mechanism would be perhaps to test for each character entered if it's a dead key and display the correct character depending on both the next character entered and the mapping from the property 'combos'.
A deadkey could be escaped by entering 'space' as described in http://en.wikipedia.org/wiki/Dead_key.

I may have a look as well to further dive into the source code.

Thanks!
Franck

@Mottie
Owner

Hi Franck!

There is a {combo} key that you can add to the keyboard to toggle the automatic formation of diacritics. It's not perfect in that once it is enabled again, all matching combinations will be formed - see the Custom: Junk demo for the ö key.

Additionally, the useCombos option can be set to false to completely disable this feature.

If neither of those methods work, I am open to suggestions on how I can change the keyboard to work better.

@outsideMyBox

Hi Mottie,

I actually need the diacritics! I came up with a first solution which is kind of a proof of concept and only works for characters entered from the physical keyboard, not the virtual one by clicking on the keys.
I've forked the project and it's available at https://github.com/outsideMyBox/Keyboard (jquery.keyboard.js and demo.js have been modified).
Only the first example of the demo (QWERTY text) uses it. To do so a new option keyboard.deadkeys has been added (useCombos must be set to false as well).

Franck

@Mottie
Owner

Sorry I haven't gotten back to you, but I do like your idea of checking the input for the last keys pressed instead of the entire input. WIth that change, the {combo} key would be more useful.

I still have a few projects I need to catch up on, but I'll look into a modification using this method soon. Thanks!

@Mottie
Owner

Hi Franck!

In the latest update (v1.10), I've modified how combo keys are detected. Now only the left two characters are checked for dead key combinations. So if you enter something like ee then move the caret in front of the first e and type in an accent like an apostrophe ', you'll end up with 'ee instead of ée. Of course, it would be even easier to use the {combo} key to toggle the check.

I hope this change makes the dead keys more useful for everyone :)

@outsideMyBox

Hi Mottie,

sorry for the late reply. I haven't tried your solution yet but I see an usability issue: this mechanism is different from the one typically used to enter diacritics by pressing + or to disable the functionality by pressing + . (I use it daily to enter French or German diacritics on a English keyboard).
My solution works for me so far (see outsideMyBox@23aa221) but is not compatible with the current mechanism used by the option useCombos (hence useCombos : false in my example) so it may be confusing to keep both. The option useCombos could be replaced by deadKeys but that could be an compatibility issue for the users already using useCombos (I'm not sure many users use it though).

Franck

@Mottie
Owner

So if I enter a dead key then press space to cancel it from being a combination, does it enter a space or not?

An issue with that method would be that if you add content to the keyboard externally, it wouldn't be able to determine what should or should not become combined. This is especially a problem with the typing extension. For example, I paste in the following into the keyboard - hell^o world​​​​​​​​​ there wouldn't be any way to make that diacritic. Right now, you can just click to move the caret after the o and it will combine.

@outsideMyBox

it's how it works:
if in the configuration you have
deadKeys : { '^' : { a : "â" } }
then
'^' + 'a' => â
'^' + [space] => '^' ( [space] is used as a means to enter the character '^'. It's the usual way to do it).
'^' + 'e' => '^e' ('e' is not in the configuration so in this case both '^' and 'e' are displayed. It's also the usual behavior used by various keyboard layouts).

As for the the issue you mentioned I think it's not an issue but a feature :) . Dead keys are used to easily enter special characters while typing. For the typing extension the pasted text (created with another text editor) should already contain the character with diacritics (hellô word).
The actual option useCombos seems to be used for some kind of post-processing on the text entered which is not ideal to enter diacritics 'on the fly' but perhaps I miss a use case here.

I'd like to know what the users of this library think about it. The new option can be tested by cloning my branch and using the first example of the demo (QWERTY text). The letters with diacritics are enclosed by brackets for test purpose ('^' + 'e' => '[^e]')

@outsideMyBox

Oups, just forget my comment about typing extension. I've just realized it allows us to simulate typing into the keyboard.
Perhaps this extension should behave the same way as when a user enters characters but I haven't check how to do it.
My modifications don't work when a user enters characters by clicking on the keys either (I haven't fully understood yet how the code works :))

@Adikku

Hey guys.
I have an issue with the "ü" combos.. Cant seem to get them to work.
I added the combinations to letters a,e,i and u but they dont combine. Default is using " and u to get ü. This cant be right, can it? If I want to quote "user" it would result üser".

Any who, I guess these are two bugs or questions. The one Im focused on is how to make use of combinations to get letters like ü, ë and so on.

I tried:
' ¨ ' : {e:"\u00eb", E:"\u00cb", i:"\u00ef", I:"\u00cf", o:"\u00f6", O:"\u00d6", u:"\u00fc", U:"\u00dc", y:"\u00ff", Y:"\u0178" }

@Mottie
Owner

Hi @Adikku!

Currently, the way combo keys are checked is that it looks at the last two typed keys, if they match the combo pattern, the letter changes. This may not exactly match how dead keys work (space to cancel the combo), but hopefully someday when I have the time, I'll make them work this way.

Anyway, all of the default umlaut combos work for me (click the keyboard icon next to the input in this demo).

There are two ways to type in "user":

  • Use the combo key (ö) to toggle the dead key combinations (included in the above demo, bottom row)
  • Type in " u" ("spaceu) then move the cursor left once (), backspace () to remove the space between the quote and the u, move the cursor right () once and continue typing. I know this isn't ideal, but as stated, I'll fix it when I have time.
@Adikku

Hey Mottie,
The "user" part isn't all that critical for the keyboard Im working on. Main issue is typing ü. If I type " u I get ü. But I need it to use ¨ u instead. (u00a8). I tried to simply replace that in the combos section, but it didnt help.

Do you mean that this is something you need to look at when you find the time?

@Mottie
Owner

Why not just turn off the combos? Set the useCombos option to false.

@Adikku

How would I then enable the user to use those characters? If I add the keys for those characters, the keyboard layout would be to large.

@Mottie
Owner

Just include the {combo} key in your layout... that will allow the user to toggle the useCombos option.

I was just typing in this bit of information in case you wanted to completely remove the umlaut combo by changing the default options:

$.keyboard.defaultOptions.combos['"'] = null;
// removing quote from regex for completeness
$.keyboard.comboRegex = /([`\'~\^ao])([a-z])/mig;

Edit: Someday, I'd like to add a toolbar-like row/header to the table which includes the combo key, language selector, etc...

@Adikku

Yay!
There was an easier way to get it to work (for my needs)
I simply changed $.keyboard.comboRegex = /([`\'~\^\"ao])([a-z])/mig; to $.keyboard.comboRegex = /([`\'~\^\¨ao])([a-z])/mig;` which did the trick.

Case closed for me :)
Thanks Mottie!

@Mottie
Owner

Great!

I just wanted to emphasize that the reason this keyboard uses quotes is because you can't type an umlaut on the standard U.S. keyboard without using Alt + keypad numbers (148 for ö) . So changing the regex to only work with an umlaut means you're only targeting users that can type that character.

@Adikku
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment