Electron BrowserWindow 禁用缩放

问题描述 投票:0回答:1

如何禁用电子应用程序的缩放?我尝试了这个片段,但它不起作用。我仍然可以使用 CMD+/- 缩放内容。我需要禁用其他东西吗?

const win = new BrowserWindow({
    width: 1200,
    height: 1000,
    title: "MyApp",
    resizable: false, // Prevent resizing
    webPreferences: {
      preload: path.join(__dirname, "preload.js"),
      contextIsolation: true,
      enableRemoteModule: false,
      webSecurity: true,
      zoomFactor: 1,
      disableZoom: true,
    },
electron
1个回答
0
投票
window.webContents.on("before-input-event", (event, input) => {
  if (
    (input.control || input.meta) && // Control for Windows/Linux, Command (meta) for macOS
    (input.key === "+" || input.key === "-" || input.key === "0")
  ) {
    event.preventDefault();
    console.log(`Blocked zoom action: ${input.key}`);
  }
});

这会阻止键盘缩放命令并解决它

© www.soinside.com 2019 - 2024. All rights reserved.