Space inserted instead of Enter on using pressKeyCode(AndroidKeyCode.ENTER)

I am automating on Nexus 6 which has Android M. My code to hit enter was working, but since last few days it stopped working. I tried a lot of things like AndroidKeyCode.KEYCODE_SEARCH, AndroidKeyCode.KEYCODE_TAB and other buttons. I even tried sending adb shell commands through my code (adb shell input keyevent KEYCODE_ENTER), but nothing worked.
After all this, I factory reset the phone, and my earlier code, AndroidKeyCode.ENTER, started working again. Hence I conclude that in latest update of Google Keyboard, an issue has crept up, where space is inserted in text field if pressKeyCode(AndroidKeyCode.ENTER) is used.
Has anyone else faces this issue yet? If yes, is there a fix, other than reverting the update on keyboard and keeping auto update off?