ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 ImageEnView1SpecialKey Called Twice
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

w2m

USA
1990 Posts

Posted - Apr 17 2015 :  09:55:42  Show Profile  Reply
With the following code ImageEnView1SpecialKey gets called twice so the layer position changes by 2 insead of 1?
procedure TForm1.ImageEnView1SpecialKey(Sender: TObject; CharCode: Word;
  Shift: TShiftState; var Handled: Boolean);
begin
  if (ssShift in Shift) and (ImageEnView1.LayersCurrent > 0) then
  begin
    case CharCode of
      VK_LEFT:
        begin
          ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosX :=
            ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosX - 1;
          ImageEnView1.Update;
          Handled := True;
        end;
      VK_RIGHT:
        begin
          ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosX :=
            ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosX + 1;
          ImageEnView1.Update;
          Handled := True;
        end;
      VK_UP:
        begin
          ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosY :=
            ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosY - 1;
          ImageEnView1.Update;
          Handled := True;
        end;
      VK_DOWN:
        begin
          ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosY :=
            ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosY + 1;
          ImageEnView1.Update;
          Handled := True;
        end;
    end;
  end;
end;


Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development

xequte

38616 Posts

Posted - Apr 21 2015 :  21:18:25  Show Profile  Reply
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
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: