Skip to content

Add opt-in global brightness shortcuts - #1

Closed
LinkaiQi wants to merge 3 commits into
mainfrom
linkaiqi-microsoft-global-brightness-hotkeys
Closed

Add opt-in global brightness shortcuts#1
LinkaiQi wants to merge 3 commits into
mainfrom
linkaiqi-microsoft-global-brightness-hotkeys

Conversation

@LinkaiQi

@LinkaiQi LinkaiQi commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Adds two system-wide keyboard shortcuts that step every connected Apple display's brightness by 10%, without stealing focus from whatever you're doing.

Action Default
Increase brightness by 10% Win + Ctrl +
Decrease brightness by 10% Win + Ctrl +

Off by default — nothing is taken over until you turn it on in tray → Settings.

Why these defaults

Win+Ctrl+↑/↓ is one of the few arrow combinations Windows leaves free. Ruled out along the way: Win+↑/↓ (snap), Win+Shift+↑/↓ (stretch across monitors), Win+Alt+↑/↓ (Win11 22H2 half-snap), Ctrl+Alt+arrows (Intel GPU rotation), Ctrl+Shift+arrows (text selection), Win + Plus/Minus (Magnifier). Only Win+Ctrl+←/→ is taken, by virtual desktops.

Both combinations are user-configurable anyway, and a collision is reported rather than swallowed.

How it works

  • RegisterHotKey binds to the main window's HWND — the same window that already receives WM_DEVICECHANGE, so shortcuts keep working while the window is hidden in the tray. WM_HOTKEY is dispatched through an HwndSource hook, exactly like the device-change watch.
  • MOD_NOREPEAT is set, so one press is one 10% step. Without it a held key auto-repeats ~30×/sec, crossing the whole range in about a third of a second.
  • Registration failures surface in the UI. ERROR_HOTKEY_ALREADY_REGISTERED (1409) becomes an inline warning naming the combination; anything else is logged with its Win32 error.
  • Recording a shortcut suspends the live ones, otherwise Windows would deliver the combination as WM_HOTKEY and it would never reach the settings window as a key press.
  • Settings persist to %LOCALAPPDATA%\NitTray\settings.json, beside the diagnostic log. Load/Save never throw.

UI

  • New Settings window (Fluent, Mica) with an enable toggle, click-to-record buttons for each shortcut, an inline status bar, and "Restore defaults". Reachable from the tray menu and the main window footer.
  • New on-screen overlay near the bottom of the primary screen showing the display name and new level. Click-through, never activates, fades out on its own.

Notes

  • One WPF gotcha worth knowing: Keyboard.Modifiers never reports the Windows key (confirmed in KeyboardDevice.cs — it only computes Alt/Ctrl/Shift), so the recorder probes Key.LWin/Key.RWin directly. Without that, Win+Ctrl+Up silently records as Ctrl+Up.
  • Known limitation, documented in the settings window: Windows doesn't deliver shortcuts to ordinary apps while an elevated window has focus.
  • Not yet tested on Windows. Builds clean (Release + Debug, 0 warnings/errors), but every runtime path — registration, capture, OSD placement — needs a real run before merging.

Copilot AI added 3 commits August 2, 2026 17:34
Step every connected Apple display by 1% from any app. Shortcuts are
registered with RegisterHotKey against the main window's HWND — the same
window that already receives WM_DEVICECHANGE — so they keep working while
NitTray sits in the tray.

- Defaults to Win+Ctrl+Up / Win+Ctrl+Down, the least contended arrow
  combination Windows leaves unassigned, and they are configurable.
- Off until enabled, persisted to %LOCALAPPDATA%\NitTray\settings.json.
- MOD_NOREPEAT is not set so holding a key ramps; DisplayViewModel already
  coalesces the writes.
- A combination another app owns (ERROR_HOTKEY_ALREADY_REGISTERED) is
  reported inline in the new Settings window instead of failing silently,
  and live registrations are suspended while recording a new one.
- A click-through, never-activated overlay reports the new level, since the
  window is normally hidden.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
WPF's Keyboard.Modifiers only reports Alt, Ctrl, and Shift — it never sets
ModifierKeys.Windows — so the recorder silently downgraded Win+Ctrl+Up to
plain Ctrl+Up and registered that instead, without telling the user. Probe
Key.LWin/Key.RWin directly.

Also require Ctrl, Alt, or Win in a binding: Shift alone would have taken
over ordinary text-selection chords system-wide.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
One press is now one 10% step, so ten presses covers the full range. Register
the shortcuts with MOD_NOREPEAT to match: a held key auto-repeats about 30
times a second, which at this step size would cross the whole range in roughly
a third of a second.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@LinkaiQi LinkaiQi closed this Aug 3, 2026
@LinkaiQi
LinkaiQi deleted the linkaiqi-microsoft-global-brightness-hotkeys branch August 3, 2026 01:46
@LinkaiQi

LinkaiQi commented Aug 3, 2026

Copy link
Copy Markdown
Owner Author

Closed automatically when the head branch was renamed. Continued in #2.

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

Successfully merging this pull request may close these issues.

2 participants