Forum > CustomDrawn

[SOLVED] TEdit key press events in customdrawn LCLWidgetType

(1/3) > >>

lagprogramming:
Using Linux, add a standard TEdit on a Form and fill the OnKeyPress with the following code:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: char);begin  if key=chr(13) then form1.Caption:=form1.Caption+'>';end;
The above event is triggered when the project is running Linux using default gtk2 LCLWidgetType.
Now go to "Project/Project options..." menu, "Additions and Overrides", set the LCLWidgetType value to "customdrawn". Run the project again and you might see that the key press event is not triggered at all. I've looked at OnUTF8KeyPress event and this one is triggered for both gtk2 and customdrawn. Gtk2 triggers OnUTF8KeyPress before OnKeyPress, customdrawn triggers OnUTF8KeyPress and doesn't trigger OnKeyPress at all.

Maybe it's a bug.

winni:
Hi!

Never call inside a TForm1 procedure Form1!!!!
That might be dangerous.

Do it that way:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if key=#13 then self.Caption:=self.Caption+'>';
or even shorter:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if key=#13 then Caption:=Caption+'>';
Winni

lagprogramming:
@winni For sure that's not the main problem here.
In the meantime I've done an additional test. You don't need a TEdit, TForm class has the same problem. The OnKeyPress event of a form is never triggerd, only the OnUTF8KeyPress.

lagprogramming:
When running an empty form in QT, are both OnFormUTF8KeyPress and OnFormKeyPress triggered when pressing a key? If the answer is yes, is OnFormUTF8KeyPress triggered before OnFormKeyPress?
When running an empty form in win32, are both OnFormUTF8KeyPress and OnFormKeyPress triggered when pressing a key? If the answer is yes, is OnFormUTF8KeyPress triggered before OnFormKeyPress?

KodeZwerg:

--- Quote from: lagprogramming on April 13, 2023, 05:03:06 pm ---1. When running an empty form in win32, are both OnFormUTF8KeyPress and OnFormKeyPress triggered when pressing a key?
2. If the answer is yes, is OnFormUTF8KeyPress triggered before OnFormKeyPress?

--- End quote ---
1. Yes (if Win64 counts too)
2. Yes (if Win64 counts too)
Lazarus 2.3.0 (rev main-2_3-3193-g3bdbedd91b) FPC 3.2.2 x86_64-win64-win32/win64
(I only can test for win64 and activated "KeyPreview" if that makes a difference.)

Navigation

[0] Message Index

[#] Next page

Go to full version