Hi
This is by Microsoft design, as it is called both on key down and key up. Use a method such as GetKeyState to handle only one of the calls, e.g.
// Allow the current layer to be moved using the Shift+Cursor keys
procedure Tfmain.ImageEnView1SpecialKey(Sender: TObject; CharCode: Word; Shift: TShiftState; var Handled: Boolean);
function _IsKeyPressed(aKey: Word): Boolean;
begin
Result := ( GetKeyState( aKey ) and $8000 ) <> 0;
end;
begin
if ( ssShift in Shift ) and ( ImageEnView1.LayersCurrent > 0 ) then
case CharCode of
VK_LEFT :
if _IsKeyPressed( 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 _IsKeyPressed( 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 _IsKeyPressed( 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 _IsKeyPressed( 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;
Nigel
Xequte Software
www.xequte.com
nigel@xequte.com