Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AltGr doesn't work #89

Closed
ReneHollander opened this issue Oct 13, 2014 · 13 comments
Closed

AltGr doesn't work #89

ReneHollander opened this issue Oct 13, 2014 · 13 comments

Comments

@ReneHollander
Copy link

The AltGr Key to modify a keys behaviour doesn't print any characters. For example 8+AltGr should lead to a [ printed, but it does just nothing. The AltGr Key is used on German keyboards. I don't know about the other layouts out there.

Edit: Using RichTextFX 0.5 on JDK 8 Update 20

@TomasMikula
Copy link
Member

Hi Rene, does this work with a regular TextArea from JavaFX?

@ReneHollander
Copy link
Author

Hey Tomas!
It works in a normal TextArea from JavaFX without a problem.

@TomasMikula
Copy link
Member

Hi Rene,

I just tested it and it works for me in the provided RichTextFX demos (e.g. JavaKeywords), using JDK 8u20 on Linux. What platform are you on?

@ReneHollander
Copy link
Author

I tried it on Windows and Linux, both have the german keyboard layout enabled. On the Windows machine it doesn't work, on Linux I don't have any problems with the demo.

@ReneHollander
Copy link
Author

I did some testing.
If I try to type the [ key on a simple JavaFX TextArea, this event is getting raised:

KeyEvent [source = TextArea@3f5157ee[styleClass=root text-input text-area], target = TextArea@3f5157ee[styleClass=root text-input text-area], eventType = KEY_PRESSED, consumed = false, character =  , text = 8, code = DIGIT8, controlDown, altDown, shortcutDown]

As you can see control, alt and shortcut is beeing pressed. In StyledTextAreaBehavior on line 133-136 you check if either control, alt or meta (I think it's shortcut) is pressed, if one of them is, the character is not getting appended to the TextArea. I think windows is a bit wierd here, so I just removed the checks and I was able to type for e.g the [ key.

I hope I was able to help identifying the cause of the problem. Looking forward to a fix :)

@TomasMikula
Copy link
Member

Hi Rene, sorry for the delay. I cannot test it on Windows right now. The event you report is of type KEY_PRESSED, however, character input in StyledTextArea (and I believe in TextArea as well) is handled using KEY_TYPED events. Can you please check what KEY_TYPED event is produced on TextArea or StyledTextArea (they should be the same)?

I think you correctly identified where the event is blocked. However, your suggested fix (removing the checks for control keys) would mean that, for example, Ctrl+Z would produce the character 'Z' in addition to "Undoing" the last action, which is not desirable.

Anyway, if it works correctly in TextArea, we can make it work in RichTextFX, we just have to figure out how.

@ReneHollander
Copy link
Author

I checked the KeyTyped Event:

KeyEvent [source = CodeArea@3f0f5198[styleClass=styled-text-area code-area], target = CodeArea@3f0f5198[styleClass=styled-text-area code-area], eventType = KEY_TYPED, consumed = false, character = [, text = , code = UNDEFINED, controlDown, altDown, shortcutDown]

I tried out some key combinations like Ctrl+Z and did not had a problem with writing for example a Z. The fix was more like a quick and dirty lets see if it works kind off fix :D. If you need any more testing, I will gladly help you!

@TomasMikula
Copy link
Member

You are right, after removing the checks, Ctrl+Z does not produce 'Z'—it is prevented at this line

&& isLegal(e.getCharacter())

because Ctrl+Z produces KEY_TYPED event with the character 0x1A, which is a control character and is filtered out by the isLegal method.

However, Shift+Ctrl+Z does type 'Z' in addition to "Redo" (the KEY_TYPED event that is produced does contain the character 'Z').

@ReneHollander
Copy link
Author

Interesting. I also tried the Ctrl+Shift+Z key combo to redo but I did not get an extra Z and isLegal returned false.

@TomasMikula
Copy link
Member

So there really is a difference in what events and characters are produced between Windows and Linux. It doesn't seem to be resolvable in a platform independent manner.

This is the relevant code in JavaFX to handle this (copied from TextInputControlBehavior.java):

// Filter out control keys except control+Alt on PC or Alt on Mac
if (event.isControlDown() || event.isAltDown() || (isMac() && event.isMetaDown())) {
    if (!((event.isControlDown() || isMac()) && event.isAltDown())) return;
}

@TomasMikula
Copy link
Member

Can you please sanity test the behavior of my latest commit on Windows?

@ReneHollander
Copy link
Author

It seems to work now! Thanks!

@TomasMikula
Copy link
Member

Thanks for your help. I made a 0.5.1 release that includes this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants