keyboard in use

I have a textField that, according to certain conditions, should accept only text in Hebrew, according to other conditions only Bengali, or only Greek etc.
For instance, to detect if the user is typing using the Bengali keyboard, at present I have this snipped in the keydown event of the textField, where kBanglaGlyphs is a constant string containing the Bengali alphabet; to detect other languages I have other constants containing the alphabet of other languages.
if key = instr(kBanglaGlyphs, key) > 0 then
Return false//allow
end if
if key = instr(kHebrewGlyphs, key) > 0 then
Return false//allow
end if
//etc. for each language

Does anybody have code for Mac and win32 that tells which keyboard is in use at a particular time?
As far as I know, MacOSlibrary doesnt seem to have something of this kind; but I may have overlooked it.
Of course, preferredLanguage is not the solution for what I need.
No plugins, please.
Thanks, Carlo

http://askstop.com/questions/881306/determine-os-x-keyboard-layout-input-source-in-the-terminal-a-script

?n Yosemite the terminal script is not able to execute for permission reasons.
The AppleScript works OK, but I fear MAS wont allow it since there is a call to System Events.
But from both terminal and apple scripts I’ve come to know where to look (Library > Preferences > com.apple.HT…), hoping for MAS to allow us extracting info from user library.
Thanks.