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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 ImageEnView1SpecialKey Called Twice

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
w2m Posted - Apr 17 2015 : 09:55:42
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
1   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Apr 21 2015 : 21:18:25
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