> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# 禁止右键与按键

## 1、禁止鼠标右键菜单

```javascript title="代码示例"
// 屏蔽鼠标右键菜单
document.oncontextmenu = function () {
    return false;
};

document.addEventListener("contextmenu", (e) => e.preventDefault());
```

```html title="代码示例"
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <link rel="icon" href="/favicon.ico" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Vite App</title>
    </head>
    <!-- 禁用鼠标右键菜单 -->
    <body oncontextmenu="self.event.returnValue = false">
        <div id="app"></div>
        <script type="module" src="/src/main.js"></script>
    </body>
</html>
```

## 2、禁止键盘按键事件

```javascript title="代码示例"
window.onload = function () {
    document.onkeydown = function () {
        let e = window.event || arguments[0];
        if (e.keyCode == 123) {
            return false;
        } else if (e.ctrlKey && e.shiftKey && e.keyCode == 73) {
            return false;
        } else if (e.ctrlKey && e.keyCode == 85) {
            return false;
        }
    };
    // 屏蔽鼠标右键菜单
    document.oncontextmenu = function () {
        return false;
    };
};
```
