Recent

Author Topic: jEditText | OnKeyPress  (Read 2140 times)

cpalx

  • Hero Member
  • *****
  • Posts: 754
jEditText | OnKeyPress
« on: June 26, 2023, 03:59:20 pm »
Hello

how can i get on key press event?

i need to capture the #13 key

jmpessoa

  • Hero Member
  • *****
  • Posts: 2330
Re: jEditText | OnKeyPress
« Reply #1 on: June 26, 2023, 09:17:53 pm »
What about jEditText "OnEnter"  ?

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.EditText1Enter(Sender: TObject);
  2. begin
  3.   //
  4. end;
  5.  
« Last Edit: June 26, 2023, 10:13:51 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

maurobio

  • Hero Member
  • *****
  • Posts: 640
  • Ecology is everything.
    • GitHub
Re: jEditText | OnKeyPress
« Reply #2 on: July 01, 2023, 07:53:29 pm »
Hi, @cpslx,

The OnEnter event is triggered when the jEdit control gets focus, not when the user pressed the Enter key. You should use the OnKeyPress event for that, but that event does not exist in LAWM jEdit.

OnEnter is not passed a "Key" parameter (as OnKeyPress does) which would allow to capture the key pressed (eg. #13).

With best regards,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 3.8 - FPC 3.2.2 on GNU/Linux Mint 19.1/20.3, Windows XP SP3, Windows 7 Professional, Windows 10 Home

jmpessoa

  • Hero Member
  • *****
  • Posts: 2330
Re: jEditText | OnKeyPress
« Reply #3 on: July 04, 2023, 08:45:19 pm »
Quote
The OnEnter event is triggered when the jEdit control gets focus, not when the user pressed the Enter key. You should use the OnKeyPress event for that, but that event does not exist in LAWM jEdit.

OnEnter is not passed a "Key" parameter (as OnKeyPress does) which would allow to capture the key pressed (eg. #13).

No.  "OnEnter"  handle the "enter/done/go"   specific  key   (KeyEvent.KEYCODE_ENTER = 66)

To handle  jEditText  focus  use  "OnFocus":
Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.EditText1Focus(Sender: TObject; textContent: string);
  2. begin
  3.     //
  4. end;  
  5.  
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

maurobio

  • Hero Member
  • *****
  • Posts: 640
  • Ecology is everything.
    • GitHub
Re: jEditText | OnKeyPress
« Reply #4 on: July 04, 2023, 08:57:32 pm »
Hi, @jmpessoa!

Quote
No.  "OnEnter"  handle the "enter/done/go"   specific  key   (KeyEvent.KEYCODE_ENTER = 66)

What's the difference between handling the enter/done/go and and triggering the OnEnter event (which is what what actually the OnEvent do)?.

OnFocus will provide the contents of the edit field, not with key that has been pressed (#13 or
whatever).

Best regards,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 3.8 - FPC 3.2.2 on GNU/Linux Mint 19.1/20.3, Windows XP SP3, Windows 7 Professional, Windows 10 Home

jmpessoa

  • Hero Member
  • *****
  • Posts: 2330
Re: jEditText | OnKeyPress
« Reply #5 on: July 04, 2023, 10:14:09 pm »
Quote
What's the difference between handling the enter/done/go and and triggering the " event...

In Android/LAMW  "OnEnter"  just handle  enter/done/go  key.....
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

maurobio

  • Hero Member
  • *****
  • Posts: 640
  • Ecology is everything.
    • GitHub
Re: jEditText | OnKeyPress
« Reply #6 on: July 04, 2023, 10:18:35 pm »
@Hi, jpessoa!

Quote
In Android/LAMW  "OnEnter"  just handle  enter/done/go  key....

What are the "done" and "go" keys then? I know where the "enter" key is, but never heard of a "done" and a "go" key before.

Triggering of events (like OnEnter) and pressing of the keys (on a physical or a virtual keyboard) are quite distinct.

Best regards,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 3.8 - FPC 3.2.2 on GNU/Linux Mint 19.1/20.3, Windows XP SP3, Windows 7 Professional, Windows 10 Home

jmpessoa

  • Hero Member
  • *****
  • Posts: 2330
Re: jEditText | OnKeyPress
« Reply #7 on: July 04, 2023, 11:13:41 pm »
In Android  the  "Enter" or "Go" or "Done" are alias  to the same key... and you can get the user press action handling
LAMW jEditText  "OnEnter"  event....
« Last Edit: July 04, 2023, 11:15:16 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

maurobio

  • Hero Member
  • *****
  • Posts: 640
  • Ecology is everything.
    • GitHub
Re: jEditText | OnKeyPress
« Reply #8 on: July 04, 2023, 11:20:23 pm »
Hi, @jmpessoa!

Quote
In Android  the  "Enter" or "Go" or "Done" are alias  to the same key... and you can get the user press action handling LAMW jEditText  "OnEnter"  event....

Please present a simple working example of how the <ENTER> key can be captured in the OnEnter as this will make everything clear for everyone.

Best regards,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 3.8 - FPC 3.2.2 on GNU/Linux Mint 19.1/20.3, Windows XP SP3, Windows 7 Professional, Windows 10 Home

jmpessoa

  • Hero Member
  • *****
  • Posts: 2330
Re: jEditText | OnKeyPress
« Reply #9 on: July 04, 2023, 11:28:45 pm »
Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.EditText1Enter(Sender: TObject);
  2. begin
  3.    ShowMessage('You just press key "Enter"');
  4. end;  
  5.  
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

maurobio

  • Hero Member
  • *****
  • Posts: 640
  • Ecology is everything.
    • GitHub
Re: jEditText | OnKeyPress
« Reply #10 on: July 04, 2023, 11:45:59 pm »
Hi, @jmpessoa!

A fragment of code is worth a thousand words in pidgin English.  ;)

Best regards,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 3.8 - FPC 3.2.2 on GNU/Linux Mint 19.1/20.3, Windows XP SP3, Windows 7 Professional, Windows 10 Home

neuro

  • Jr. Member
  • **
  • Posts: 93
Re: jEditText | OnKeyPress
« Reply #11 on: October 03, 2025, 06:26:04 am »
Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.EditText1Enter(Sender: TObject);
  2. begin
  3.    ShowMessage('You just press key "Enter"');
  4. end;  
  5.  

Yesterday I have installed the latest version v2.4.0f of “fpcupdeluxe”.
I have recompiled my all LAMW programs with targetSdk set to 35.
Now I have discovered that in all my programs in all jEditText components “OnEnter” event no longer works.

As a workaround fix I have moved my program code from “OnEnter” event into “OnDone” event, and now it works.
However “OnDone” event works only when virtual keyboard shows submit button with the word “Done”.
When the number of visible jEditText components changes from one to more then submit button of virtual keyboard shows the word “Next” instead of word “Done” and in this case “OnDone” event fails to work.

I have stopped random switches (of submit button of virtual keyboard) from “Done” into “Next” by adding the following code to OnJNIPrompt event:
Code: Pascal  [Select][+][-]
  1. InputTextEdit.SetImeOptions(imeActionDone); // Theoretically this should set submit button to "Done", however it sets to "Enter"
  2.  

Additionally I have connected three events together (just in case if submit button will randomly switch from “Enter” into “Done” or “Next”):
Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.InputTextEditEnter(Sender: TObject);
  2. begin
  3.   InputTextEditDone(Self);
  4. end;
  5.  
  6. procedure TAndroidModule1.InputTextEditNext(Sender: TObject);
  7. begin
  8.   InputTextEditDone(Self);
  9. end;
  10.  


Quote
What's the difference between handling the enter/done/go and and triggering the " event...

In Android/LAMW  "OnEnter"  just handle  enter/done/go  key.....

In the latest version v2.4.0f of “fpcupdeluxe” this behavior has changed.
Now “OnDone” and “OnNext” and “OnEnter” are separate events.
« Last Edit: October 03, 2025, 04:38:38 pm by neuro »

 

TinyPortal © 2005-2018