Recent

Author Topic: FPGui Keyevent  (Read 1887 times)

relocate

  • New Member
  • *
  • Posts: 16
FPGui Keyevent
« on: February 15, 2021, 11:50:15 am »
Hello,

is there a way to get a basic Keyevent with FPGui. Here with a fpgmemo.
I tried to use OnKeypress, but the Memo allready forefilled its task after the Key is pressed.
So I press the backspace key and i want to prevent in some cases, that the char will be deleted, but I can't prevent that an because it is allready deletet when the event is fired I don't know which char has been deleted so I am also not able to restore this. How can I catch the key in advanced.

Greetings relocate
OS, Lazarus, FPC: Win (no Lazarus, FPC 2.4.4) | CPU-Target: 32Bit

Bart

  • Hero Member
  • *****
  • Posts: 4415
    • Bart en Mariska's Webstek
Re: FPGui Keyevent
« Reply #1 on: February 15, 2021, 12:19:06 pm »
Well, if the key is already handled by the memo before OnKeyDown/OnKeyPress are called, then this would be a bug IMO.

Bart

Fred vS

  • Hero Member
  • *****
  • Posts: 2388
    • StrumPract is the musicians best friend
Re: FPGui Keyevent
« Reply #2 on: February 15, 2021, 02:08:43 pm »
Hello,

is there a way to get a basic Keyevent with FPGui. Here with a fpgmemo.
I tried to use OnKeypress, but the Memo allready forefilled its task after the Key is pressed.
So I press the backspace key and i want to prevent in some cases, that the char will be deleted, but I can't prevent that an because it is allready deletet when the event is fired I don't know which char has been deleted so I am also not able to restore this. How can I catch the key in advanced.

Greetings relocate

Hello.

Please ask this to fpGUI mailing list:

http://geldenhuys.co.uk/webnews/

or create a issue here:

https://github.com/graemeg/fpGUI/issues

Thanks.
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

relocate

  • New Member
  • *
  • Posts: 16
Re: FPGui Keyevent
« Reply #3 on: February 15, 2021, 02:40:44 pm »
I don't see it as a bug, it seems to be the normal behavior. May be I'm doing something wrong.
The Memo response as it should, a key ist pressed for example 'c' and it occurs in the memo.
Or keep it with backspace. The char in front of the cursor will be deleted, as it should.
But in this case I want to prevent this and I don't know how, it doesn't work with the events, or I'm doing it wrong. That's the reason I asked in the board.
OS, Lazarus, FPC: Win (no Lazarus, FPC 2.4.4) | CPU-Target: 32Bit

winni

  • Hero Member
  • *****
  • Posts: 2663
Re: FPGui Keyevent
« Reply #4 on: February 15, 2021, 04:53:27 pm »
Hi!

The "default" way goes like this:

After every keypress make an unvisible copy of the Memo1.lines.text.
If you made a typo then fetch your copy and use it in the Memo1.
This Undo is typically connected to Ctrl-z

If you need more than 1 undo-step, then you have to build an array of TStringlist for your copies.  And for a big amount you have obvious to refine that undo-system, that not the whole text is buffered but only the last char(s) .  Otherwise the Lazarus IDE could not offer 32767 undo-steps for the editor.

Winni

relocate

  • New Member
  • *
  • Posts: 16
Re: FPGui Keyevent
« Reply #5 on: February 15, 2021, 09:18:18 pm »
Hi,

thank you for your  suggestions, but that won't work for me.
Backspace was one example. But I would rather need to prevent some keystrokes other than to correct them.
May be I have to think about another way.

relocate
OS, Lazarus, FPC: Win (no Lazarus, FPC 2.4.4) | CPU-Target: 32Bit

winni

  • Hero Member
  • *****
  • Posts: 2663
Re: FPGui Keyevent
« Reply #6 on: February 15, 2021, 09:49:26 pm »
Hi!

This is a simple way to block some keys.
Here we block F1 and Escape.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState         );
  2. begin
  3.    if (key =VK_F1) or (Key = VK_ESCAPE) then key := 0;
  4. end;
  5.  


If this does not work for you, then this is a bug and you should follow the steps shown by Bart.

Winni

relocate

  • New Member
  • *
  • Posts: 16
Re: FPGui Keyevent
« Reply #7 on: February 16, 2021, 06:54:58 am »
In FPGui it doesn't work like this.
There is an OnKeyPress property, but if I use this, there are some keys that won't get to the procedure, they are allready processed by the memo itself.
So now I made a new class with fpgmemo as parent and overide the keypress procedure and now I get all keys.
Thank you for your suggestions.
OS, Lazarus, FPC: Win (no Lazarus, FPC 2.4.4) | CPU-Target: 32Bit

Bart

  • Hero Member
  • *****
  • Posts: 4415
    • Bart en Mariska's Webstek
Re: FPGui Keyevent
« Reply #8 on: February 16, 2021, 01:52:23 pm »
Only keys that are printable characters (please don't stat a war about UTF-8) don't make it into OnKeyPress.
This is by design.
Amost all keys should be visible in OnKeyDown however.

Bart

relocate

  • New Member
  • *
  • Posts: 16
Re: FPGui Keyevent
« Reply #9 on: February 19, 2021, 07:30:09 am »
Hey,

as I mentioned, it is about, for example, the backspace key. It is far away from UTF-8 things.

relocate
OS, Lazarus, FPC: Win (no Lazarus, FPC 2.4.4) | CPU-Target: 32Bit

Bart

  • Hero Member
  • *****
  • Posts: 4415
    • Bart en Mariska's Webstek
Re: FPGui Keyevent
« Reply #10 on: February 19, 2021, 12:29:11 pm »
I you cannot intercept Backspace in either OnKeyPress or OnKeyDown, I would consider that a bug.

Bart

 

TinyPortal © 2005-2018