mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-18 09:59:31 +08:00
26 lines
820 B
Plaintext
26 lines
820 B
Plaintext
# 鼠标按钮
|
||
|
||
Wails 运行时拦截鼠标单击以确定无框窗口是否需要调整大小或需要移动窗口。 有人询问如何检测鼠标点击何时发生,因为 `window.onclick` 没有正确报告鼠标按钮。 下面的代码展示了如何检测鼠标点击:
|
||
|
||
```javascript
|
||
window.addEventListener("mousedown", handleMouseButtonDown);
|
||
|
||
function handleMouseButtonDown(event) {
|
||
if (event.button === 0) {
|
||
// left mouse button
|
||
} else if (event.button === 1) {
|
||
// middle mouse button
|
||
} else if (event.button === 2) {
|
||
// right mouse button
|
||
} else if (event.button === 3) {
|
||
// back mouse button
|
||
} else if (event.button === 4) {
|
||
// forward mouse button
|
||
} else {
|
||
// other mouse button
|
||
}
|
||
}
|
||
```
|
||
|
||
参考:https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
|