Einzelnen Beitrag anzeigen

taaktaak

Registriert seit: 25. Okt 2007
Ort: Radbruch
1.990 Beiträge
 
Delphi 7 Professional
 
#1

WM_KEYDOWN in ApplicationEventsMessage()

  Alt 10. Dez 2011, 11:54
Delphi-Version: 7
Moin, Moin.

Ich muss mit TApplicationEvents Tastatureingaben (incl. Tastenkombinationen) auswerten. Je nach Tastenkombination werden verschiedene MenuEinträge oder Speedbuttons aufgerufen. Meine Lösung ist ...
Delphi-Quellcode:
procedure TfoMain.ApplicationEventsMessage(var Msg:tagMSG;var Handled:Boolean);
var Shift : TShiftState;
    Key : Word;

 procedure GetShiftState(var Shift:TShiftState);
 var KeyboardState : TKeyboardState;
 begin
  Shift:=[];
  GetKeyboardState(KeyboardState);
  if (KeyboardState[vk_Shift] and 128=128) then Shift:=Shift+[ssShift];
  if (KeyboardState[vk_Control] and 128=128) then Shift:=Shift+[ssCtrl];
  if (KeyboardState[vk_Menu] and 128=128) then Shift:=Shift+[ssAlt];
 end;

begin
 if Msg.message=WM_KeyDown then begin

  GetShiftState(Shift);
  Key:=Msg.wParam;

  if Shift=[] then // ...................................................... xx
   case Msg.wParam of
    vk_F1 : begin m_HelpCommandsClick(nil); Handled:=true end;
    // ..
    end

  else

  if Shift=[ssShift] then // ......................................... Shift+xx
   case Msg.WParam of
    ord('O') : begin sbuInsertOperation.Click; Handled:=true end;
    // ..
    end

  else

  if Shift=[ssCtrl] then // ........................................... Ctrl+xx
   case Msg.WParam of
    vk_Up : begin sbuUpSizeFont.Click; Handled:=true end;
    // ..
    end

  else

  if Shift=[ssAlt] then // ............................................. Alt+xx
   Showmessage('alt+xx')// wird NICHT erkannt

  else

  if Shift=[ssShift,ssCtrl] then // ............................. Shift+Ctrl+xx
   case Msg.WParam of
    ord('L') : begin sbuLoad.Click; Handled:=true end;
    // ..
    end

  else

  if Shift=[ssShift,ssAlt] then // ............................... Shift+Alt+xx
   Showmessage('shift+alt+xx') // wird als Shift+xx erkannt

  else

  if Shift=[ssCtrl,ssAlt] then // ................................. Ctrl+Alt+xx
   Showmessage('ctrl+alt+xx');

  end;
end;
Für fast alle Kombinationen funktioniert das auch; aber leider nicht für die Fälle ALT+Taste und SHIFT+ALT+Taste. Hmm, war lange Zeit "inaktiv" und habe leider gar keine Idee. Das Erkennen von ALT+Taste wäre aber sehr wichtig! Wo ist der Fehler??
Ralph
  Mit Zitat antworten Zitat