manage accented chars from keyboard

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

manage accented chars from keyboard

Post by jmburnod » Sat May 30, 2015 3:03 pm

I'm looking to manage the accented letters input from keyboard.
I wrote a function that works but I'm wondering if there is not a simplest or more elegant way

Code: Select all

local sKeyUpSpec
on rawkeyup pKey
   if the uMyjeu of this cd = "TexteAvecTrous" then
      if pKey is in "43,61,93" then--- "43 graveOnly,61 circumflex, 93 trema"
         put pKey into sKeyUpSpec
      end if
   end if
   pass rawkeyup
end rawkeyup

on keyUp pKey
   answer getLetterAccentSpec(pKey)
   ClearsKeyUpSpec
end keyUp

function getLetterAccentSpec pKey,pSpec
   put "61,93,43" into tAccentSpec
   if sKeyUpSpec <> empty then
      put itemoffset(sKeyUpSpec,tAccentSpec) into tAccentSpecFound
      if tAccentSpecFound = 0 then return pKey
   end if
   put "aâä,eêë,iîï,oôö,uûüù" into tLetterTarget
   put itemoffset(pkey,tLetterTarget) into tLetterFound
   if tLetterFound = 0 then return pKey
   put char (tAccentSpecFound + 1) of item tLetterFound of tLetterTarget into tLetterAcc
   return tLetterAcc
end getLetterAccentSpec

on ClearsKeyUpSpec
    put empty into sKeyUpSpec
end ClearsKeyUpSpec
Best regards
Jean-Marc
https://alternatic.ch

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10089
Joined: Fri Feb 19, 2010 10:17 am

Re: manage accented chars from keyboard

Post by richmond62 » Sun May 31, 2015 4:47 pm

This is a start to your problem using Function keys:

I have set things up ONLY for one character: à

as a proof of concept.

You need 3 field called "KODE3", "KEYZ" and "KEYZZ" and this in the cardScript:

on functionKey FK
put the keysdown into fld "KEYZ"
end functionKey

on keyDown
put empty into fld "KODE3"
set the useUnicode to true
put the keysdown into fld "KEYZZ"
if fld "KEYZ" contains "65470" then
if fld "KEYZZ" contains "97" then
set the unicodeText of fld "KODE3" to numToChar(224)
end if
end if
end keyDown

So first you press F1 and then 'a'.

Obviously you can extend this, so that F2, F3, F4 . . . can signal different diacritical marks,

and you can expand inside the loops to allow diacritical marks on other letters.

Post Reply