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

Adding an InputBinding for Alt+Up or Alt+Down results in extra character #954

Closed
dgosbell opened this issue Jun 17, 2021 · 2 comments
Closed
Assignees
Labels
Milestone

Comments

@dgosbell
Copy link

This is a bit of an edge case, but I was attempting to add hotkeys for Alt+Up and Alt+Down to my application which uses Fluent Ribbon, but I was getting extra characters entered and I managed to isolate the fact that this only happened when the window included Fluent Ribbon and I've been able to replicate this in the showcase application

image

(These characters are the same you would get from typing Alt+8 and Alt+2 and on English keyboards at least Num8 is the same as the Up key and Num2 is the same as the Down key if numlock is off)

I've been able to narrow the issue down to this one call, if I temporarily stub out this line I do not get the extra character

var result = NativeMethods.ToUnicode((uint)virtualKey, scanCode, keyboardState, chars, chars.Length, 0);

Looking at the docs for the ToUnicode function it says "If bit 0 is set, a menu is active." I tried setting this to 1 and it does fix this issue but there is no further explanation of what this means so I was not confident to just submit a pull request without raising this as an issue first.

I've manually tested this and the KeyTip navigation still works as do other accelerator keys (such as using alt-A to navigate to the other text box on the Test tab) so I think this is a safe change, but I wanted to open a discussion around this first to see if you had any feedback.

It's strange that if there is not an active input binding these extra characters are not generated

I've attached a copy of TestWindow.xaml.cs which includes some code to add some input bindings which reproduce this issue you just need put this in the Fluent.Ribbon.Showcase folder
TestWindow.xaml.cs.zip

If you then edit line 21 of Fluent.Ribbon/Internal/KeyEventUtility.cs to pass a 1 instead of a 0 for the last parameter of ToUnicode( ) it "fixes" this issue.


Environment

  • Fluent.Ribbon v8.0.0.0
  • Windows 10
  • .NET Framework 4.8
@batzen batzen self-assigned this Jun 17, 2021
@batzen batzen added this to the 9.0 milestone Jun 17, 2021
@batzen
Copy link
Member

batzen commented Jun 17, 2021

That's indeed very strange. I guess i didn't pay enough attention when using that API.
Thanks for pointing out the correct way to fix this.

@batzen batzen closed this as completed in 2f30a3e Jun 17, 2021
@dgosbell
Copy link
Author

Thanks! I don't think it's your fault at all, those flags are VERY poorly documented

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

No branches or pull requests

2 participants