Recent

Author Topic: Dead keys cannot be handled in TForm.OnUTF8KeyPress  (Read 1263 times)

AlexTP

  • Hero Member
  • *****
  • Posts: 2402
    • UVviewsoft
Dead keys cannot be handled in TForm.OnUTF8KeyPress
« on: April 18, 2023, 05:35:42 pm »
Original very detailed report:
https://github.com/Alexey-T/CudaText/issues/5002
In the topic, user even has shown the keyboard layout (Portuguese, ABNTII).

My Lazarus test program, with the source, is attached there too.
It shows that app cannot see accented letters in TForm.OnUTF8KeyPress.
Can you help, Zeljko?

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, LCLType;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     ListBox1: TListBox;
  16.     procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  17.     procedure FormUTF8KeyPress(Sender: TObject; var UTF8Key: TUTF8Char);
  18.   private
  19.  
  20.   public
  21.  
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  
  31. { TForm1 }
  32.  
  33. function _hexstr(const c: TUTF8Char): string;
  34. var
  35.   i: integer;
  36. begin
  37.   result:= '';
  38.   for i:= 1 to length(c) do
  39.     result+= HexStr(Ord(c[i]), 2)+' ';
  40. end;
  41.  
  42. procedure TForm1.FormUTF8KeyPress(Sender: TObject; var UTF8Key: TUTF8Char);
  43. begin
  44.   Listbox1.Items.Add('keypress: '+UTF8Key+', hex: '+_hexstr(UTF8Key));
  45.   Listbox1.ItemIndex:= Listbox1.Items.Count-1;
  46. end;
  47.  
  48. procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  49. begin
  50.   Listbox1.Items.Add('keydown: '+IntTostr(key));
  51.   Listbox1.ItemIndex:= Listbox1.Items.Count-1;
  52. end;
  53.  
  54. end.
  55.  

 

TinyPortal © 2005-2018