Skip to content

Fix ZoomIt Record hotkey ignoring Alt modifier when Alt is the only modifier key#47388

Merged
MuyuanMS merged 3 commits into
mainfrom
copilot/fix-zoomit-record-hotkey
May 13, 2026
Merged

Fix ZoomIt Record hotkey ignoring Alt modifier when Alt is the only modifier key#47388
MuyuanMS merged 3 commits into
mainfrom
copilot/fix-zoomit-record-hotkey

Conversation

Copilot AI commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Summary of the Pull Request

ZoomIt derives three recording hotkeys from one base key via XOR: fullscreen (base), crop (base XOR Shift), window (base XOR Alt). When Alt is the sole modifier, base XOR Alt = 0, registering a modifier-less hotkey that captures every bare keypress (e.g., pressing 5 triggers window recording).

Zoomit.cpp — 4 hotkey registration sites:

  • Guard RECORD_CROP_HOTKEY registration behind (g_RecordToggleMod ^ MOD_SHIFT) != 0
  • Guard RECORD_WINDOW_HOTKEY registration behind (g_RecordToggleMod ^ MOD_ALT) != 0
// Before (all 4 sites):
registerHotkey( RECORD_CROP_HOTKEY, ( g_RecordToggleMod ^ MOD_SHIFT ) | MOD_NOREPEAT, ... );
registerHotkey( RECORD_WINDOW_HOTKEY, ( g_RecordToggleMod ^ MOD_ALT ) | MOD_NOREPEAT, ... );

// After:
if ( g_RecordToggleMod ^ MOD_SHIFT ) {
    registerHotkey( RECORD_CROP_HOTKEY, ( g_RecordToggleMod ^ MOD_SHIFT ) | MOD_NOREPEAT, ... );
}
if ( g_RecordToggleMod ^ MOD_ALT ) {
    registerHotkey( RECORD_WINDOW_HOTKEY, ( g_RecordToggleMod ^ MOD_ALT ) | MOD_NOREPEAT, ... );
}

ZoomItViewModel.csRecordToggleKeyCrop / RecordToggleKeyWindow computed properties:

  • Return null when the derived hotkey would have no modifier keys, so the Settings UI omits the inapplicable shortcut description rather than displaying a bare-key shortcut.

PR Checklist

  • Closes: #xxx
  • Communication: I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected
  • Tests: Added/updated and all pass
  • Localization: All end-user-facing strings can be localized
  • Dev docs: Added/updated
  • New binaries: Added on the required places
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

ZoomIt registers crop and window recording variants by XOR-ing the base modifier with MOD_SHIFT and MOD_ALT respectively. This design breaks when the base modifier equals the XOR target — the result is 0, and RegisterHotKey with no modifiers intercepts every bare keypress of that key system-wide.

The fix is symmetric across all 4 registration sites (standalone registerHotkey() in RegisterAllHotkeys, the legacy dialog OK path, and two WM_CREATE-adjacent paths): skip the derived hotkey registration when the computed modifier is zero. The Settings UI ViewModel mirrors this logic by returning null for the affected computed properties, causing the converter to emit an empty string instead of a modifier-less shortcut label.

Validation Steps Performed

  • Code review confirmed fix is applied consistently across all 4 RegisterHotKey call sites in Zoomit.cpp
  • Verified HotkeySettingsToLocalizedStringConverter returns string.Empty for null input — no display regression in Settings UI
  • Confirmed the default Ctrl+5 hotkey is unaffected (MOD_CONTROL ^ MOD_ALT = MOD_CONTROL | MOD_ALT ≠ 0)

When Alt is the only modifier in the Record toggle hotkey, XOR-ing it
away for the RECORD_WINDOW_HOTKEY results in a zero modifier, causing
any unmodified key press to trigger window recording.

Fix: Skip registering RECORD_CROP_HOTKEY and RECORD_WINDOW_HOTKEY when
the XOR operation would produce zero modifiers (i.e., when the single
modifier matches the toggled one). Apply this check in all 4 hotkey
registration locations in Zoomit.cpp.

Also update ZoomItViewModel.cs to return null for RecordToggleKeyCrop
and RecordToggleKeyWindow when the derived hotkey would have no
modifier keys, preventing display of an invalid shortcut in settings UI.

Agent-Logs-Url: https://github.com/microsoft/PowerToys/sessions/70c535fc-8c23-4415-bbbb-029432a5eeb3

Co-authored-by: MuyuanMS <116717757+MuyuanMS@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix ZoomIt record toggle hotkey not capturing Alt modifier Fix ZoomIt Record hotkey ignoring Alt modifier when Alt is the only modifier key Apr 29, 2026
Copilot AI requested a review from MuyuanMS April 29, 2026 10:27
@niels9001 niels9001 added the Product-ZoomIt Refers to the ZoomIt tool label Apr 29, 2026
@MuyuanMS MuyuanMS requested a review from Copilot May 7, 2026 08:57

Copilot AI left a comment

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.

Pull request overview

Fixes a ZoomIt recording hotkey edge case where deriving crop/window recording hotkeys via XOR can produce a modifier-less hotkey (when Alt or Shift is the only modifier), causing bare keypresses to trigger recording. The PR updates both the native ZoomIt hotkey registration and the Settings UI display logic to avoid advertising/creating these unsafe derived shortcuts.

Changes:

  • Skip registering derived crop/window record hotkeys when the XOR-derived modifier mask is 0 (preventing key-only global hotkeys).
  • Update Settings UI computed properties to return null for inapplicable derived shortcuts so the UI omits the label instead of showing a bare-key shortcut.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
src/settings-ui/Settings.UI/ViewModels/ZoomItViewModel.cs Suppresses display of derived record shortcuts when XOR would produce a modifier-less hotkey.
src/modules/ZoomIt/ZoomIt/Zoomit.cpp Prevents registration of derived record hotkeys when the XOR-derived modifier would be zero.

Comment thread src/settings-ui/Settings.UI/ViewModels/ZoomItViewModel.cs
Comment thread src/settings-ui/Settings.UI/ViewModels/ZoomItViewModel.cs
Comment thread src/modules/ZoomIt/ZoomIt/Zoomit.cpp Outdated
Comment thread src/modules/ZoomIt/ZoomIt/Zoomit.cpp Outdated
Comment thread src/modules/ZoomIt/ZoomIt/Zoomit.cpp Outdated
Comment thread src/modules/ZoomIt/ZoomIt/Zoomit.cpp Outdated
- Reword C# comments: clarify null return prevents UI display, not hotkey registration
- Extract XOR expressions into named locals (cropMod/windowMod) with explicit != 0 checks
  across all 4 hotkey registration sites in Zoomit.cpp for readability

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@MuyuanMS MuyuanMS marked this pull request as ready for review May 8, 2026 03:46
@MuyuanMS MuyuanMS merged commit ba68b88 into main May 13, 2026
15 checks passed
@LegendaryBlair LegendaryBlair added this to the PowerToys 0.100 milestone May 19, 2026
@crutkas crutkas deleted the copilot/fix-zoomit-record-hotkey branch May 25, 2026 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Product-ZoomIt Refers to the ZoomIt tool

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zoom It - Record Toggle Hotkey does not capture the Alt modifier key

5 participants