Set default keyboard layout (for other language) for a field

Igor de Oliveira Couto igor at semperuna.com
Mon Feb 18 23:42:35 EST 2013


An alternative:

On 19/02/2013, at 12:39 PM, Jonathan Cooper <drdada at gmail.com> wrote:

> Or, failing that, to
> have Livecode automatically set the keyboard layout as soon as the field is
> opened?

That may not be always reliable, as in some systems - like the Mac - the user has to explicitly 'enable' the keyboard layout (in System Preferences), for it to be available. There is, however, a more 'low-tech' solution. 

Many years ago, before people were able to easily type accented letters on the internet, it was common to see an 'alternative' Esperanto spelling, which used 'x' - a letter that doesn't exist in Esperanto - where an accent should be used. So, for instance, instead of typing "ĉ", the user would type "cx". Instead of typing "ŭ", the user would type "ux". 

I remember, that I developed an online forum that scanned for the appropriate letter combinations in user posts (cx, gx, hx, jx, sx and ux), and automatically replaced them with the 'correct', accented characters: ĉ, ĝ, ĥ, ĵ, ŝ and ŭ. 

In Livecode, this kind of 'search-and-replace' could be done quite easily in a field script - either on 'textChanged', or on 'closeField'. I imagine something like this would do:

on closeField
 // because we cannot hard-code unicode characters into our script
 // it's easier to use the 'htmlText' property to deal with unicode chars:
 local tHTMLContent
 put the htmlText of me into tHTMLContent
 
 // replace all the x-letters with their equivalent html entities:
 replace "cx" with "ĉ" in tHTMLContent
 replace "CX" with "Ĉ" in tHTMLContent
 replace "gx" with "ĝ" in tHTMLContent
 replace "GX" with "Ĝ" in tHTMLContent
 replace "hx" with "ĥ" in tHTMLContent
 replace "HX" with "Ĥ" in tHTMLContent
 replace "jx" with "ĵ" in tHTMLContent
 replace "JX" with "Ĵ" in tHTMLContent
 replace "sx" with "ŝ" in tHTMLContent
 replace "SX" with "Ŝ" in tHTMLContent
 replace "uxx" with "ŭ" in tHTMLContent -- we don't want to have problems
 replace "UXX" with "Ŭ" in tHTMLContent -- with English words like 'auxiliary'...
 
 // put the replaced text back in the field:
 set the htmlText of me to tHTMLContent	
end closeField

This already provides a workable solution. For an more polished user experience, you can try developing a script that is more forgiving when the user mixes upper- and lower-case 'x's, like "Cx" and "cX". You can also try to develop a script that would do the replacing on 'textChanged' rather than on 'closeField', but you will then have to use 'the selectedChunk' and some basic maths in order not to loose the user's insertion point place in the text, as you replace the characters.

I hope this helps!

Kind regards,

--
Igor Couto
Sydney, Australia








More information about the use-livecode mailing list