Recent

Author Topic: Language keyboard  (Read 5281 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Language keyboard
« on: November 17, 2011, 09:54:06 am »
Hello guys, anyone of you tell me how can I do to track down the alphabet on the keyboard? If possible a cross-platform solution.

thanks
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Language keyboard
« Reply #1 on: November 17, 2011, 10:09:09 am »
This code is for Windows Only, but it may get you started.  It returns a Language ID number as a string.

function GetKeybLayout: string;
var
  buffer: array[0..KL_NAMELENGTH-1] of char;
begin
  if getkeyboardlayoutname(buffer) then
    setstring(result, buffer, strlen(buffer));
  else
    raise exception.create('Failed to get the layout.');
end;
« Last Edit: November 17, 2011, 10:32:03 am by Avishai »
Lazarus Trunk / fpc 2.6.2 / Win32

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: Language keyboard
« Reply #2 on: November 17, 2011, 10:14:44 am »
Thank you, someone else knows how to do it with Linux?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

zeljko

  • Hero Member
  • *****
  • Posts: 1870
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Language keyboard
« Reply #3 on: November 17, 2011, 11:16:20 am »
Yes, first read /etc/X11/xorg.conf (if exists), if not read $LANG.
But be aware of this since some distros pack keyboard info into /etc/sysconfig.
Update: keyboard info should be /etc/sysconfig/keyboard (recent distros, just checked Fedora14 and SuSe11.04) BUT ONLY /etc/X11/xorg.conf doesn't have different setup.
So, first check if xorg.conf exists, and if yes -> check if there's keyboard entry. If not , then attack /etc/sysconfig/keyboard
« Last Edit: November 17, 2011, 11:21:10 am by zeljko »

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Language keyboard
« Reply #4 on: November 17, 2011, 03:22:40 pm »
Maybe we should write a cross-platform wrapper around this and add it to Lazarus LCL.  I think this should be a commonly needed piece of information.
Lazarus Trunk / fpc 2.6.2 / Win32

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Language keyboard
« Reply #5 on: November 17, 2011, 06:23:20 pm »
On a recent ubuntu the keyboard layout is in /etc/default/console-setup and /etc/X11/xorg.conf isn't present anymore :(
Parsing the output of setxkbmap -print seems to work for most distributions.
 

 

TinyPortal © 2005-2018