[fpc-pascal] keyboard layout.
Marco van de Voort
marcov at stack.nl
Sun Nov 21 11:56:07 CET 2004
> We are having a problem with keyboard layouts in the keyboard unit in windows.
> Currently it is automatically assumed that both alt keys differ.
>
> So this is a small poll:
>
> What is your Windows keyboardlayout, and are your two alt keys different (ALT-GR system)?
>
> Me:
>
> Layout: ALT-GR ?
> US no
Florian dug up some C++ code that I tried to convert. Could sb try to run this on his windows
machine, and check if the ALT-GR status is detected correctly.
Please also mention your windows version, since I found notes here and there that some aspects
of keyboardlayouts are NT specific.
program printlayout;
{$mode delphi}
Uses SysUtils,Windows;
// Checks if the right-hand ALT key is used as a 2nd shift key
var hklold : HKL = 0;
var HasAltGr : Boolean = false;
procedure CheckAltGr;
var ahkl : HKL;
i : integer;
begin
HasAltGr:=FALSE;
ahkl:=GetKeyboardLayout(0);
if (hklOld<>ahkl) then
Begin
hklOld:=ahkl;
i:=$20;
while i<$100 do
begin
// <MSDN>
// For keyboard layouts that use the right-hand ALT key as ashift key
// (for example, the French keyboard layout), the shift state is
// represented by the value 6, because the right-hand ALT key is
// converted internally into CTRL+ALT.
// </MSDN>
if (HIBYTE(VkKeyScanEx(chr(i),ahkl))=6) then
begin
HasAltGr:=TRUE;
break;
end;
inc(i);
end;
end;
end;
begin
writeln(hexstr(getkeyboardlayout(0),8));
CheckAltGr;
if HasAltGr then writeln(' Has altgr') else writeln('shouldn''t have alt-gr');
end.
More information about the fpc-pascal
mailing list