Skip to main content
Kofax

Change Keyboard Language in KTM Validation

17231 17243
3011109

Question / Problem: 

Is it possible to switch the keyboard language in KTM Validation?

Answer / Solution: 

It is possible to set different keyboard layout using KTM Scripting. The sample code below changes the keyboard language to Arabic when validating "Field3". Validation for all other fields will be in English. 

Attached is a KTM project that runs the script below. Note the project is saved in KTM 6.2.1.0.

Public Declare Function GetKeyboardLayoutName Lib "user32" Alias "GetKeyboardLayoutNameA" (ByVal pwszKLID As String) As Long
Public Declare Function LoadKeyboardLayout Lib "user32" Alias "LoadKeyboardLayoutA" (ByVal pwszKLID As String, ByVal flags As Long) As Long

Const KLF_ACTIVATE = &H1
' some languages code
Public Const LANG_ENGLISH As String = "00000409"
Public Const LANG_FRENCH As String = "0000040C"
Public Const LANG_ARABIC As String = "00000401"
Public Const LANG_GREEK As String = "00000408"
Public Const LANG_ITALIAN As String = "00000400"
Public Const LANG_GERMAN As String = "00000407"

Public Function SwitchKeyboardLang(ByVal strLangID As String) As Boolean
   'Returns TRUE when the KeyboardLayout was set properly, FALSE otherwise
   Dim strRet As String
   On Error Resume Next
   strRet = String(9, 0)
   GetKeyboardLayoutName strRet
   If strRet = (strLangID & Chr(0)) Then
      ' you are try to switch to the already selected language
      ' so return without doing anything
      SwitchKeyboardLang = True
      Exit Function
   Else
      strRet = String(9, 0)
      Dim res As Long
      res = LoadKeyboardLayout((strLangID & Chr(0)), KLF_ACTIVATE)
   End If
   GetKeyboardLayoutName strRet ' Test if switch successed
   If strRet = (strLangID) Then SwitchKeyboardLang = True
End Function

Private Sub ValidationForm_FieldGotFocus(ByVal pXDoc As CASCADELib.CscXDocument, ByVal pField As CASCADELib.CscXDocField)
   Select Case pField.Name
      Case "Field3"
         SwitchKeyboardLang(LANG_ARABIC)
      Case Else
         SwitchKeyboardLang(LANG_ENGLISH)
   End Select
End Sub

Applies to:  

Product Version Category
KTM 6.3 Scripting
KTM 6.2 Scripting