ImageEn, unit imageenview

TImageEnView.OnSpecialKey

TImageEnView.OnSpecialKey


Declaration

property OnSpecialKey: TIESpecialKeyEvent;


Description

OnSpecialKey is called whenever a special key is pressed. Special keys are arrows, "Home", "End", etc.

Note:
OnSpecialKey is called twice for each key press (On key down and on key up). This is by Microsoft design. You can use GetKeyState to determine whether this is the on key down or on key up call
If you have problems receiving OnSpecialKey events, it is recommended that you place the TImageEnView (or its inherited components) on a TPanel instead of TForm
    

Example

// Allow the current layer to be moved using the Shift+Cursor keys
procedure Tfmain.ImageEnView1SpecialKey(Sender: TObject; CharCode: Word; Shift: TShiftState; var Handled: Boolean);
begin
  if ( ssShift in Shift ) and ( ImageEnView1.LayersCurrent > 0 ) then
    case CharCode of
      VK_LEFT :
        if IEIsKeyPressed( VK_LEFT ) then // Ensure this is a KeyDown call
        begin
          ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosX := ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosX - 10;
          ImageEnView1.Update();
          Handled := True;
        end;
      VK_RIGHT :
        if IEIsKeyPressed( VK_RIGHT ) then // Ensure this is a KeyDown call
        begin
          ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosX := ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosX + 10;
          ImageEnView1.Update();
          Handled := True;
        end;
      VK_UP :
        if IEIsKeyPressed( VK_UP ) then // Ensure this is a KeyDown call
        begin
          ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosY := ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosY - 10;
          ImageEnView1.Update();
          Handled := True;
        end;
      VK_DOWN :
        if IEIsKeyPressed( VK_DOWN ) then // Ensure this is a KeyDown call
        begin
          ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosY := ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosY + 10;
          ImageEnView1.Update();
          Handled := True;
        end;
    end;
end;