Especially for international applications, it is important for an application to find out what kind of keyboard is attached. For some applications, keyboard input in multiple languages, such as Japanese and English, is necessary. In that case, the program must be able determine which keyboard is attached.

Two Windows API functions, GetKeyboardLayoutName() and GetKeyboardType(), can be used.  

The Code

Below is the code, in the CLICK event of a button, that will return these keyboard characteristics.

declare function GetKeyboardLayoutName, GetKeyboardType
kbLayoutName = Str(' ',9): char(0)

rv = GetKeyboardLayoutName( kbLayoutName)
call msg(@window , 'Keyboard layout identifier is ': kbLayoutName[1,8])

kbType = 0
rv = GetKeyboardType( kbType)
begin case
  case rv = 1
    call msg(@window, "Keyboard type: IBM PC/XT or compatible (83-key) keyboard")
  case rv = 2
    call msg(@window, "Keyboard type: Olivetti 'ICO' (102-key) keyboard")
  case rv = 3
    call msg(@window, "Keyboard type: IBM PC/AT (84-key) or similar keyboard")
  case rv = 4
    call msg(@window, "Keyboard type: IBM enhanced (101- or 102-key) keyboard")
  case rv = 5
    call msg(@window, "Keyboard type: Nokia 1050 and similar keyboards")
  case rv = 6
    call msg(@window, "Keyboard type: Nokia 9140 and similar keyboards")
  case rv = 7
    call msg(@window, "Keyboard type: Japanese keyboard")
  case 1
    call msg(@window, "Keyboard type: Unknown")
end case
kbType = 2
call msg(@window, 'This keyboard supports ': GetKeyboardType (kbType) : ' function keys.')

The call to GetKeyboardLayoutName() returns the language identifier of the keyboard in kbLayoutName.

The programs calls GetKeyboardType() twice. The first call, passing 0, returns the numeric value of the keyboard type. The second call, passing 2, returns the number of function keys supported.

The Windows API Declaration

The code above will not run until the declaration for GetKeyboardLayoutName() and GetKeyboardType() have been added.  To add the declarations, do the following:

  1. Log out of the application.

  2. Log into the SYSPROG application.

  3. Add a row, (call it DLL_APICALLS_USER32), with the first line as USER32 and containing the declarations as shown below.

    USER32
    LONG  STDCALL GetKeyboardLayoutNameA( LPCHAR) As GetKeyboardLayoutName
    LONG  STDCALL GetKeyboardType( LONG)
    //....add any other declarations in USER32 here.....
  4. Save  the row.
  5. Run Declare_FCNS at the System Editor Exec Line to create the declaration header, as shown below:

    RUN DECLARE_FCNS 'DLL_APICALLS_USER32'
  6. Exit the editor.
  7. Log out of SYSPROG.
  8. Log into your application.
  9. Run the window.