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

戏子无情 提交于 2019-12-24 06:36:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!