Feature request: Support use of Shift+Enter
cbiere opened this issue · 9 comments
Some apps or forms behave differently when pressing Enter vs. Shift + Enter. For example, in a document editor pressing Enter might result in new paragraph but Shift + Enter inserts a line break only. In (web) forms, Enter might result in submitting the form but Shift + Enter inserts a line break and allows to make text more readable than a wall of text.
GBoard doesn't seem to have any option for this. The only keyboard other than a physical one that respects thebShift modifier when tapping Enter, I could find, is Unexpected Keyboard. Would be great to have this option in Simple Keyboard as well.
Can you send links to sample pages/apps that misbehave?
LatinIME has remains of what looks like a Shift+ Enter support but I'm not sure if this still works:
The message forms on patreon.com explicitely suggest using Shift + Enter to insert a line break. A normal Return/Enter submits the message. Some of my Google Docs behave that way too, i.e. you don't want empty lines in address fields.
Example docx file attached.
test.docx
Here is an HTML example with a demo for testing:
https://htmldom.dev/press-shift-and-enter-for-a-new-line/
I'm starting to doubt this is even possible in Android. Have you seen a keyboard that supports it? In emulator even pressing Shift+Enter in a physical keyboard doesn't add a new line.
The logic for Shift + Enter is there in the LatinIME, you have to click Shift and then Enter to invoke it. It just sends the same Enter key event afterwards so it looks more like a placeholder or a deprecated feature.
I tried this code and it doesn't work in the HTML example:
mConnection.sendKeyEvent(new KeyEvent(eventTime, eventTime,
KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0,
KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE));
mConnection.sendKeyEvent(new KeyEvent(eventTime, eventTime,
KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0,
KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE));
mConnection.sendKeyEvent(new KeyEvent(eventTime, eventTime,
KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0,
KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE));
mConnection.sendKeyEvent(new KeyEvent(eventTime, eventTime,
KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0,
KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE));
Nope, spoke too soon. As shift + enter is being detected by checking if enter event has a shift modifier just sending shift events doesn't work. Found a property where these modifiers can be set in key events. This does seem to work:
mConnection.sendKeyEvent(new KeyEvent(eventTime, eventTime,
KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER, 0, eyEvent.META_SHIFT_ON, KeyCharacterMap.VIRTUAL_KEYBOARD, 0,
KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE));
mConnection.sendKeyEvent(new KeyEvent(eventTime, eventTime,
KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER, 0, eyEvent.META_SHIFT_ON, KeyCharacterMap.VIRTUAL_KEYBOARD, 0,
KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE));
Aaaaand this doesn't work in a Pixel 3a. Attached a zipped apk, you're welcome to test.
app-release.zip
Awesome. Thanks a lot. Exactly what I was looking for. Tested on Patreon comment forms and Google Docs. In case it matters: I use a Redmi Note 10 Pro (sweet) with PixelOS (Android 13).