解决 ctrl ++ 无法放大问题

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("快捷键注册失败");
    }
  });
posted @ 2024-12-25 09:44  暖暖De幸福  阅读(116)  评论(0)    收藏  举报