How do I get the size of the native keyboard?

Can anyone tell me how to get or calculate the height of the native keyboard?

When using native.newTextField() on iOS, the native keyboard pops up whenever the user touches inside the text field. Obviously the keyboard hides the lower part of the screen and possibly other input elements so it is usually necessary to scroll the main screen contents upwards by some amount, so the keyboard no longer hides stuff.

It would be great to be able to automatically and dynamically determine the height of the keyboard to determine exactly how much the screen contents need to be scrolled by.

The iPad keyboard takes up less (relative) screen area compared to the iPhone keyboard, and I’m sure Android has all sorts of variations in keyboard sizes for various screens.

Any ideas would be greatly appreciated!

It is not possible at the moment as far as I know. A pretty serious drawback in my opinion. Please vote for it in the feature requests: http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback/suggestions/4267410-get-keyboard-height

My solution is to move the input boxes up to what I think is a safe position. My optimal solution would be to move them so they rest upon the keyboard, but that is not possible since we have no idea about the height.

Thanks. I voted for that.

What I plan on doing is making a decision on the keyboard height based on device dimensions. It’ll work for iOS devices because there a limited number of screen sizes and I can deduce that the keyboard will be about 1/3 of the screen area on an iPad4 but 40% of the screen are on the iPhone4 (iPad and iPhone have different keyboards layouts). On Android though I’ll just have to either make sure the screen contents are raised high enough to be not be covered by the keyboard (and risk raising screen content too much), or just make sure there are no critical input elements at the bottom of the screen. I’m very surprised there is not a proper solution for this. Do Corona developers not use keyboards and text input widgets in their apps??

I do lots of testing… unfortunately you really need the hardware to do that. Or maybe the xCode Sim can run a corona app? I never tried that.

You can get all the apple device keyboard heights. Minus them (after your scaling mods) from the screen height and you should get an almost pixel perfect calculation of it’s rest position. Problem is as it moves you have no real idea. I just made my own animation/tween algorithm to closely match the keyboards as it moves. Problem is I think the keyboard runs in it’s own world so to speak and depending on system resources at them time  how ‘matched’ up they are can vary. Implementing time based tweens rather than Frame based could be a solution to this if you want to get finicky. Easiest option is to make sure your animation always lags slightly behind the keyboard animation so it pops up behind it, as doing so before hand could look a bit funny.

Getting the real actual height at a given time would be a great feature for more business style apps and I’m definitely going to vote for it. Even better would be to have more control over the keyboard itself. I notice many native apps have more customized colors / submit buttons on their keyboards.

As for Android… well you’re on your own there for now. I am surprised they give us keyboard access but very little information… basically none… around what it is doing. Alternative is to spend time making your own robust keyboard… that could also be a bit of a nightmare to build.

Yeah Android is the real headache :slight_smile: Maybe there is some technical reason for Corona not to have this yet, seems very strange omission.

haven’t tried it but here’s a custom keyboard although the code is old so may need to make some changes.

http://developer.coronalabs.com/code/onscreenkeyboard

Craig42, you say “You can get all the apple device keyboard heights”, this is what I want. How do you do this ?

Sorry to mislead you. I just meant for the ios devices you can do a bit of research and learn the keyboard height for each device. Your program would have to detect which device they are running then set the variable appropriately.

I wish there was some system call to get the keyboard height no matter which device.

Ah yes, that is what I was planning to do. It will work for the limited number of iOS devices but is not a great solution for Android.

It is not possible at the moment as far as I know. A pretty serious drawback in my opinion. Please vote for it in the feature requests: http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback/suggestions/4267410-get-keyboard-height

My solution is to move the input boxes up to what I think is a safe position. My optimal solution would be to move them so they rest upon the keyboard, but that is not possible since we have no idea about the height.

Thanks. I voted for that.

What I plan on doing is making a decision on the keyboard height based on device dimensions. It’ll work for iOS devices because there a limited number of screen sizes and I can deduce that the keyboard will be about 1/3 of the screen area on an iPad4 but 40% of the screen are on the iPhone4 (iPad and iPhone have different keyboards layouts). On Android though I’ll just have to either make sure the screen contents are raised high enough to be not be covered by the keyboard (and risk raising screen content too much), or just make sure there are no critical input elements at the bottom of the screen. I’m very surprised there is not a proper solution for this. Do Corona developers not use keyboards and text input widgets in their apps??

I do lots of testing… unfortunately you really need the hardware to do that. Or maybe the xCode Sim can run a corona app? I never tried that.

You can get all the apple device keyboard heights. Minus them (after your scaling mods) from the screen height and you should get an almost pixel perfect calculation of it’s rest position. Problem is as it moves you have no real idea. I just made my own animation/tween algorithm to closely match the keyboards as it moves. Problem is I think the keyboard runs in it’s own world so to speak and depending on system resources at them time  how ‘matched’ up they are can vary. Implementing time based tweens rather than Frame based could be a solution to this if you want to get finicky. Easiest option is to make sure your animation always lags slightly behind the keyboard animation so it pops up behind it, as doing so before hand could look a bit funny.

Getting the real actual height at a given time would be a great feature for more business style apps and I’m definitely going to vote for it. Even better would be to have more control over the keyboard itself. I notice many native apps have more customized colors / submit buttons on their keyboards.

As for Android… well you’re on your own there for now. I am surprised they give us keyboard access but very little information… basically none… around what it is doing. Alternative is to spend time making your own robust keyboard… that could also be a bit of a nightmare to build.

Yeah Android is the real headache :slight_smile: Maybe there is some technical reason for Corona not to have this yet, seems very strange omission.

haven’t tried it but here’s a custom keyboard although the code is old so may need to make some changes.

http://developer.coronalabs.com/code/onscreenkeyboard

Craig42, you say “You can get all the apple device keyboard heights”, this is what I want. How do you do this ?

Sorry to mislead you. I just meant for the ios devices you can do a bit of research and learn the keyboard height for each device. Your program would have to detect which device they are running then set the variable appropriately.

I wish there was some system call to get the keyboard height no matter which device.

Ah yes, that is what I was planning to do. It will work for the limited number of iOS devices but is not a great solution for Android.

Well , I believe that this should help Corona Team to make an universal variable that returns the keyboard height on Android right?

Well , I believe that this should help Corona Team to make an universal variable that returns the keyboard height on Android right?

Would be awesome if this feature could get implemented any time soon, especially now with iOS 8 the keyboards are INCREDIBLY dynamic and it is next to impossible to design something properly when you don’t know the actual height of the keyboard that is coming up, covering a huge chunk of your screen. Along with custom keyboards the keyboard height can range between a whole range of different heights nowadays, for example with/without keyboard suggestions, custom downloaded keyboards and so on.

Our only solution right now is just to animate the screen up 300px when the keyboard comes up as that covers most keyboard heights, but when the keyboard is nowhere close to 300px in height, but say 216px which is the standard height without suggestions, the app looks like a total mess.

Implementing this feature would help A LOT as you could make beautiful app ui’s for ALL platforms without worrying too much and it would look equally great on all platforms.

Voted on it on the feature suggestion here, but the suggestion has been there since 2013 without any response from devs so don’t know how much use an additional 3 votes would do.

http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback/suggestions/4267410-get-keyboard-height