Skip to content

Fix: Disable duplicate shortcut keys#1224

Open
ChenYiLins wants to merge 3 commits intoAutoDarkMode:v11.1from
ChenYiLins:fix/1146-disable-same-shortcut-key
Open

Fix: Disable duplicate shortcut keys#1224
ChenYiLins wants to merge 3 commits intoAutoDarkMode:v11.1from
ChenYiLins:fix/1146-disable-same-shortcut-key

Conversation

@ChenYiLins
Copy link
Copy Markdown
Member

Description

Before, we allowed multiple shortcuts to use the same shortcut key. This PR improves this problem. Now when you try to save the same shortcut key, an error message will pop up and you can't save it.

Sloved #1146.

Screenshots

image

@ChenYiLins ChenYiLins added the area-winui3 Issues for winui3, version 11 or later label May 2, 2026
@ChenYiLins ChenYiLins requested review from a team, Armin2208 and Spiritreader as code owners May 2, 2026 06:13
@ChenYiLins ChenYiLins linked an issue May 2, 2026 that may be closed by this pull request
Comment on lines +45 to +50
shortcutDialog.Closing += (dialog, args) =>
{
if (args.Result == ContentDialogResult.Primary)
{
var (isDuplicate, conflictingName) = ViewModel.IsDuplicateHotkey(hotkeyData.Tag, dialogContent.CapturedHotkeys);
if (isDuplicate)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this to the "changed" OnKeyboardEvent event, for immediate display? Similar to the check for a "valid" hotkey.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. (By the way, I used delegation to realize this function, but it also led to the problem of higher code coupling, but I really couldn't think of a better solution, because the key information was saved in the ViewModel of the page, which had nothing to do with ShortcutDialogContentControl, but the InfoBar of error information was in ShortcutDialogContentControl)

Copy link
Copy Markdown
Member

@Armin2208 Armin2208 May 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually don't like the OnKeyboardEvent for the new addition of showing that only modifier keys aren't allowed. Now as soon the user presses one button (for example ctrl) he sees a red message. I think its irritating, even though it's only for one second.
So at least for the Key Modifier warning, it should only appear if the shortcut dialog wants to close.

Comment thread AutoDarkModeApp/UserControls/ShortcutDialogContentControl.xaml
Comment thread AutoDarkModeApp/Views/HotkeysPage.xaml.cs
@ChenYiLins
Copy link
Copy Markdown
Member Author

ChenYiLins commented May 3, 2026

Code quality: Show conflict results immediately

Fix: Disable invalid shortcut keys

Description

  • Now the key conflict will be displayed immediately.
  • Shift and Ctrl will be displayed immediately (previously, they were not displayed when only the Shift or Ctrl key was pressed)
  • Saving invalid shortcut keys (only Shift or Ctrl) will not be allowed.

Screenshots

image image PixPin_2026-05-03_17-02-45

@Armin2208
Copy link
Copy Markdown
Member

* Shift and Ctrl will be displayed immediately (previously, they were not displayed when only the Shift or Ctrl key was pressed)
* Saving invalid shortcut keys (only Shift or Ctrl) will not be allowed.

Really good and important additions, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-winui3 Issues for winui3, version 11 or later

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[11.1] Don't allow multiple Hotkeys having the same Hotkey

3 participants