前言
项目需要一个功能-霸屏,并且用户不能通过alt+tab、win+tab来切换窗口。其他的都容易,就是这个禁止系统快捷键不好弄,网上查了一下都是挂羊头卖狗肉的,点进去都是globalShortcut。globalShortcut这个能实现个der。
最后只能编写Node.js C++ Addon来实现,叫我写C++那是万万不能的,但是AI是万万可以的,剩下的交给AI了,我只管提需求、规划文档、测试就可以了。
后面有Node.js C++ Addon仓库地址,需要的可以使用。
正文
如何编写C++代码没什么好说的,因为不是我写的,我也看不懂。但是我可以教你们如何在Electron中使用。
- 先将包打出来得到
build文件夹
js
npm i
npm build
- 在
Electron中创建目录放置

- 放入
build文件夹和index.js文件

- 还缺少一个
package.json文件
json
{
"name": "block-system-shortcuts",
"version": "1.0.0",
"description": "Native module for blocking system shortcuts",
"main": "index.js",
"keywords": ["electron", "native", "shortcuts", "windows", "macos"],
"author": "MoreD",
"license": "MIT",
"engines": {
"node": ">=16.0.0"
}
}
- 在项目中安装这个本地模块

记得要重新安装一下依赖
sh
//我的是用pnpm
pnpm i
- 在项目中使用
然后就可以在项目中使用了

结语
感谢Cursor的大力支持!!
感兴趣的可以去试试,还有别的按键需要禁用的,可以让Cursor继续编写代码