Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 10, 2025

Windows media key detection only worked when SwiftControl was focused, preventing BLE HID controllers from functioning in the background.

Changes

Native Plugin (media_key_detector_windows_plugin.cpp)

  • Replaced focus-dependent keyboard handler with RegisterHotKey API for VK_MEDIA_PLAY_PAUSE, VK_MEDIA_NEXT_TRACK, VK_MEDIA_PREV_TRACK
  • Added event channel + window message handler for WM_HOTKEY events
  • Implemented lifecycle management: register on setIsPlaying(true), unregister on setIsPlaying(false) or destruction
  • All-or-nothing registration with cleanup on partial failure

Dart Plugin (media_key_detector_windows.dart)

  • Switched from keyboard handler to event channel listener (consistent with iOS/macOS)
  • Wire setIsPlaying to native method for hotkey control

Implementation

// Hotkeys registered globally with MOD_NOREPEAT
RegisterHotKey(hwnd, HOTKEY_PLAY_PAUSE, MOD_NOREPEAT, VK_MEDIA_PLAY_PAUSE);

// WM_HOTKEY messages forwarded to Dart via event channel
std::optional<LRESULT> HandleWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
  if (message == WM_HOTKEY && event_sink_) {
    event_sink_->Success(EncodableValue(key_index));
    return 0;
  }
  return std::nullopt;
}

Media keys now work system-wide regardless of application focus.

Original prompt

This section details on the original issue you should resolve

<issue_title>Ensure BLE HID media controllers work with Windows</issue_title>
<issue_description>> I also wanted to ask if the Windows version now includes BLE HID support in version 3.4.0, or is there still only classic BT?

I couldn't connect my controller there in the application.

And one last thing: the web version redirects to the URL:
https://jonasbark.github.io/swiftcontrol/#/device
and a blank gray screen appears (tested in Edge and Chrome)

Originally posted by @TomasT342 in #110</issue_description>

<agent_instructions>the Windows implementation of the media_key_detector plugin (media_key_detector_windows_plugin.cpp) does not work globally when SwiftControl isn't the focused application. Implement a way to globally register for the media hotkeys</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits November 10, 2025 07:49
… API

Co-authored-by: jonasbark <1151304+jonasbark@users.noreply.github.com>
Co-authored-by: jonasbark <1151304+jonasbark@users.noreply.github.com>
Co-authored-by: jonasbark <1151304+jonasbark@users.noreply.github.com>
Co-authored-by: jonasbark <1151304+jonasbark@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement global registration for media hotkeys Implement global hotkey registration for Windows media key detection Nov 10, 2025
Copilot finished work on behalf of jonasbark November 10, 2025 07:55
Copilot AI requested a review from jonasbark November 10, 2025 07:55
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.

Ensure BLE HID media controllers work with Windows

2 participants