Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 6, 2025

Implements system-wide camera usage detection to automatically enable edge lighting during video calls. Addresses the approach outlined in Issue #21 research using registry monitoring as the most viable solution for WPF/.NET desktop applications.

Implementation

  • CameraMonitor.cs: Registry-based detection monitoring CapabilityAccessManager\ConsentStore\webcam. Polls every 2 seconds, filters Windows Hello events, thread-safe with proper locking.

  • MainWindow.xaml.cs: Tray menu toggle for camera detection. Automatically enables light when camera activates, restores previous state when camera releases.

private void OnCameraStatusChanged(object? sender, CameraStatusChangedEventArgs e)
{
    Dispatcher.BeginInvoke(new Action(() =>
    {
        if (e.IsInUse)
        {
            lightWasOnBeforeCamera = isLightOn;
            if (!isLightOn) ToggleLight();
        }
        else
        {
            if (!lightWasOnBeforeCamera && isLightOn) ToggleLight();
        }
    }));
}

Technical Notes

Registry value LastUsedTimeStop == 0 indicates active camera usage. Uses Convert.ToInt64() to handle DWORD/QWORD type variations. Windows Hello filtering matches package name patterns (hello, windows.internal, cloudexperiencehost).

Feature is opt-in, fails gracefully without registry access, read-only operations only. No direct camera access required.

Original prompt

This section details on the original issue you should resolve

<issue_title>Detect camera is being used by another application and automatically turn on</issue_title>
<issue_description>Below is initial research. My believe is there is an API where you can detect your camera is in use. From there, the edge lighting can kick on.

Edge case you'd want to be aware of is if this would trigger in a Windows Hello event.

Research:
Detecting when a camera is in use on Windows, especially with an event-based API, is a nuanced topic. Here's an overview of what's available in the official Windows APIs and practical approaches, plus some workarounds and relevant context:

1. MediaCapture. CaptureDeviceExclusiveControlStatusChanged Event (UWP)

  • Best Supported Option for UWP/WinRT Applications: Starting from Windows 10, version 1703, UWP apps can subscribe to the MediaCapture.CaptureDeviceExclusiveControlStatusChanged event. This notifies your app when the camera's exclusive control status changes—essentially, whether another process/app has taken control and when it becomes available again. However, it only tells you about camera access state, not which app is using it, and only within the context of your own MediaCapture usage (so not system-wide)[1].

    Example:

    _mediaCapture. CaptureDeviceExclusiveControlStatusChanged += (sender, args) =>
    {
        if (args.Status == MediaCaptureDeviceExclusiveControlStatus.SharedReadOnlyAvailable)
        {
            // Camera is in use by another application
        }
        else if (args.Status == MediaCaptureDeviceExclusiveControlStatus.ExclusiveControlAvailable)
        {
            // Camera is available
        }
    };

    Limitation: Only available in UWP/WinRT; not for Win32 or . NET Framework/CORE directly.

2. Windows. Media.Capture API Samples

  • Microsoft's Windows-Camera GitHub repo provides samples that show how to work with Windows camera-related APIs, including the MediaCapture API and IMFSensorActivityMonitor. Reviewing the samples there can provide code patterns for detecting camera status and getting notifications within supported app models[2][3].

3. Win32 Sensor API Events

  • Windows offers a legacy Sensor API with event notification via COM interfaces (ISensorEvents). However, the Sensor API is deprecated, and it's not specifically targeted at camera usage, nor does it provide system-wide notification of camera access by other processes[4].

4. Polling-Based Workarounds & Registry Monitoring

  • There is no public Win32 or .NET API that offers direct, event-driven camera usage notifications at the system level. Solutions in community forums often suggest polling for device status or monitoring registry keys. For instance, certain registry keys (CapabilityAccessManager) can provide info about webcam access by apps, which some open-source tools (like Lineblacka/webcam-usage-detector) monitor and trigger notifications based on camera usage events[5][6].

5. DirectShow & WM_CAP_GET_STATUS

  • The old DirectShow method (WM_CAP_GET_STATUS) checks the camera status via a window message. But querying the status requires opening a capture window, which itself triggers device activation—so it's not a feasible way to monitor usage unobtrusively[7].

6. Limitations and Alternative Solutions

  • Event Viewer: Does not receive system events when cameras are activated or deactivated.
  • Tapping into Windows Notifications: Some third-party tools monitor for device changes or hooks at the OS/driver level, but no official event-based public API exists for general desktop apps.
  • Virtual Camera Driver: Advanced solution is writing a virtual camera driver that mediates access and logs usage, but it's complex and requires kernel-mode development.

Summary Table

API/Event Scope Notification? Recommended For
MediaCapture.CaptureDeviceExclusiveControlStatusChanged App-level/UWP Yes (event) UWP/WinRT apps
Sensor API (ISensorEvents) Device-level Yes (event, deprecated) Legacy/WIN32 apps
Registry Monitoring System-level Workaround (poll/...

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits December 6, 2025 22:43
Co-authored-by: shanselman <2892+shanselman@users.noreply.github.com>
Co-authored-by: shanselman <2892+shanselman@users.noreply.github.com>
…nitialization

Co-authored-by: shanselman <2892+shanselman@users.noreply.github.com>
Co-authored-by: shanselman <2892+shanselman@users.noreply.github.com>
Copilot AI changed the title [WIP] Detect camera usage by another application and turn on edge lighting Add camera usage detection for automatic light activation Dec 6, 2025
Copilot AI requested a review from shanselman December 6, 2025 22:52
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.

Detect camera is being used by another application and automatically turn on

2 participants