问题
given a Delphi 10.1 Berlin update 2 Firemonkey Android app and a TEdit. I like to detect when the user presses Enter while being in the TEdit.
I implemented an OnTyping event already where I loop through all the chars of the .Text property. If vkLineFeed or vkReturn is detected it is Enter (I added the check for vkLineFeed by finding out that certain devices do send that one instead of vkReturn).
ReturnKeyType is default. When being set to done or go it looks like I don't even get the Enter key to see in .Text. The OnKeyDown/OnKeyUp events of a TEdit do not fire on purpose in a FMX app on Android.
But now I encountered a device which simply closes the keyboard on enter but doesn't send me any "enter" char. It's a LG L50 with Android 4.4.
Is there some method to reliably detect return presses on Android/FMX?
回答1:
Here is a working solution: http://www.danielespinetti.it/2017/03/intercept-keyevent-on-android-with.html
I had issues with the memo when trying it out, but after I added a TEdit to the form and tested with that one (as I wanted to use a TEdit anyhow) it worked on the LG L50. Further tests on other devices need to be carried out, but since that was the not functioning device...
Interestingly the hardware key used to show the list of open apps (the most right one) was detected as 0x12.
回答2:
You can also use TEdit.OnChangeTracking event, that occurs when typing individual characters into the edit control. Or OnExit event
来源:https://stackoverflow.com/questions/42633640/delphi-fmx-how-to-reliably-detect-pressing-of-return-key-on-android-device