SimpleMobileTools / Simple-Keyboard

Easy keyboard for inserting all kinds of texts, special characters and numbers.
https://www.simplemobiletools.com
GNU General Public License v3.0
330 stars 115 forks source link

New line on enter #220

Open unmellow opened 1 year ago

unmellow commented 1 year ago

Certain apps like discord have a separate submit button, and expect the enter key to be used to enter a new line.

It would be nice to have simple keyboard match this functionality.

LennartCode commented 11 months ago

+1 This is also the case for Slack. Maybe this is a CR/LF thing? On other apps, enter is interpreted correctly as a new line instead of a post. Signal and WhatsApp get it correctly. Interestingly it works as intended on Gboard.

Hope this helps! :)

krunal-jethva-tark commented 1 month ago

📝 Note to developers:

If you're coming here to find a solution for the simple-keyboard JavaScript library, this is not the one you're looking for 😅.

For some reason, both Google and Bing searches led me to this issue repeatedly over the last two days, and I initially thought Enter key functionality was not supported in the simple-keyboard library.

However, after a deep inspection of the simple-keyboard library's code, I discovered that there is a built-in option you can use:

Example:

const keyboard = new Keyboard({
    newLineOnEnter: true, // This enables adding a newline when the "Enter" key is pressed
});

This will automatically handle the "Enter" key and insert a new line (\n) at the current cursor position without the need for manual handling.

🎯 Key takeaway:
If you're trying to add a newline on the Enter key press in simple-keyboard, just set the newLineOnEnter option to true. It works out of the box!