检查 control/command 键当前是否在 VS 扩展中按下
Checking if control/command key is currently pressed in VS Extensions
在我的扩展程序中,如果当前按下了控制(或命令)键,我想检查某个功能。这怎么可能?我找不到公开此信息的任何字段。
This question 可能有用。使用这种方法,您可以跟踪按键按下事件,然后判断按键代码是否等于命令(Safari/Chrome 上为 91 或 93,Firefox 上为 224)或控件。从那里,如果此 returns 为真,您可以添加您的功能,或者您想要构造它
这不会直接回答您的问题,但可能有助于解决您的问题:
您的扩展可以提供两个不同的命令:例如第一个命令 myextension.runTarget
(noDebug=true
) 和 myextension.debugTarget
(noDebug=false
)。此外,您的扩展可以提供将这两个命令绑定到不同热键的键绑定,例如 CTRL + F5 并且仅 F5.
看起来 vscode 本身也是这样做的(键绑定视图的屏幕截图):
如果你阅读了下面的文章
https://code.visualstudio.com/docs/extensionAPI/patterns-and-principles
它说
Visual Studio Code has a very rich extensibility model and there are many ways to extend the tool. However, we do not provide direct access to the underlying UI DOM to extension writers. With VS Code, we’re continually trying to optimize use of the underlying web technologies to deliver an always available, highly responsive editor and we will continue to tune our use of the DOM as these technologies and our product evolve. To maintain performance and compatibility, we run extensions in their own host process and prevent direct access to the DOM. VS Code also includes a built-in set of UI components for common scenarios such as IntelliSense, so that these experiences are consistent across programming languages and extensions and extension developers do not need to build their own.
We realize that this approach may initially feel restrictive to extension developers. We’re always looking for ways to improve our extensibility model and expand the capabilities available to extensions. We look forward to hearing your feedback and ideas.
这意味着您的扩展代码根本 运行 编辑器 window 上下文。而且你不能侵入 webview,因为扩展 api 不提供它。因此,您需要向 VScode 团队提出功能请求,并要求他们公开最后的键盘事件或至少公开 Shift
、Ctrl
和 alt
键的状态。目前他们只是丢弃它并扔掉它(如果没有打开编辑器)否则他们在检查任何快捷方式组合之前将它发送到摩纳哥编辑器
在我的扩展程序中,如果当前按下了控制(或命令)键,我想检查某个功能。这怎么可能?我找不到公开此信息的任何字段。
This question 可能有用。使用这种方法,您可以跟踪按键按下事件,然后判断按键代码是否等于命令(Safari/Chrome 上为 91 或 93,Firefox 上为 224)或控件。从那里,如果此 returns 为真,您可以添加您的功能,或者您想要构造它
这不会直接回答您的问题,但可能有助于解决您的问题:
您的扩展可以提供两个不同的命令:例如第一个命令 myextension.runTarget
(noDebug=true
) 和 myextension.debugTarget
(noDebug=false
)。此外,您的扩展可以提供将这两个命令绑定到不同热键的键绑定,例如 CTRL + F5 并且仅 F5.
看起来 vscode 本身也是这样做的(键绑定视图的屏幕截图):
如果你阅读了下面的文章
https://code.visualstudio.com/docs/extensionAPI/patterns-and-principles
它说
Visual Studio Code has a very rich extensibility model and there are many ways to extend the tool. However, we do not provide direct access to the underlying UI DOM to extension writers. With VS Code, we’re continually trying to optimize use of the underlying web technologies to deliver an always available, highly responsive editor and we will continue to tune our use of the DOM as these technologies and our product evolve. To maintain performance and compatibility, we run extensions in their own host process and prevent direct access to the DOM. VS Code also includes a built-in set of UI components for common scenarios such as IntelliSense, so that these experiences are consistent across programming languages and extensions and extension developers do not need to build their own.
We realize that this approach may initially feel restrictive to extension developers. We’re always looking for ways to improve our extensibility model and expand the capabilities available to extensions. We look forward to hearing your feedback and ideas.
这意味着您的扩展代码根本 运行 编辑器 window 上下文。而且你不能侵入 webview,因为扩展 api 不提供它。因此,您需要向 VScode 团队提出功能请求,并要求他们公开最后的键盘事件或至少公开 Shift
、Ctrl
和 alt
键的状态。目前他们只是丢弃它并扔掉它(如果没有打开编辑器)否则他们在检查任何快捷方式组合之前将它发送到摩纳哥编辑器