Home > SCH_Event > addMouseEventListener
SCH_Event.addMouseEventListener() method
Add a mouse event listener
Signature
typescript
function addMouseEventListener(
id: string,
eventType: 'all' | ESCH_MouseEventType,
callFn: (eventType: ESCH_MouseEventType) => void | Promise<void>,
onlyOnce?: boolean,
): void;1
2
3
4
5
6
2
3
4
5
6
Parameters
Parameter | Type | Description |
|---|---|---|
id | string | Event ID, used to prevent duplicate event registration |
eventType | 'all' | ESCH_MouseEventType | Event type |
callFn | (eventType: ESCH_MouseEventType) => void | Promise<void> | The callback function triggered when the event fires |
onlyOnce | boolean | (Optional) Whether to listen only once |
Returns
void
Remarks
Note: This API is only valid for extensions. Calling it in a standalone script environment will always throw Error
Example
javascript
const listenerId = '嘉立创示例_sch_mouse_event';
// 1. 注册鼠标事件监听,eventType 用 'all' 接收全部鼠标事件,onlyOnce 为 false 持续监听
eda.sch_Event.addMouseEventListener(
listenerId,
'all',
(eventType) => {
// 回调在用户画布操作时触发
console.log('mouseEvent:', eventType);
},
false
);
// 2. 回读确认注册成功
const registered = eda.sch_Event.isEventListenerAlreadyExist(listenerId);
console.log('registered:', registered);
// 3. 清理监听
const removed = eda.sch_Event.removeEventListener(listenerId);
console.log('removed:', removed);1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20