5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-18 09:59:31 +08:00
wails/website/i18n/zh-Hans/docusaurus-plugin-content-docs/version-v2.9.0/guides/mouse-buttons.mdx
Lea Anthony 8b215a9b4c
v2.9.0
2024-06-16 10:34:01 +10:00

26 lines
820 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 鼠标按钮
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