FPGui Keyevent lazarus / 30-Other ---------------------------------------------------------------------- relocate · 2021-02-15 10:50 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 ---------------------------------------------------------------------- Bart · 2021-02-15 11:19 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 · 2021-02-15 13:08 Quote from: relocate on February 15, 2021, 11:50:15 amHello, 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. ---------------------------------------------------------------------- relocate · 2021-02-15 13:40 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. ---------------------------------------------------------------------- winni · 2021-02-15 15:53 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 · 2021-02-15 20:18 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 ---------------------------------------------------------------------- winni · 2021-02-15 20:49 Hi! This is a simple way to block some keys. Here we block F1 and Escape. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState         );begin   if (key =VK_F1) or (Key = VK_ESCAPE) then key := 0;end;  If this does not work for you, then this is a bug and you should follow the steps shown by Bart. Winni ---------------------------------------------------------------------- relocate · 2021-02-16 05:54 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. ---------------------------------------------------------------------- Bart · 2021-02-16 12:52 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 · 2021-02-19 06:30 Hey, as I mentioned, it is about, for example, the backspace key. It is far away from UTF-8 things. relocate ---------------------------------------------------------------------- Bart · 2021-02-19 11:29 I you cannot intercept Backspace in either OnKeyPress or OnKeyDown, I would consider that a bug. Bart