BrowserWindow - win.setIgnoreMouseEvents(ignore[, options])

概述

设置窗口是否忽略所有鼠标事件(穿透)。

基本信息

属性
模块 BrowserWindow
类型 Method
鸿蒙支持 支持

OHOS 依赖与基本表现

属性
系统权限依赖 无需申请
主窗 支持
子窗 支持
悬浮窗 支持
添加JIT权限 支持
坚盾模式 支持

差异说明

属性
是否存在差异 存在差异
差异说明 setIgnoreMouseEvents 在触屏为主的鸿蒙环境下,事件穿透与桌面鼠标场景差异较大,不支持部分穿透参数

Demo

const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');

let mainWindow = null;
let childWindow = null;

function sendLog(type, message) {
  if (mainWindow && !mainWindow.isDestroyed()) {
    mainWindow.webContents.send('log-message', { type, message, time: new Date().toLocaleTimeString() });
  }
}

app.whenReady().then(() => {
  mainWindow = new BrowserWindow({
    width: 1400, height: 900,
    webPreferences: { preload: path.join(__dirname, '..', 'preload.js'), contextIsolation: true, nodeIntegration: false },
    title: 'Test setIgnoreMouseEvents and restore',
  });
  mainWindow.loadFile(path.join(__dirname, '..', 'index.html'));

  ipcMain.handle('method:setIgnoreMouseEvents-and-restore', async () => {
    mainWindow.setIgnoreMouseEvents(true);
    const ignored = true;
    mainWindow.setIgnoreMouseEvents(false);
    return { ignored, restored: true };
  });
});

app.on('window-all-closed', () => { app.quit(); });