mabe02 / lanterna

Java library for creating text-based GUIs
GNU Lesser General Public License v3.0
2.23k stars 243 forks source link

Is there a way to capture ctrl+enter or ctrl+backspace? #580

Closed panicz closed 9 months ago

panicz commented 9 months ago

When I receive a KeyStoke by invoking the readInput method with the ctrl key pressed, and I press a regular character, I get something that is printed as KeyStroke{keytype=Character, character='e', modifiers=[ctrl]}, and for which the isCtrlPressed method returns true.

However, when I press enter, the keystroke object is printed as KeyStroke{keytype=Enter, character='\n'}, and the isCtrlPressed method returns false regardless of the actual state of the ctrl button.

So I'd like to know if there's any way to obtain the state of modifier buttons for objects whose keytype is different than Character?

avl42 commented 9 months ago

If you run lanterna in a terminal, you're constrained to the input the terminal supports. they all support ctrl for letters, except that some ctrl-letters are tab(ctrl-i), backspace(ctrl-h) or newline (ctrl-m/j) some other keys like cursor home,end,pgup,pgdn,ins,del may depend on the specific terminal, as to whether ctrl it is supported.

There's much legacy involved with terminals.

Panicz @.***> schrieb am Di., 12. Sep. 2023, 00:11:

When I receive a KeyStoke by invoking the readInput method with the ctrl key pressed, and I press a regular character, I get something that is printed as KeyStroke{keytype=Character, character='e', modifiers=[ctrl]}, and for which the isCtrlPressed method returns true.

However, when I press enter, the keystroke object is printed as KeyStroke{keytype=Enter, character='\n'}, and the isCtrlPressed method returns false regardless of the actual state of the ctrl button.

So I'd like to know if there's any way to obtain the state of modifier buttons for objects whose keytype is different than Character?

— Reply to this email directly, view it on GitHub https://github.com/mabe02/lanterna/issues/580, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABIDBMWHVXWEEHAKOODECE3XZ6D73ANCNFSM6AAAAAA4T7E7PQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

panicz commented 9 months ago

Thanks for clarification!