Recent

Author Topic: (Solved) Custom control KeyDown event  (Read 2160 times)

lainz

  • Hero Member
  • *****
  • Posts: 4691
  • Web, Desktop & Android developer
    • https://lainz.github.io/
(Solved) Custom control KeyDown event
« on: October 04, 2020, 06:03:46 pm »
Hi, I'm making a ListBox with TCustomControl. What I need is when the user press the keys down and up fire the code that I wrote.

I overrided KeyDown event, but it does nothing.

I've seen in other controls the use of UTF8KeyPress, but I need KeyDown because I need the arrow keys, vk_up and vk_down.

Any help is appreciated.

Edit:

Here is the source code:
https://github.com/bgrabitmap/bgracontrols/blob/dev-bgracontrols/bclistboxex.pas
« Last Edit: October 05, 2020, 12:07:05 am by lainz »

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Custom control KeyDown event
« Reply #1 on: October 04, 2020, 06:38:28 pm »
KeyDown should work in everything derived from TCustomControl. I can only see that you don't call
Code: Pascal  [Select][+][-]
  1. inherited KeyDown(Key, Shift);
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Custom control KeyDown event
« Reply #2 on: October 04, 2020, 06:44:18 pm »
Hi!

I just tested your BCListBoxEX.

If you set the initial value of ItemHeight to 20 (and not 150) then you can see the Items.

Two Bugs:
* If you change the direction you have to type KeyUp or KeyDown twice
* You start at the first item, but you will never reach it again with KeyUp.

Winni

lainz

  • Hero Member
  • *****
  • Posts: 4691
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Custom control KeyDown event
« Reply #3 on: October 04, 2020, 06:54:23 pm »
I'm using trunk. I first made the logic in a TForm, but then I'm moving to TCustomControl to have it independently of the TForm. But in trunk it doesn't works, I can't move with the keys, maybe it's my trunk that doesn't works...

Winni you're using FPC release? or trunk?

Edit: using FPC 3.2.0 and Lazarus 2.0.10 doesn't works as well...
« Last Edit: October 04, 2020, 06:58:50 pm by lainz »

lainz

  • Hero Member
  • *****
  • Posts: 4691
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Custom control KeyDown event
« Reply #4 on: October 04, 2020, 06:58:07 pm »
Hi!

I just tested your BCListBoxEX.

If you set the initial value of ItemHeight to 20 (and not 150) then you can see the Items.

Two Bugs:
* If you change the direction you have to type KeyUp or KeyDown twice
* You start at the first item, but you will never reach it again with KeyUp.

Winni

The idea was not to see the items to force the need of changing the scroll when moving with the keyboard.
I've not tested the code with keyboard since it doesn't works on my setup :(

lainz

  • Hero Member
  • *****
  • Posts: 4691
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Custom control KeyDown event
« Reply #5 on: October 04, 2020, 07:00:58 pm »
KeyDown should work in everything derived from TCustomControl. I can only see that you don't call
Code: Pascal  [Select][+][-]
  1. inherited KeyDown(Key, Shift);

Thanks, but adding that also doesn't works...

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Custom control KeyDown event
« Reply #6 on: October 04, 2020, 07:17:16 pm »
Do you mean that KeyDown is not triggered at all or your code just does not work?
Put there some DebugLn('KeyDown', inttostr(Key)); to see what happens.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Custom control KeyDown event
« Reply #7 on: October 04, 2020, 07:26:55 pm »

Winni you're using FPC release? or trunk?


Hi!

fpc 3.04, Laz 2.010

Screenshot attached.

Winni


lainz

  • Hero Member
  • *****
  • Posts: 4691
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Custom control KeyDown event
« Reply #8 on: October 04, 2020, 11:25:13 pm »
Do you mean that KeyDown is not triggered at all or your code just does not work?
Put there some DebugLn('KeyDown', inttostr(Key)); to see what happens.

Added that in top of the event and doesn't fire. Also added a breackpoint and doesn't fire as well.


Winni you're using FPC release? or trunk?


Hi!

fpc 3.04, Laz 2.010

Screenshot attached.

Winni

Thanks winni, so it's an FPC bug, since with 3.2.0 doesn't works and you confirm my code is buggy but at least fires on 3.0.4

I will report at the bugtracker
https://bugs.freepascal.org/view.php?id=37871
« Last Edit: October 04, 2020, 11:28:08 pm by lainz »

lainz

  • Hero Member
  • *****
  • Posts: 4691
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Custom control KeyDown event
« Reply #9 on: October 05, 2020, 12:02:51 am »
Ok It works, the problem was I've not setup ActiveControl in the demo form.

 

TinyPortal © 2005-2018