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
 How to detect if a Key is pressed or not?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

yogiyang

India
727 Posts

Posted - Jul 28 2018 :  08:19:32  Show Profile  Reply
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

xequte

39053 Posts

Posted - Jul 29 2018 :  16:03:54  Show Profile  Reply
Hi Yogi

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



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

yogiyang

India
727 Posts

Posted - Jul 30 2018 :  07:41:50  Show Profile  Reply
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
Go to Top of Page

xequte

39053 Posts

Posted - Jul 30 2018 :  20:34:02  Show Profile  Reply
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
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: