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
 How to detect if a Key is pressed or not?

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
yogiyang Posted - Jul 28 2018 : 08:19:32
Hello,

I am trying to implement a feature in which if the user presses the Spacebar key
ImageEnView's MouseInteract will be set to miScroll. And will remain like this as long as the key is kept pressed.

The moment the key is released ImageEnView's MouseInteract should get set to its previous mode.

For this I am using the component - ApplicationEvents. this component ships with Delphi.

Here is the code that I am using. With current code is written in the ShortCut and I am able to toggle between active MouseInteract and miScroll.


private
    { Private declarations }
    PrevMI : TIEMouseInteract;
    ModeAssigned: Boolean;

//------- ShortCut Event code --------------
var
  iKey: Integer;

  if ImageEnView1.IsEmpty then
    Exit;

  ikey := Msg.CharCode;
  if iKey = VK_SPACE then
  begin
    if ModeAssigned = False then
    begin
      PrevMI := ImageEnView1.MouseInteract;
      ModeAssigned := True;
      ImageEnView1.Cursor := crIEHandDrag;
      ImageEnView1.MouseInteract := [];
      ImageEnView1.MouseInteract := [miScroll];
    end
    else
    begin
      ImageEnView1.MouseInteract := [];
      ImageEnView1.MouseInteract := PrevMI;
      ModeAssigned := False;
      ImageEnView1.Cursor := crIECross;
    end;
    Handled := True;
  end;



But I am not able to implement this functionality as described.

Can someone please help in solving this?

TIA


Yogi Yang
3   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Jul 30 2018 : 20:34:02
Hi Yogi

To capture all key presses regardless of focus, set form.KeyPreview := True and use the form's OnKeyDown/Up (ensuring you set Key to 0 if you use it).

If it fires multiple times you might need to use a private variable to store its down state.

Nigel
Xequte Software
www.imageen.com
yogiyang Posted - Jul 30 2018 : 07:41:50
Hello Nigel,

Thanks for the tip. Actually no!

Because the KeyDown event gets fires multiple times as long as the key is pressed.

Again when we use KeyDown of ImageEnView, it only fires when ImageEnView has focus not otherwise.

What I want is to switch MouseInteract to miScroll irrespective of which control has focus on the form.

TIA


Yogi Yang
xequte Posted - Jul 29 2018 : 16:03:54
Hi Yogi

Why not use the KeyDown and KeyUp events of the ImageEnView control?



Nigel
Xequte Software
www.imageen.com