Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to reliably detect pressing of Return key on Android device?


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 8 - Last Post: Mar 7, 2017 1:59 PM Last Post By: Markus Humm
Markus Humm

Posts: 5,113
Registered: 11/9/03
How to reliably detect pressing of Return key on Android device?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 6, 2017 6:27 AM
Hello,

given Delphi Berlin and a TEdit. I like to detect when the user presses Enter.
I implemented a OnTyping event already where I loop through all the chars of the .Text.
If vkLineFeed or vkReturn is detected it is Enter (vkLineFeed by finding out that certain devices
do send that one).

But now I encountered a device which simply closes the keyboard on enter but doesn't
send me a "enter" char. It's a LG L50 with Android 4.4.

Is there some method to reliably detect return presses on Android/FMX?

Greetings

Markus
steven chesser

Posts: 401
Registered: 4/13/09
Re: How to reliably detect pressing of Return key on Android device?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 6, 2017 11:23 AM   in response to: Markus Humm in response to: Markus Humm
Markus Humm wrote:
Hello,

given Delphi Berlin and a TEdit. I like to detect when the user presses Enter.
I implemented a OnTyping event already where I loop through all the chars of the .Text.
If vkLineFeed or vkReturn is detected it is Enter (vkLineFeed by finding out that certain devices
do send that one).

But now I encountered a device which simply closes the keyboard on enter but doesn't
send me a "enter" char. It's a LG L50 with Android 4.4.

Is there some method to reliably detect return presses on Android/FMX?

Greetings

Markus

Tried anything like this on the keyup event?

procedure TForm38.Edit1KeyUp(Sender: TObject; var Key: Word; var KeyChar: Char;
  Shift: TShiftState);
begin
 if key  = vkreturn then showmessage('vkReturn') else
  if key  = vkLineFeed then showmessage('vkLineFeed') else
   showmessage('Unknown : '+key.tostring);
end;


Only have a few devices to test with ... all returned vkReturn :(
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: How to reliably detect pressing of Return key on Android device?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 6, 2017 12:08 PM   in response to: steven chesser in response to: steven chesser
Am 06.03.2017 um 20:23 schrieb steven chesser:
Markus Humm wrote:
Hello,

given Delphi Berlin and a TEdit. I like to detect when the user presses Enter.
I implemented a OnTyping event already where I loop through all the chars of the .Text.
If vkLineFeed or vkReturn is detected it is Enter (vkLineFeed by finding out that certain devices
do send that one).

But now I encountered a device which simply closes the keyboard on enter but doesn't
send me a "enter" char. It's a LG L50 with Android 4.4.

Is there some method to reliably detect return presses on Android/FMX?

Greetings

Markus

Tried anything like this on the keyup event?

procedure TForm38.Edit1KeyUp(Sender: TObject; var Key: Word; var KeyChar: Char;
  Shift: TShiftState);
begin
 if key  = vkreturn then showmessage('vkReturn') else
  if key  = vkLineFeed then showmessage('vkLineFeed') else
   showmessage('Unknown : '+key.tostring);
end;


Only have a few devices to test with ... all returned vkReturn :(

Hello,

really the OnKeyUp event? How does this work for you?
I once tried to use this and when it never fired asked somewhere (most
likely here) about it and got the answer that it (rightfully) never
fires on Android. I created this QP entry then:

https://quality.embarcadero.com/browse/RSP-15822

Greetings

Markus
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: How to reliably detect pressing of Return key on Android device?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 6, 2017 12:09 PM   in response to: steven chesser in response to: steven chesser
Am 06.03.2017 um 20:23 schrieb steven chesser:
Markus Humm wrote:
Hello,

given Delphi Berlin and a TEdit. I like to detect when the user presses Enter.
I implemented a OnTyping event already where I loop through all the chars of the .Text.
If vkLineFeed or vkReturn is detected it is Enter (vkLineFeed by finding out that certain devices
do send that one).

But now I encountered a device which simply closes the keyboard on enter but doesn't
send me a "enter" char. It's a LG L50 with Android 4.4.

Is there some method to reliably detect return presses on Android/FMX?

Greetings

Markus

Tried anything like this on the keyup event?

procedure TForm38.Edit1KeyUp(Sender: TObject; var Key: Word; var KeyChar: Char;
  Shift: TShiftState);
begin
 if key  = vkreturn then showmessage('vkReturn') else
  if key  = vkLineFeed then showmessage('vkLineFeed') else
   showmessage('Unknown : '+key.tostring);
end;


Only have a few devices to test with ... all returned vkReturn :(

Hello,

isn't ShowMessage a synchronous dialog?
If yes they won't work on Android as they're not allowed.

Did you really test this on Android?
Sorry if I doubt this.

Greetings

Markus
steven chesser

Posts: 401
Registered: 4/13/09
Re: How to reliably detect pressing of Return key on Android device?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 6, 2017 7:27 PM   in response to: Markus Humm in response to: Markus Humm
Markus Humm wrote:
Am 06.03.2017 um 20:23 schrieb steven chesser:
Markus Humm wrote:
Hello,

given Delphi Berlin and a TEdit. I like to detect when the user presses Enter.
I implemented a OnTyping event already where I loop through all the chars of the .Text.
If vkLineFeed or vkReturn is detected it is Enter (vkLineFeed by finding out that certain devices
do send that one).

But now I encountered a device which simply closes the keyboard on enter but doesn't
send me a "enter" char. It's a LG L50 with Android 4.4.

Is there some method to reliably detect return presses on Android/FMX?

Greetings

Markus

Tried anything like this on the keyup event?

procedure TForm38.Edit1KeyUp(Sender: TObject; var Key: Word; var KeyChar: Char;
  Shift: TShiftState);
begin
 if key  = vkreturn then showmessage('vkReturn') else
  if key  = vkLineFeed then showmessage('vkLineFeed') else
   showmessage('Unknown : '+key.tostring);
end;


Only have a few devices to test with ... all returned vkReturn :(

Hello,

isn't ShowMessage a synchronous dialog?
If yes they won't work on Android as they're not allowed.

Did you really test this on Android?
Sorry if I doubt this.

Greetings

Markus

I tried it on 3 devices I have ... I guess I should have mentioned the keyup event only worked ON hitting the return key.. .did not happen pressing anything else..

so basically typed stuff... hit enter key on the android keyboard, would trigger the event.
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: How to reliably detect pressing of Return key on Android device?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 6, 2017 10:31 PM   in response to: steven chesser in response to: steven chesser
Am 07.03.2017 um 04:27 schrieb steven chesser:
Markus Humm wrote:
Am 06.03.2017 um 20:23 schrieb steven chesser:
Markus Humm wrote:
Hello,

given Delphi Berlin and a TEdit. I like to detect when the user presses Enter.
I implemented a OnTyping event already where I loop through all the chars of the .Text.
If vkLineFeed or vkReturn is detected it is Enter (vkLineFeed by finding out that certain devices
do send that one).

But now I encountered a device which simply closes the keyboard on enter but doesn't
send me a "enter" char. It's a LG L50 with Android 4.4.

Is there some method to reliably detect return presses on Android/FMX?

Greetings

Markus

Tried anything like this on the keyup event?

procedure TForm38.Edit1KeyUp(Sender: TObject; var Key: Word; var KeyChar: Char;
  Shift: TShiftState);
begin
 if key  = vkreturn then showmessage('vkReturn') else
  if key  = vkLineFeed then showmessage('vkLineFeed') else
   showmessage('Unknown : '+key.tostring);
end;


Only have a few devices to test with ... all returned vkReturn :(

Hello,

isn't ShowMessage a synchronous dialog?
If yes they won't work on Android as they're not allowed.

Did you really test this on Android?
Sorry if I doubt this.

Greetings

Markus

I tried it on 3 devices I have ... I guess I should have mentioned the keyup event only worked ON hitting the return key.. .did not happen pressing anything else..

so basically typed stuff... hit enter key on the android keyboard, would trigger the event.

Hello,

ah, that's a good hint!
Now I should retry using it. I guess I had something else in it first
and when this didn't fire I stopped using it.

Greetings

Markus
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: How to reliably detect pressing of Return key on Android device?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 7, 2017 9:10 AM   in response to: Markus Humm in response to: Markus Humm
Am 07.03.2017 um 07:31 schrieb Markus Humm:
Am 07.03.2017 um 04:27 schrieb steven chesser:
Markus Humm wrote:
Am 06.03.2017 um 20:23 schrieb steven chesser:
Markus Humm wrote:
Hello,

given Delphi Berlin and a TEdit. I like to detect when the user presses Enter.
I implemented a OnTyping event already where I loop through all the chars of the .Text.
If vkLineFeed or vkReturn is detected it is Enter (vkLineFeed by finding out that certain devices
do send that one).

But now I encountered a device which simply closes the keyboard on enter but doesn't
send me a "enter" char. It's a LG L50 with Android 4.4.

Is there some method to reliably detect return presses on Android/FMX?

Greetings

Markus

Tried anything like this on the keyup event?

procedure TForm38.Edit1KeyUp(Sender: TObject; var Key: Word; var KeyChar: Char;
  Shift: TShiftState);
begin
 if key  = vkreturn then showmessage('vkReturn') else
  if key  = vkLineFeed then showmessage('vkLineFeed') else
   showmessage('Unknown : '+key.tostring);
end;


Only have a few devices to test with ... all returned vkReturn :(

Hello,

isn't ShowMessage a synchronous dialog?
If yes they won't work on Android as they're not allowed.

Did you really test this on Android?
Sorry if I doubt this.

Greetings

Markus

I tried it on 3 devices I have ... I guess I should have mentioned the keyup event only worked ON hitting the return key.. .did not happen pressing anything else..

so basically typed stuff... hit enter key on the android keyboard, would trigger the event.

Hello,

ah, that's a good hint!
Now I should retry using it. I guess I had something else in it first
and when this didn't fire I stopped using it.

Greetings

Markus

Didn't work in my short test. I'll try out the solution mentioned by
Dave Nottage as soon as time permits.

Greetings

Markus
Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: How to reliably detect pressing of Return key on Android device?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 6, 2017 12:29 PM   in response to: Markus Humm in response to: Markus Humm
Markus Humm wrote:

Is there some method to reliably detect return presses on Android/FMX?

Does this help?

http://www.danielespinetti.it/2017/03/intercept-keyevent-on-android-with.html

--
Dave Nottage [MVP, TeamB]
Hints, tips and tricks at: http://www.delphiworlds.com/blog
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: How to reliably detect pressing of Return key on Android device?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 7, 2017 1:59 PM   in response to: Dave Nottage in response to: Dave Nottage
Am 06.03.2017 um 21:29 schrieb Dave Nottage (TeamB):
Markus Humm wrote:

Is there some method to reliably detect return presses on Android/FMX?

Does this help?

http://www.danielespinetti.it/2017/03/intercept-keyevent-on-android-with.html

Hello,

if being used together with a TEdit (as intended by me) it works.
Thanks!

Greetings

Markus
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02