Feature Request: Expose Command Trigger Source (Keyboard vs Mouse vs Menu)
📝 Summary
I would like to request a feature in the VS Code API to allow extensions to determine how a command was triggered — specifically, whether it was initiated via:
- A keyboard shortcut
- A mouse click (e.g., context menu or toolbar)
- The command palette
- Other UI actions
🔍 Use Case
This feature would be useful for:
- Telemetry and UX research
- Extensions that want to adapt behavior based on how a command was initiated
- Accessibility tools
- Teaching or onboarding extensions that want to provide helpful suggestions based on user habits
📦 Current Limitation
Currently, the commands.onDidExecuteCommand event does not provide metadata about the input source that triggered the command. As a result, extension authors can't distinguish between keyboard-driven and mouse-driven command executions.
✅ Suggested Solution
Extend the onDidExecuteCommand event or expose a new API that includes optional metadata like:
{
command: string;
arguments?: any[];
triggerSource?: 'keyboard' | 'mouse' | 'palette' | 'api';
}
Even something coarse-grained would help improve context awareness.
🛠 Possible Workarounds
Some developers try to track keyboard/mouse state separately, but this is error-prone and limited to custom UIs like WebViews. There is currently no reliable way to detect how a native command (like editor.action.copy) was triggered.
🙏 Why This Matters
Command origin tracking could unlock a lot of developer creativity, improve user analytics, and make VS Code even more extensible and adaptive.
This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.
Happy Coding!
:slightly_smiling_face: This feature request received a sufficient number of community upvotes and we moved it to our backlog. To learn more about how we handle feature requests, please see our documentation.
Happy Coding!