Keyboard Detection?

Scott Rossi scott at tactilemedia.com
Fri Dec 11 18:41:31 EST 2009


Recently, Richmond Mathewson wrote:

> I wonder if there is any way of telling:
> 
> 1. The default language of an end-user's computer?

Here's a function I've used which has worked on Windows from Win95 up
through Vista (not tested on Win 7);  for Mac, has worked last few OS
versions up through Show Leopard, but not sure how far back is supported.
Try it and see if it works for you (watch line wrapping):

# RETURNS LANGUAGE INFO ABOUT HOST OPERATING SYSTEM
# WINDOWS - RETURNS
# -- COUNTRY DESIGNATION
# -- 3 CHAR LANGUAGE CODE
# -- 8 CHAR LOCALE HEX CODE
# -- 4 CHAR LOCALE DECIMAL CODE
# MAC - RETURNS
# -- CURRENT SYSTEM LANGUAGE
# -- AVAILABLE SYSTEM LANGUAGES

function langSpecs
   if "win" is in platform() then
      if word 1 of systemVersion() = "Windows" then
         put url ("file:" & specialFolderPath(system) & "/win.ini") into
tSystem
         set itemDel to "="
         put item 2 of line (lineOffset("sCountry",tSystem)) of tSystem & cr
after tData
         put item 2 of line (lineOffset("sLanguage",tSystem)) of tSystem &
cr after tData
      else
         put queryRegistry("HKEY_CURRENT_USER\Control
Panel\International\sCountry") & cr after tData
         put queryRegistry("HKEY_CURRENT_USER\Control
Panel\International\sLanguage") & cr after tData
      end if
      put queryRegistry("HKEY_CURRENT_USER\Control
Panel\International\Locale") & cr after tData
      put baseConvert(line 3 of tData,16,10) after tData
      return tData
   end if
   if "mac" is in platform() then
      put "defaults read -g" && quote & "AppleLocale" & quote into tCmd
      put shell(tCmd) into currLang
      put replaceText(shell("defaults read NSGlobalDomain
AppleLanguages"),"(\s|\(|\))","") into availableLangs
      return currLang & cr & availableLangs
   end if
   return languagesList
end langSpecs



Regards,

Scott Rossi
Creative Director
Tactile Media, Multimedia & Design





More information about the use-livecode mailing list