How can I see if the TouchScreenKeyboard is covering an InputField?

My question is quite simple. Just trying to see if the mobile keyboard is covering an InputField so I can slide the canvas up a bit.
I have tried several ways to check if its covering but nothing seems to return the expected result.
I have tried:

if (TouchScreenKeyboard.area.Contains(inputfield.position))
if (TouchScreenKeyboard.area.Contains(inputfield.position, true))
if (TouchScreenKeyboard.area.Overlaps(inputfield.rect))
if (TouchScreenKeyboard.area.Overlaps(inputfield.rect, true))

I’m wondering if maybe my Canvas Scaler has anything to do with the results not being accurate.
Or is there a simpler way to have the Keyboard not cover any InputField?

Thanks in advanced!

Thinking out loud here without testing it. But isn’t the issue that the inputfield position and rect as in more of a world space where the keyboard area is in screen space. Try converting to screen space and see how that works.

I thought something like that. Will try that shortly. Got some other things to fix first.

Thanks!

I tried doing Camera.main.WorldToScreenPoint and that didn’t seem to be even close to work

What type of canvas? as doing Camera.main.WorldToScreenPoint for a overlay doesnt work as its not relative to a camera. for a overlay you’ll want to look at transform.TransformPoint()

Ok , but what is the “transform”? am I using the Canvas as the transform? Or am I just using the inputfield as the transform?

Ok I think my issue is that the TouchKeyboard.area is printing out “incorrect” values. or maybe inverse values. Not sure but for example:

These values come out when the inputfield is way above the keyboard

Keyboard Area Rect (x:0.00, y:704.00, width:640.00, height:432.00)

Input Field Position (320.0, 809.1, 0.0)
And for something I think that would be covered ,
Input Field Position (98.0, 382.9, 0.0)

Ah yes the UI might use a different y then what the keyboard.area uses. You’ll need to convert them :slight_smile:

Oh lovely. That’s just awesome. Please tell me there’s an easy way to do this??

you need to create a new rect and set the y =Screen.height - y

I’m assuming for the Keyboard, correct?

Ok, I actually figured it out by using the regular RectTransform components position without any manipulations and then setting the keyboard y value to 0 this way the height is added into it and its acting as the correct position

Sorry to dig up an old post here - but could you post the code you did to work this out? I’m trying to do something similar, but not had any success.

Sorry for the really late response. I actually removed my code because I had a lot of issues getting it working so I apologize I won’t be of any help unless I try this solution again.