Cycling through possible accent marks by repeated keypresses

58 views
Skip to first unread message

Sassan Sanei

unread,
Jun 5, 2016, 4:57:13 PM6/5/16
to Ukelele Users
Hello, Ukelele Forum.

I am using Ukelele to create a Spanish keyboard layout. Its output consists of the regular English character set, plus these 16 special characters:

Vowels with acute accent: á é í ó ú Á É Í Ó Ú
U with dieresis: ü Ü
Eñe: ñ Ñ
Inverted punctuation marks: ¿ ¡

The existing Spanish keyboard on OS X uses various dead keys as accents, e.g. pressing ' followed by a produces á.

And the OS X approach of pressing and holding the letter to reveal all of its possible variations is a bit slow, and unfortunately does not work universally (some applications repeat the letter instead).

So, as a matter of personal preference, I would like to use the Option key to produce the special character associated with that letter. For example, Option-A to produce á, Option-N to produce ñ, etc. (I am fully aware of the historicity of ñ and that it is a distinct letter of the alphabet, and not simply an n with a diacritical mark. Option-N is still how I wish to type it. The reason is to preserve all of the non-alphabet keys of the keyboard with their existing printed labels, instead of reassigning one to ñ.)

However, I have run into a limitation with the letter U, which can take either an acute accent (ú) or a dieresis (). I want to cycle through these two possible outputs through repeated pressing of the U key while still holding down Option:

ú : Option-U (Press and hold Option, Press and release U, release Option)
Ú: Option-Shift-U (Press and hold Option, Press and hold Shift, Press and release U, release Shift, release Option)
ü: Option-U-U (Press and hold Option, Press and release U, Press and release U again, release Option)
Ü: Option-Shift-U-U (Press and hold Option, Press and hold Shift, Press and release U, Press and release U again, release Shift, release Option)

I have not found a way to do this, and reading other questions on this forum suggests that it might not be possible with a Keyboard Layout and that I would need to define an Input Method instead (something Ukelele is not designed to do).

I considered using Option-Command-U to make ü but then I can't define Option-Command-Shift-U to be Ü. Plus that could at most give me two accents per letter and I would like to extend this approach indefinitely, e.g. to create a French keyboard using the same paradigm:

é : Option-E
è : Option-E-E
ê : Option-E-E-E
ë : Option-E-E-E-E

This approach just feels more natural to me, even if it feels strange or non-standard to others.

Is this possible? Thank you for any suggestions!

Sorin Paliga

unread,
Jun 5, 2016, 5:29:53 PM6/5/16
to ukelel...@googlegroups.com
You need something, which may be labelled ‘Spanish Programmers’. You do not specify how you have been working so far: started from an existing keylayout, e.g. Spanish, or you attempted from the scratch? I guess it is the first variant. 
If I correctly understand, you do not wish any dead keys, because you interfere with the existing dead keys on a standard keylayout. So, you must first remove the dead keys, if using an existing keylayout, then build your combinations, e.g. Option+A = á and option-shift-A = Á. I guess you cannot get these keys, including ü Ü, because they are associated to a dead key, this happens on the US keylayout with  E, ` , U, I and N. Spanish has the same dead keys, but on other locations.
It is not clear to me why you had problems with the key combinations for U, I guess the dead key is ‘hidden’ if you tried to remove it.

--
You received this message because you are subscribed to the Google Groups "Ukelele Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ukelele-user...@googlegroups.com.
To post to this group, send email to ukelel...@googlegroups.com.
Visit this group at https://groups.google.com/group/ukelele-users.
For more options, visit https://groups.google.com/d/optout.

Sorin Paliga

unread,
Jun 5, 2016, 5:36:16 PM6/5/16
to ukelel...@googlegroups.com
What about choosing option-U and option-Y combinations, in oder to get the four chars you need? ú Ú ü Ü
I find this a lot easier than trying smth like opt-u-u, I do not think this is possible either.

On 05 Jun 2016, at 23:57, Sassan Sanei <sassa...@gmail.com> wrote:

Sassan Sanei

unread,
Jun 5, 2016, 9:32:08 PM6/5/16
to Ukelele Users
Thank you, Cattus Thraex. To clarify, I am starting from scratch, not modifying the existing Spanish keyboard. I create a new "Keyboard Layout in this bundle" under the + dropdown then select "Standard Keyboard Layout" then select Base keyboard layout: QWERTY" and then I redefine Option-A to be á, Option-E to be é, etc. and then repeat the process for the capital letters (Option-Shift as well as if CAPS LOCK is pressed). Therefore, I am not removing any existing dead keys.

This works well for most of the Spanish special characters, which can only be modified in one way, but not the U, because the U can take two different accents (ú or ü). Rather than create multiple dead keys for different accents (and deviate from what is physically printed on each key of the keyboard), I am trying to stick with Option as the only accent key. Therefore:

ú : Option-U
ü : Option-U-U
Ú : Option-Shift-U
Ü : Option-Shift-U-U

I have not been able to accomplish this in Ukelele. Indeed, it may not be possible. I am looking for suggestions in case there is a method that I have not considered. I appreciate the suggestion to use Option-Y for ü, but that would not feel natural to me.

If I can get this to work, I can extend it to other languages that I use, such as French, which has four different accents. I would rather press Option-E-E-E-E to get ë, instead of the more typical approach of defining Shift-' as a dead key for the ¨ then pressing Shift-', E. I realize this is not the fastest method for typing, but it is the one that feels most natural to me.

Another approach that would feel natural to me would be to use Option itself as an accent key that modifies the PREVIOUS letter, depending on how many times it is pressed. (Press and release E, then press and release Option to add an ´ accent changing the e to an é, then press and release Option a second time to change the é to an ë, etc.) but this seems impossible to accomplish using standard tools. (I did find a way to define a key to add an ´ accent to the PREVIOUS letter like pressing Option-Shift-E in the "ABC Extended" keyboard, which also feels natural, but it's not context-aware, i.e. I can't use the same key to change e to é but change n to ñ or c to ç, so I'm back to using multiple keys as accents which I really want to avoid.)

Cheers,
Sassan

Sorin Paliga

unread,
Jun 6, 2016, 1:11:54 AM6/6/16
to ukelel...@googlegroups.com
Quite clear. First, you cannot ask UKELELE to accomplish what it cannot do, therefore choose option-U and option-Y for the two instances of U: ú Ú ü Ü, it is ultimately shorter than any sequence U-U or else.
Secondly, it is easier to start from an existing keylayout, because a keylayout has other hidden, system functions, working from the scratch may easily surpass these routines.

Sorin Paliga

unread,
Jun 6, 2016, 1:15:06 AM6/6/16
to ukelel...@googlegroups.com
Corrigenda in the final part: working from an existing keylayout may easily surpass...
Mental metathesis!
On 06 Jun 2016, at 04:32, Sassan Sanei <sassa...@gmail.com> wrote:

Sassan Sanei

unread,
Jun 6, 2016, 2:36:17 AM6/6/16
to Ukelele Users
Okay, it seems like OS X is not designed to allow repeated keypresses to produce a single character (and I understand this is not a limitation of Ukelele per se). So I could use the apostrophe key to add an accent to the previous letter (U+0301) and define Option-Apostrophe to produce the apostrophe (which is very rarely used in written Spanish). Then I can use Option-U for ü and Option-N for ñ. This would preserve the correlation between the physical key labels on my English keyboard and the characters they produce. And two keypresses in rapid succesion will be slightly faster than holding down one key while pressing another.

The reason I am working from scratch is that the existing keyboard layouts do some weird things in an effort to be all things to all people, some of which I don't like. For example, the two Spanish keyboards in OS X both include a dedicated Ç key (which is not even used in Spanish), so a user on an English keyboard has no way of knowing intuitively which key produces Ç, plus they have to guess how to produce / and ? since that key is now occupied by Ç. And the « and » characters, which are used as quotation marks in Spanish, are not where one might expect them to be. My personal preference is to implement Ç as Option-C, « as Option-<, and » as Option->. There are a few other examples too, and I would rather not have to undo them all. Do you think this justifies starting from scratch, or is there another reason I should start with an existing keyboard layout? I can always hotkey-switch to a standard OS keyboard temporarily if the one I create turns out to be missing some required functionality.

Thanks,
Sassan

Sorin Paliga

unread,
Jun 6, 2016, 2:37:52 AM6/6/16
to ukelel...@googlegroups.com
As long as you do not force UKELELE to do what it cannot do, you may choose any combination you consider appropriate. 

Andrew Cunningham

unread,
Jun 6, 2016, 5:47:28 AM6/6/16
to ukelel...@googlegroups.com
Hi Sassan,

Choose the tools to suit the job. I'd probably use Keyman or Keymagic to do this. Alternatively an IME would be possible. Something like Vanilla ... although an IME would be overkill for your needs.

As has been indicated already if you wish to use Ukelele you will need to revisit your input logic.

It would be easy to do in Keyman. I have seen it done before. You just need to keep track of input context ... after first option+key ... the content becomes the ouput character ... so second key press wohld modify the character not the initial key sequence. Keymagic would follow similar principle .... but If I were you I would include an escape from tbe keylogic just in case you need to type a sequence your input logic would not make possible.

A long time ago I experimented with rotor stores in keyman ... a poor man's ime ... not sure if there are any examples still on the net.

Andrew
> --
> You received this message because you are subscribed to the Google Groups "Ukelele Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ukelele-user...@googlegroups.com.
> To post to this group, send email to ukelel...@googlegroups.com.
> Visit this group at https://groups.google.com/group/ukelele-users.
> For more options, visit https://groups.google.com/d/optout.
>

--
Andrew Cunningham
lang.s...@gmail.com



Tom Gewecke

unread,
Jun 6, 2016, 6:24:03 AM6/6/16
to ukelel...@googlegroups.com

> On Jun 6, 2016, at 5:47 AM, Andrew Cunningham <lang.s...@gmail.com> wrote:
>
> Hi Sassan,
>
> Choose the tools to suit the job. I'd probably use Keyman

Is there now a way to create Keyman layouts on a Mac?

Gé van Gasteren

unread,
Jun 6, 2016, 9:50:07 AM6/6/16
to ukelel...@googlegroups.com
@Andrew, Tom:
According to the Tavulte site, Keyman is available for Mac, but Keyman Developer (which Sassan would need) is only available for MS Windows and it costs 200 USD!
I don’t know about Keymagic.

@Sassan:
The main problem with using keyboard layouts for your intended way of typing is that the OS doesn’t remember characters typed before.
Once you have typed
ú : Option-U (Press and hold Option, Press and release U)
the OS forgets everything that happened.
In other words: holding down the Option key doesn’t tell the OS you haven’t finished typing yet.

You could do it the other way around though: pressing the spacebar to tell the OS you have finished the sequence.
This would need ‘nested’ levels of dead keys for the different accents, and typing the accent *after* the base letter.
So for example, if there are only two levels for the u (ú and ü) you could type like this:
ü : Press and release U, Press and release ´, Press and release ´
and ú would be typed like this:
ú : Press and release U, Press and release ´, Press and release spacebar

Of course, this means you’d still have to type the keystroke for the accent, not for the letter, so it’s not quite what you wanted. But there would be only one key on the entire keyboard for all the accents, e.g. the ` key top left, or the \ next to the Z key.

Sassan Sanei

unread,
Jun 6, 2016, 3:14:58 PM6/6/16
to Ukelele Users
Andrew: Thank you for the suggestion about Keyman, Keymagic, and Vanilla. I will explore these possibilities, although at initial glance they seem to require more development effort than I can put in at the moment.

Geke: I really like your idea with nested levels of accents, requiring only one physical key to produce all possible accent marks. If I understand your suggestion correctly, this would mean using the letter key itself as a dead key. My hesitation is the need to press the spacebar afterward. I could work around this by looking for any other keypress. So for example, if the ideal way to write aún is AU'N then the nested deadkey state for ' under U would look at the next keypress and if it's anything other than ' it would produce ú followed by that letter, i.e. ús. The next level would do the same but with ü instead. This could lead to an extremely complex keymap, and I'm not sure how to get two accented characters in a row using this method, although from a practical requirement that doesn't happen in Spanish. Just for fun, I tried implementing each vowel as a dead key last night, creating a French keyboard where pressing E then ' gives é, pressing E then " gives ë, etc. and also pressing O then E produces the œ ligature. I then tested it with the word "Noël" by typing Shift-N, O, E, ", L. Instead of producing Noël, it produced Nœ"l which gave me a good laugh! Of course, it has no way of knowing which one I intend. Perhaps it is this kind of ambiguity that led to the convention of typing the accent BEFORE the letter it modifies. Anyway, it's fun.

Sassan

Gé van Gasteren

unread,
Jun 6, 2016, 5:01:50 PM6/6/16
to ukelel...@googlegroups.com
Hi Sassan,

You’re right, on second thoughts the spacebar isn’t really necessary!
Sorry if I didn’t describe it clearly, but in the setup I suggested the letter keys are not dead keys, they are typed as on a regular keyboard – only the one key on the keyboard through which you want to type the accents should be a dead key.

Why you don’t need the spacebar:
Every dead-key state has a "terminator" character, which is inserted if, after the dead key, a non-assigned key is pressed.
So your sequence AU'N would indeed produce aún if you had assigned a dead key to the ' key with its terminator character being <combining acute accent>.
Because there are only two possibilities for the U, you wouldn’t even need nested dead keys:
For the sequence AU''N to produce aün you would only have to define
1.   the ' key as a dead key with terminator character <combining acute accent>
2.  the ' key *inside the above dead-key state of  '  * to produce <combining diaeresis accent>.

Only if there are more than two possibilities, like what you wanted for French, you would need to define nested dead-key states, one level deeper for each additional keystroke.
I’ve never done this, but you can see it in action in the built-in Mac keyboard layout "Unicode Hex Input": Hold down the Option key and press four hex digits/letters to produce the character at that Unicode code point. So these are three nested levels of dead keys.

The OS certainly has a way to know what you intend, or let’s say a fixed way to interpret your keystrokes. If you don’t want O E to produce œ then you shouldn’t type them in that sequence :-) e.g. you could type O space backspace E to make the OS forget about the O.


--

Andrew Cunningham

unread,
Jun 6, 2016, 6:16:21 PM6/6/16
to ukelel...@googlegroups.com

Keymagic is opensource. Developers by Myanmar developers to meet the needs of their languages.

Available on windows, osx, linux.

At the moment keyman is in transition. It is no longer owned by Tavultesoft per se. It is transitioning to its new owners: SIL International. I don't know what their plans are. Whether to keep Keyman commercial or make it free or opensource.

I mentioned it as a possibility. Things are in flux.

I know the developer had further plans for OSX, but .... depends now on the new owners ...

John Brownie

unread,
Jun 6, 2016, 7:48:53 PM6/6/16
to ukelel...@googlegroups.com
On 6/06/2016 19:47, Andrew Cunningham wrote:
> Choose the tools to suit the job. I'd probably use Keyman or Keymagic
> to do this. Alternatively an IME would be possible. Something like
> Vanilla ... although an IME would be overkill for your needs.
>
> As has been indicated already if you wish to use Ukelele you will need
> to revisit your input logic.
>
> It would be easy to do in Keyman. I have seen it done before. You just
> need to keep track of input context ... after first option+key ... the
> content becomes the ouput character ... so second key press wohld
> modify the character not the initial key sequence. Keymagic would
> follow similar principle .... but If I were you I would include an
> escape from tbe keylogic just in case you need to type a sequence your
> input logic would not make possible.
>
> A long time ago I experimented with rotor stores in keyman ... a poor
> man's ime ... not sure if there are any examples still on the net.


There are some things that are possible with keyboard layouts that
Ukelele doesn't currently handle. I recently revisited an assumption
made over a decade ago, which turns out to be invalid. Basically, it is
possible to have a dead key which has both output and a transition to a
dead key state. This might enable the original request.

Sadly, this won't make it into Ukelele for quite some time. I have begun
a project to rewrite again, this time with Swift (and other more recent
OS X technologies), enabling this option, but it's a long way from
finished. In the coming months I might have more time to devote to this,
and possibly port it back to Ukelele 3.x, but we'll see how this goes.

John
--
John Brownie, john_b...@sil.org or j.br...@sil.org.pg
Summer Institute of Linguistics, Ukarumpa, Eastern Highlands Province,
Papua New Guinea
Mussau-Emira language, Mussau Island, New Ireland Province, Papua New Guinea

Tom Gewecke

unread,
Jun 7, 2016, 6:10:09 AM6/7/16
to ukelel...@googlegroups.com

> On Jun 6, 2016, at 3:14 PM, Sassan Sanei <sassa...@gmail.com> wrote:
>
> Perhaps it is this kind of ambiguity that led to the convention of typing the accent BEFORE the letter it modifies.

I think that convention is actually inherited from mechanical typewriters, where accents had to be made by typing them without advancing the carriage.

Sassan Sanei

unread,
Jun 7, 2016, 11:10:38 AM6/7/16
to Ukelele Users
@Geke: Your suggestion works perfectly! Thank you. Outputting E followed by U+301 COMBINING ACUTE ACCENT creates  which has the exact same Unicode U+00C9 LATIN CAPITAL LETTER E WITH ACUTE as an é formed natively on a Spanish keyboard.

Unfortunately, the Duolingo web site does not recognize letters formed through the use of Unicode combining accents. This also happens with the ABC Extended keyboard that is standard with Mac OS (which produces Combining Acute Accent when the user presses Option-Shift-E), so the problem isn't with the keyboard I created in Ukelele. I will contact the Duolingo developers to investigate further.

Another problem with using the apostrophe as a Combining Acute Accent key is that when typing in English, typing WON'T results in WOŃT. This is a great example of where it would be useful to know the previous letter -- apostrophes tend to follow consonants, not vowels that take an accent, so the ambiguity could be resolved by knowing the previous letter. I could make A E I O U dead keys; if followed by ' then output á é í ó ú (and apply your suggestion to nest a second dead key state for ' to allow ü) but if followed by any other key then the output is the initial vowel plus the second key. But this would pose a problem for words like leímos which take an accent on the second vowel unless I can somehow program the keyboard to output a letter then enter a different dead state (instead of output a letter and return to root level) i.e. press E takes you into dead state E, press I outputs e and takes you into dead state I, press ' outputs í and takes you into root level, but I think as soon as it outputs e it goes to root level with no option to enter a different dead state.

@John: You wrote: "Basically, it is possible to have a dead key which has both output and a transition to a dead key state." This could enable the option I just described! How did you discover this, if not in Ukelele? Through manually editing the .XML file?

Gé van Gasteren

unread,
Jun 7, 2016, 11:23:14 AM6/7/16
to ukelel...@googlegroups.com
@Sassan:
It’s better to dedicate one key just to the accent(s), instead of what you tried: to let the quote key do double duty. But you have already found that out yourself :-)

To illustrate: I’m using the extra key on my ISO keyboard (between left shift key and the Z key) for this; you may want to use the key top left on the keyboard or any other that seems handy.

John is Ukelele’s main/only developer; he knows "everything" about keyboard layouts and Mac OS X features and quirks. But what he means by "basically" is that the XML syntax for keyboard layouts allows such a feature, only it’s not implemented in Ukelele’s user interface. Until he gets around putting it in, that is.

--

Gé van Gasteren

unread,
Jun 7, 2016, 11:26:20 AM6/7/16
to ukelel...@googlegroups.com
You’re right: that feature of merging base letters + combining accents into the Unicode code points for the precomposed accented letters doesn’t work everywhere. It came up fairly recently, so hopes are up that it will become more widely supported in time.

Sassan Sanei

unread,
Jun 7, 2016, 12:54:46 PM6/7/16
to Ukelele Users
@Geke: My (Canadian English) Mac keyboard has one fewer key than your keyboard. I chose this keyboard because I have a tendency to hit that extra key between Left-Shift and Z whenever I reached for Shift.

If I were to design a physical keyboard from scratch, I would put a row of accent keys below the space bar, and use my thumbs to activate them.

Just thinking out loud here, but it occurs to me that I rarely use the [{ ]} \| keys. I could physically remove the keys and swap them in the order \| [{ ]} and make the \| the accent key using Ukelele. It would be right next to the P, so my pinky wouldn't have to reach far to press it, thus keeping ;: and '" in their original places and for their intended purpose which I have grown used to over many years. It's hard to retrain the brain for typing... I do, on occasion, still press Shift-8, Shift-9 for () and Shift-2 for " because that's how it was on my Commodore 64 keyboard from 30 years ago!

Gé van Gasteren

unread,
Jun 7, 2016, 5:07:58 PM6/7/16
to ukelel...@googlegroups.com
Your thinking is correct; I’d also take something like the backslash, or maybe even better: the `/~ key top left on your keyboard. But wait, you didn’t want to reach far... then yes, the   \ is great.

"from scratch": I remembered you once asked why it's preferred to start from an existing keyboard. Well, there's lots of things under the hood one doesn't need to do/know when doing that. It's not more work anyway.

Good luck!

--

sil.linguist

unread,
Jul 1, 2016, 3:21:31 AM7/1/16
to Ukelele Users
@Sassan, 

You suggest that:
"Outputting E followed by U+301 COMBINING ACUTE ACCENT creates  which has the exact same Unicode U+00C9 LATIN CAPITAL LETTER E WITH ACUTE as an é formed natively on a Spanish keyboard."

Be aware that this is not the case. Unicode has canonical equivalents. This means that applications on an OS should treat the data as being the same. It does not mean that the data is actually treated the same. It is up to the application developer to apply the canonical equivalent rules for text processing in their apps. Various OSes will treat these things differently on save. If all you are ever looking for is how it prints to the screen then you will not have a problem, but if you want to search or end up coping and pasting other text into your document then the text may not be the same as what you type. 

 - Hugh Paterson

Aural Architect

unread,
Mar 20, 2017, 3:06:04 PM3/20/17
to Ukelele Users
Hello Sassan!


Actually, if I am understanding you correctly (and I believe I am)- what you are suggesting is entirely possible- I've done something equivalent myself. It's just a matter of creating nested deadkeys. Now you won't be able to actually "cycle" through (circularly) like you can with Keyman.  But you simply create a deadkey whose terminator is the first character.  Then create a nested deadkey on the same key whose terminator is the second character.  So [option]u produces ú and [option][u][option][u] produces ü  (or you could make the second nested deadkey just on plain (no option) [u] to produce ü.  Since native Spanish words do not to my knowledge utilize orthographic double vowels, you will not run into any instances of undesired, unexpected behavior- but even that could be mitigated by where you map the nested deadkey (whether with or without the [option] key or something similar).  You can obviously nest deadkeys deeper if you like- I'm not sure of the limit.  However, it seems that at some point it would be easier to map the various output characters to other keys within the first deadkey layer...
If I am completely missing something, and this is not helpful; hopefully someone may find it helpful...
Reply all
Reply to author
Forward
0 new messages