如何在VSCode中实现复制(Cmd+C)操作的弹窗通知或提示音?
在VSCode中实现复制时触发弹窗/提示音
方法一:用自定义快捷键结合内置命令实现弹窗
- 打开快捷键配置文件:按下
Cmd+Shift+P(Mac),输入Preferences: Open Keyboard Shortcuts (JSON),打开keybindings.json。 - 添加以下配置,替换默认复制快捷键的同时触发信息弹窗:
[ { "key": "cmd+c", "command": "runCommands", "args": { "commands": [ "editor.action.clipboardCopyAction", "notifications.showInformationMessage" ] }, "when": "editorTextFocus && !editorReadonly" } ]
- 说明:
runCommands会批量执行命令,先完成默认复制动作,再弹出系统信息通知。
方法二:结合扩展实现自定义弹窗或提示音
如果需要自定义弹窗内容或添加提示音,可通过扩展实现:
实现提示音
- 安装
Notification Sound扩展。 - 修改
keybindings.json,绑定复制快捷键同时播放提示音:
[ { "key": "cmd+c", "command": "runCommands", "args": { "commands": [ "editor.action.clipboardCopyAction", "notification-sound.play" ] }, "when": "editorTextFocus && !editorReadonly" } ]
- 可在扩展设置页调整提示音文件、音量等参数。
实现自定义文本弹窗
- 安装
Command Runner扩展。 - 打开
settings.json,添加自定义命令:
"command-runner.commands": { "copy-with-custom-notify": [ "editor.action.clipboardCopyAction", "notifications.showInformationMessage", "内容已复制!" ] }
- 在
keybindings.json中绑定快捷键:
{ "key": "cmd+c", "command": "command-runner.run", "args": { "command": "copy-with-custom-notify" }, "when": "editorTextFocus && !editorReadonly" }
注意事项
- 若要保留终端内的默认复制行为,可在
when条件中添加&& !terminalFocus,区分编辑器和终端场景。
内容的提问来源于stack exchange,提问作者Mehdi Faraji
相关产品推荐
相关产品推荐

