first commit
This commit is contained in:
BIN
day03-global-shotcut/c.png
Normal file
BIN
day03-global-shotcut/c.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 105 KiB |
11
day03-global-shotcut/index.html
Normal file
11
day03-global-shotcut/index.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>全局快捷键</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>全局快捷键</h2>
|
||||
<script src="index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
3
day03-global-shotcut/index.js
Normal file
3
day03-global-shotcut/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
window.onload = () => {
|
||||
|
||||
}
|
||||
44
day03-global-shotcut/main.js
Normal file
44
day03-global-shotcut/main.js
Normal file
@@ -0,0 +1,44 @@
|
||||
const { app, BrowserWindow, globalShortcut } = require('electron')
|
||||
|
||||
const createWindow = () => {
|
||||
let mainWin = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 400,
|
||||
show: false,
|
||||
webPreferences: {
|
||||
enableRemoteModule: true,
|
||||
nodeIntegration: true
|
||||
}
|
||||
})
|
||||
|
||||
mainWin.loadFile('index.html')
|
||||
mainWin.on('ready-to-show', mainWin.show)
|
||||
mainWin.on('close', () => {
|
||||
mainWin = null
|
||||
})
|
||||
}
|
||||
|
||||
app.on('ready', createWindow)
|
||||
|
||||
app.on('ready', () => {
|
||||
// 注册
|
||||
let ret = globalShortcut.register('ctrl + q', () => {
|
||||
console.log("快捷键注册成功")
|
||||
})
|
||||
|
||||
if (!ret) {
|
||||
console.log('注册失败')
|
||||
}
|
||||
|
||||
console.log(globalShortcut.isRegistered('ctrl + q'))
|
||||
|
||||
console.log(ret, '~~~~~')
|
||||
|
||||
})
|
||||
|
||||
app.on('will-quit', () => {
|
||||
globalShortcut.unregister('ctrl + q')
|
||||
globalShortcut.unregisterAll()
|
||||
})
|
||||
|
||||
app.on('window-all-closed', app.quit)
|
||||
1396
day03-global-shotcut/package-lock.json
generated
Normal file
1396
day03-global-shotcut/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
17
day03-global-shotcut/package.json
Normal file
17
day03-global-shotcut/package.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "electron-life-cycle",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"start": "nodemon --watch main.js --exec npm run build",
|
||||
"build": "electron ."
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"electron": "^11.2.1",
|
||||
"nodemon": "^3.1.9"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user