// Es wird zwischen rechter und linker Shift- bzw. Strg-Taste unterschieden.


// Getestet mit D2010 unter Win7
 

function Taste: byte; 
const 
  a = $FFFF8080; 
var 
  b: array [0 .. 2] of boolean; 
  i: integer; 
  s: array [0 .. 5] of boolean; 
begin 
  result := 0; 
  for i := 0 to 2 do 
    b[i] := GetKeyState(i + 16) and a <> 0; 
  for i := 0 to 5 do 
    s[i] := GetKeyState(i + 160) and a <> 0; 
  if GetKeyState(20) and a <> 0 then 
    result := 1 
  else if s[0] and b[0] then 
    result := 2 
  else if s[2] and b[1] and not b[2] then 
    result := 3 
  else if s[3] and b[1] then 
    result := 4 
  else if s[1] and b[0] then 
    result := 5 
  else if s[4] and b[2] then 
    result := 6 
  else if s[2] and b[1] then 
    result := 7; 
  if result = 6 then 
  begin 
    keybd_event(vk_menu, 0, 0, 0); 
    keybd_event(vk_menu, 0, keyEventF_keyUp, 0); 
  end; 
end; 
 
procedure TForm1.FormCreate(Sender: TObject); 
begin 
  KeyPreview := True; 
end; 
 
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; 
  Shift: TShiftState); 
begin 
  case Taste of 
    1: 
      Label1.Caption := 'linke Feststell-Shift'; 
    2: 
      Label1.Caption := 'linke Shift'; 
    3: 
      Label1.Caption := 'linke Strg'; 
    4: 
      Label1.Caption := 'rechte Strg'; 
    5: 
      Label1.Caption := 'rechte Shift'; 
    6: 
      Label1.Caption := 'Alt'; 
    7: 
      Label1.Caption := 'Alt Gr'; 
    else 
      Label1.Caption := ''; 
    end; 
end; 

 


 

Zugriffe seit 6.9.2001 auf Delphi-Ecke