Fix bug #3800 Incorrect keyhandler behaviour #2

This pull request fixes bug 3800. Fix is for QA_3_5 branch. However it should be merged to master as well as the bug is present there also.