Bug 483176

Summary: Cannot type special characters in the terminal
Product: [Applications] konsole Reporter: mpeter.68m0y
Component: keyboardAssignee: Konsole Developer <konsole-devel>
Status: REPORTED ---    
Severity: normal CC: ninjalj
Priority: NOR Keywords: qt6
Version: master   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description mpeter.68m0y 2024-03-10 22:19:33 UTC
SUMMARY
I wanted to connect to an SSH server, and I had trouble inputting the @ sign.
I got the idea that I could copy paste that character from somewhere else which worked, but then came the password prompt, and my password has several special characters.. so in the end I couldn't connect to this SSH server.


STEPS TO REPRODUCE
1. Obtain a Hungariay keyboard and switch Windows to the Hungarian keyboard layout
2. Press AltGr+V to try to type the @ symbol
3. Observe symbol not getting typed

OBSERVED RESULT
Cannot type special symbols in the terminal with the usual keyboard combinations of my keyboard.

EXPECTED RESULT
Special symbols can be typed as usual.

SOFTWARE/OS VERSIONS
Windows: 10
KDE Frameworks Version: 6.0.0
Qt Version: 6.6.2

ADDITIONAL INFORMATION
Version is 24.04.70, but that wasn't an option in the dropdown.
I have obtained Konsole from here: https://invent.kde.org/utilities/konsole/-/jobs/1639326/artifacts/browse/.kde-ci-packages/

I use a Hungarian keyboard, and the Hungarian keyboard layout in windows, which means some special characters require a key combination to be typed. The @ sign for example requires AltGr+V (or Ctrl+Alt+V, as windows treats AltGr as Ctrl+Alt), but all of the other special characters are also on a simialr key combination.

In some cases trying to type a special character resulted in some of the Konsole shortcut keys to get triggered, like AltGr+, to type ; opens the "Configure Keyboard Shortcuts" window (which is bound to Ctrl+Alt+,).

Other than the character not being type, sometimes it does a weird function instead.
Typing a # sign with AltGr+X inserts the # sign at the beginning of the line and starts a new prompt line, however I couldnt find the shortcut function that would do this.
Typing an @ sign with AltGr+V sometimes does not do anything, but sometimes prints to the console a few lines of text, like right now a list of network interface names or something like that, which I dont know where they come from as I had just started Konsole a few minutes ago, and havent seen these lines before.

A bit more testing revealed that its only the terminal area that does not detect the keyboard input correctly. Regular text input boxes in Konsole (like the search field in "Configure Konsole" and in the "Configure Keyboard Shortcuts" window) detect the @ sign as expected.
Maybe there are more than one technical issues in what I experience, like AltGr+, opening the shortcuts menu is probably just that windows should have a different default shortcut configuration as you probably cant detect the difference between AltGr or Ctrl+Alt being pressed (though I have seen some software being able to do that!). In case you agree these are different issues, and we can identify the separate issues, let me know if you want me to open separate bugs for them.

Also, I'm very grateful to you that you have fixed the Windows build process.
Right now Konsole is not yet usable for me, but it is improving on Windows, and I cant wait for when I can replace Windows Terminal with it, because that is buggy, I cant receive any updates anymore, and Konsole has features like the activity monitor and a better search. Thank you for your work!
Comment 1 ninjalj 2024-03-12 00:49:44 UTC
The AltGr+# and AltGr+@ are interpreted by bash's readline:

(https://www.gnu.org/software/bash/manual/bash.html#index-insert_002dcomment-_0028M_002d_0023_0029)
> insert-comment (M-#)
>    Without a numeric argument, the value of the comment-begin variable is inserted at the beginning of the current line. If a numeric 
> argument is supplied, this command acts as a toggle: if the characters at the beginning of the line do not match the value of comment-
> begin, the value is inserted, otherwise the characters in comment-begin are deleted from the beginning of the line. In either case, the line 
> is accepted as if a newline had been typed. The default value of comment-begin causes this command to make the current line a shell
> comment. If a numeric argument causes the comment character to be removed, the line will be executed by the shell.

(https://www.gnu.org/software/bash/manual/bash.html#index-complete_002dhostname-_0028M_002d_0040_0029)
> complete-hostname (M-@)
>    Attempt completion on the text before point, treating it as a hostname.

(M is the Meta key from ancient Lisp keyboards, which in emacs and readline is usually emulated by using the Alt key on modern keyboards).

You can disable the above with:

bind -m emacs-meta -r '@'
bind -m emacs-meta -r '#'
Comment 2 mpeter.68m0y 2024-03-12 01:37:49 UTC
(In reply to ninjalj from comment #1)
> The AltGr+# and AltGr+@ are interpreted by bash's readline:
> 
> (https://www.gnu.org/software/bash/manual/bash.html#index-insert_002dcomment-
> _0028M_002d_0023_0029)
> > insert-comment (M-#)
> >    Without a numeric argument, the value of the comment-begin variable is inserted at the beginning of the current line. If a numeric 
> > argument is supplied, this command acts as a toggle: if the characters at the beginning of the line do not match the value of comment-
> > begin, the value is inserted, otherwise the characters in comment-begin are deleted from the beginning of the line. In either case, the line 
> > is accepted as if a newline had been typed. The default value of comment-begin causes this command to make the current line a shell
> > comment. If a numeric argument causes the comment character to be removed, the line will be executed by the shell.
> 
> (https://www.gnu.org/software/bash/manual/bash.html#index-
> complete_002dhostname-_0028M_002d_0040_0029)
> > complete-hostname (M-@)
> >    Attempt completion on the text before point, treating it as a hostname.
> 
> (M is the Meta key from ancient Lisp keyboards, which in emacs and readline
> is usually emulated by using the Alt key on modern keyboards).
> 
> You can disable the above with:
> 
> bind -m emacs-meta -r '@'
> bind -m emacs-meta -r '#'

Thank you for your help, this is good to know. I didn't think it is bash that could be doing that.

The two commands did not fix the problem, though.
After running the first one, @ still cant be typed, and after running the second one typing # does not comment the line anymore, but a # is not typed either. As I perceive currently nothing happens when attempting to type @ or #.

Also, when we figure out the exact problems (in case there is more than what you have discovered already), would it be possible to integrate the solution into Konsole?
Windows Terminal passes these inputs to bash by default in a way that doesnt confuse it, and it would be very helpful if Konsole too worked out of the box that way.
Not sure how is it with other layouts, but among Hungarian keyboards its common to have the right Alt as an AltGr key.
Comment 3 ninjalj 2024-03-12 23:17:14 UTC
Ok, instead of the above commands, try:

    bind -m emacs-meta '"@": self-insert'
    bind -m emacs-meta '"#": self-insert'

Can you try launching konsole with -platform windows:altgr? As per https://bugreports.qt.io/browse/QTBUG-69317 and https://bugreports.qt.io/browse/QTBUG-83032 this should allow to detect AltGr as different from Ctrl+Alt.
Comment 4 mpeter.68m0y 2024-03-16 02:54:23 UTC
After running the 2 commands, typing both the @ and the # characters work as expected!
However if I start Konsole as `konsole.exe -platform windows:altgr`, the above characters work as expected even without running the bind commands! To test this I have restarted the WSL environment, it seems the effect of the `bind` commands are somehow persisted across Konsole processes.

Now this really makes a difference! :)

For now I have created a `qt.conf` file besides konsole.exe with the following content, so that Konsole always starts this way.
```
[Platforms]
WindowsArguments = altgr
```

Unless theres a better solution, you could consider shipping such a file in the windows release, with the installer and portable archives.