瀏覽代碼

禁用windows键

Michael Wang 5 年之前
父節點
當前提交
c241da6172
共有 2 個文件被更改,包括 37 次插入0 次删除
  1. 2 0
      src/main.js
  2. 35 0
      src/utils/hotkeys.js

+ 2 - 0
src/main.js

@@ -17,6 +17,8 @@ import "./styles/global.css";
 import axiosPlugin from "./utils/axios";
 import "./utils/axiosRetry";
 import "./utils/monitors";
+// 不能禁用windows键,否则会当做病毒,暂时不做此限制
+// import "./utils/hotkeys";
 import "webrtc-adapter";
 
 import MainLayout from "@/components/MainLayout/MainLayout.vue";

+ 35 - 0
src/utils/hotkeys.js

@@ -0,0 +1,35 @@
+import { createLog } from "@/utils/logger";
+
+if (typeof nodeRequire !== "undefined") {
+  console.log("考生端,disable key");
+  createLog({
+    page: "electron",
+    action: "禁用key",
+  });
+
+  let remote = window.nodeRequire("electron").remote;
+  // const { electron, dialog } = remote;
+  // console.log(remote);
+  // Module to control application life.
+  // const app = remote.app;
+  const { globalShortcut } = remote;
+  // app.whenReady().then(() => {
+  // Register a 'CommandOrControl+Y' shortcut listener.
+  if (globalShortcut.isRegistered("Super+Y")) {
+    console.log("reged");
+    createLog({
+      page: "electron",
+      action: "reged->unreg",
+    });
+    globalShortcut.unregisterAll();
+  }
+  // globalShortcut.registerAll(["Super+Tab"], () => {
+  globalShortcut.register("Super+Y", () => {
+    console.log("key clicked");
+    createLog({
+      page: "electron",
+      action: "禁用key-pressed",
+    });
+    // Do stuff when Y and either Command/Control is pressed.
+  });
+}