mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-11 04:38:14 -06:00
## Summary of the Pull Request Accumulated information from internal transition about the modules development, and reworked it to be added in dev docs. Also the dev docs intself was restructured to be more organized. New pages was verified by transition team. ## PR Checklist - [x] **Dev docs:** Added/updated --------- Co-authored-by: Zhaopeng Wang (from Dev Box) <zhaopengwang@microsoft.com> Co-authored-by: Hao Liu <liuhao3418@gmail.com> Co-authored-by: Peiyao Zhao <105847726+zhaopy536@users.noreply.github.com> Co-authored-by: Mengyuan <162882040+chenmy77@users.noreply.github.com> Co-authored-by: zhaopeng wang <33367956+wang563681252@users.noreply.github.com> Co-authored-by: Jaylyn Barbee <51131738+Jaylyn-Barbee@users.noreply.github.com>
3.1 KiB
3.1 KiB
Keyboard Manager Debugging Guide
This document provides guidance on debugging the Keyboard Manager module in PowerToys.
Module Overview
Keyboard Manager consists of two main components:
- Keyboard Manager Editor: UI application for configuring key and shortcut remappings
- Keyboard Manager Engine: Background process that intercepts and handles keyboard events
Development Environment Setup
- Clone the PowerToys repository
- Open
PowerToys.slnin Visual Studio - Ensure all NuGet packages are restored
- Build the entire solution in Debug configuration
Debugging the Editor (UI)
Setup
- In Visual Studio, right-click on the
KeyboardManagerEditorproject - Select "Set as Startup Project"
Common Debugging Scenarios
UI Rendering Issues
Breakpoints to consider:
EditKeyboardWindow.cpp:CreateWindow()methodEditShortcutsWindow.cpp:CreateWindow()method
Configuration Changes
When debugging configuration changes:
- Set breakpoints in
KeyboardManagerState.cpparound theSetRemappedKeys()orSetRemappedShortcuts()methods - Monitor the JSON serialization process in the save functions
Testing UI Behavior
The KeyboardManagerEditorTest project contains tests for the UI functionality. Run these tests to validate UI changes.
Debugging the Engine (Remapping Logic)
Setup
- In Visual Studio, right-click on the
KeyboardManagerEngineproject - Select "Set as Startup Project"
- Press F5 to start debugging
Key Event Flow
The keyboard event processing follows this sequence:
- Low-level keyboard hook captures an event
KeyboardEventHandlers.cppprocesses the eventKeyboardManager.cppapplies remapping logic- Event is either suppressed, modified, or passed through
Breakpoints to Consider
main.cpp:StartLowlevelKeyboardHook()- Hook initializationKeyboardEventHandlers.cpp:HandleKeyboardEvent()- Entry point for each keyboard eventKeyboardManager.cpp:HandleKeyEvent()- Processing individual key eventsKeyboardManager.cpp:HandleShortcutRemapEvent()- Processing shortcut remapping
Logging and Trace
Enable detailed logging by setting the _DEBUG and KBM_VERBOSE_LOGGING preprocessor definitions.
Common Issues and Troubleshooting
Multiple Instances
If you encounter issues with multiple instances, check the mutex logic in KeyboardManagerEditor.cpp. The editor uses PowerToys_KBMEditor_InstanceMutex to ensure single instance.
Key Events Not Being Intercepted
- Verify the hook is properly installed by setting a breakpoint in the hook procedure
- Check if any other application is capturing keyboard events at a lower level
- Ensure the correct configuration is being loaded from the settings JSON
UI Freezes or Crashes
- Check XAML Islands initialization in the Editor
- Verify UI thread is not being blocked by IO operations
- Look for exceptions in the event handling code
Advanced Debugging
Debugging Both Components Simultaneously
To debug both the Editor and Engine:
- Launch the Engine first in debug mode
- Attach the debugger to the Editor process when it starts