Page 1 of 1

Allow enter-key for confirming dialogs

Posted: Wed Dec 19, 2018 11:10 am
by Therenas
I would love it if I could confirm a dialog with ENTER. As it currently works, you can detect keyboard shortcuts only when no textfield is selected/in focus, so pressing ENTER directly after typing can't be detected by mods. Now I see how custom shortcuts won't work in a textfield, as for example CTRL+A selects all text, etc. But one set key (ENTER seems suitable) that, when pressed when a textfield is in focus, fires an 'submit-event' to be caught by mods, would really make for a nicer UI experience. As a user, a form that doesn't submit with ENTER really seems broken.

Re: Allow enter-key for confirming dialogs

Posted: Wed Jan 09, 2019 7:59 pm
by Rseding91
I can implement this for single-line text boxes but it's not going to work for multi-line ones since enter is "add new line" and not "submit".

Re: Allow enter-key for confirming dialogs

Posted: Thu Jan 10, 2019 12:13 am
by Nexela
Most programs with multi line text boxes use CTRL+ENTER to send it, would it be viable to add this combination to multiline boxes?

Re: Allow enter-key for confirming dialogs

Posted: Fri Jan 11, 2019 10:03 am
by bobingabout
Nexela wrote: Thu Jan 10, 2019 12:13 am Most programs with multi line text boxes use CTRL+ENTER to send it, would it be viable to add this combination to multiline boxes?
I thought it was Shift + Enter.

Still, I'd probably agree with Rseding, I'd want the default behaviour of a multi-line text box to be new line, not send, where message boxes (like the console) should be (and the console actually is) enter to submit.

that yellow box that appears at the start of a new game that says "Press tab to close", I must admit, I've tried pressing Escape and Enter to close it.

Re: Allow enter-key for confirming dialogs

Posted: Thu Jan 24, 2019 8:13 am
by zysnarch
Just chiming in to support this idea - I was about to ask the same thing.

Re: Allow enter-key for confirming dialogs

Posted: Tue Jan 29, 2019 5:56 pm
by Therenas
Yeah I totally agree that in multi-line ones, enter should go to the next line. Implementing a shift-enter or ctrl-enter would be nice, but not as important, as those multi-line boxes aren't used for some quick input typically, thus aren't used as frequently, which makes enter not working less annoying.

Re: Allow enter-key for confirming dialogs

Posted: Fri May 31, 2019 6:15 pm
by Therenas
Boodals and I just talked a bit about this on discord, and a different way to implement this came to mind: You could have a field on the textfield/box that you set. You give it a reference to a button object, and when the user hits enter on it, that button gets programmatically pressed. This way, it would not require a new event, which I‘m told is kinda annoying to implement. It might not be the 100% clean way to do it, but it‘ll work.

Re: Allow enter-key for confirming dialogs

Posted: Fri May 31, 2019 7:12 pm
by eradicator
Therenas wrote: Fri May 31, 2019 6:15 pm Boodals and I just talked a bit about this on discord, and a different way to implement this came to mind: You could have a field on the textfield/box that you set. You give it a reference to a button object, and when the user hits enter on it, that button gets programmatically pressed. This way, it would not require a new event, which I‘m told is kinda annoying to implement. It might not be the 100% clean way to do it, but it‘ll work.
How about adding "button" to the on_gui_text_changed event (same as on_gui_click)? That also makes it easy to add ctrl/shift modifiers. Doesn't invent new api concepts like "event for a different element", and keeps the events seperated for different element types.

Re: Allow enter-key for confirming dialogs

Posted: Wed Jun 26, 2019 6:01 pm
by raiguard
+1 from me! I would like users of my mod to be able to press enter to dismiss this textfield:

Image

Re: Allow enter-key for confirming dialogs

Posted: Thu Jun 27, 2019 2:41 am
by raiguard
I am going to add a few more things to this request, all in the effort to mimic how textfields work in the vanilla settings GUI. Along with enter-to-confirm, I would like to have a way to detect the focused state of a textfield (or maybe just any GUI element). Something like element.get_focused_state(), or an event that fires when something is focused / unfocused, such as on_gui_element_focused and on_gui_element_unfocused.

Either one of these, combined with the ability to press enter to confirm, would allow me to make my settings GUI behave consistent with the vanilla settings GUI.

Thanks for your time!

Re: Allow enter-key for confirming dialogs

Posted: Thu Jun 27, 2019 7:38 am
by Therenas
You can detect an element being focused by listening to https://lua-api.factorio.com/latest/eve ... _gui_click, it works for textfields too.

Re: Allow enter-key for confirming dialogs

Posted: Mon Jul 15, 2019 7:50 pm
by Therenas
This just got added for 0.17.57, thanks guys! (Can be moved)