Add camera usage detection for automatic light activation #23
+512
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 monitoringCapabilityAccessManager\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.Technical Notes
Registry value
LastUsedTimeStop == 0indicates active camera usage. UsesConvert.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.CaptureDeviceExclusiveControlStatusChangedevent. 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:
Limitation: Only available in UWP/WinRT; not for Win32 or . NET Framework/CORE directly.
2. Windows. Media.Capture API Samples
3. Win32 Sensor API Events
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
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
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
Summary Table
MediaCapture.CaptureDeviceExclusiveControlStatusChanged💡 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.