Restore smart keyboard closing (#3975) that got clobbered

My fix for #3975 got clobbered by this commit:
https://github.com/appium/appium/commit/f3dd84d7931bd140fb3ecb1c80a4f6e9f305bd66

This pull request restores my functionality.