const { app, BrowserWindow, globalShortcut, webContents } = require("electron");
app.on("ready", async () => {
createWindow();
globalShortcut.register("Ctrl+=", () => {
// 获取当前窗口的webContents
const currentWebContents = webContents.getFocusedWebContents();
if (currentWebContents) {
// 增加缩放级别
const level = currentWebContents.getZoomLevel() + 1;
currentWebContents.setZoomLevel(level);
}
// 这里放置快捷键触发时的操作
});
// 也可以检查快捷键是否注册成功
if (!globalShortcut.isRegistered("Ctrl+=")) {
console.error("快捷键注册失败");
}
});