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

Numeric access keys not working #15957

Open
JouriM2 opened this issue Jun 8, 2024 · 1 comment · May be fixed by #16076
Open

Numeric access keys not working #15957

JouriM2 opened this issue Jun 8, 2024 · 1 comment · May be fixed by #16076
Labels

Comments

@JouriM2
Copy link

JouriM2 commented Jun 8, 2024

Here is sample repo: https://github.com/JouriM2/AvDropDownBug
It contains simple window with 3 edits and labels to access them.

изображение

implemented as:

	<StackPanel Orientation="Vertical" Margin="20">
		<Label Content="_1 One" Target="edt1"/>
		<TextBox x:Name="edt1"/>

		<Label Content="_2 Two" Target="edt2"/>
		<TextBox x:Name="edt2"/>

		<Label Content="_A Three" Target="edt3"/>
		<TextBox x:Name="edt3"/>

	</StackPanel>

Problems I have:

  1. Number hotkeys not working. Pressing Alt+1 or Alt+2 do nothing. Alt+A works as expected and move focus to edit.
    If to press mouse on Label itself all three are works.
    How to use number hotkeys?

  2. After I press Alt on keyboard all hotkeys stay underlined until I press any mouse button inside window (any button, at any point inside window).
    At same time any keyboard actions do not remove highlighting.
    It seems like a bug and hotkeys need to be hidden after Alt key released.

Originally posted by @JouriM2 in #15939

@stevemonaco
Copy link
Contributor

Moving some details from the originating discussion...

For point 1:

protected virtual void OnKeyDown(object? sender, KeyEventArgs e)
{
bool menuIsOpen = MainMenu?.IsOpen == true;
if (e.KeyModifiers.HasAllFlags(KeyModifiers.Alt) && !e.KeyModifiers.HasAllFlags(KeyModifiers.Control) || menuIsOpen)
{
// If any other key is pressed with the Alt key held down, or the main menu is open,
// find all controls who have registered that access key.
var text = e.Key.ToString();

e.Key.ToString() returns "D1" for the key (because of the enum) whereas "_1 One" registers "1" in the hotkey map.

For point 2:

This works as expected if you have a Menu, which is the primary use of AccessText. I'm not sure what the intended design is for out-of-menu access keys. You should be able to press the alt key, release it, and continue pressing access keys (with or without alt held down) to navigate. The non-menu access keys return to normal when the menu is closed.

It can be fixed in this area

protected virtual void OnPreviewKeyUp(object? sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.LeftAlt:
case Key.RightAlt:
_altIsDown = false;
if (_ignoreAltUp)
{
_ignoreAltUp = false;
}
else if (_showingAccessKeys && MainMenu != null)
{
MainMenu.Open();
}
break;
}
}
by placing the following before the break;. Not sure if there are any side-effects.

if (MainMenu is null)
{
    _owner!.ShowAccessKeys = _showingAccessKeys = false;
}

@workgroupengineering workgroupengineering linked a pull request Jun 20, 2024 that will close this issue
3 tasks
@maxkatz6 maxkatz6 added the bug label Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants