Skip to content

Commit

Permalink
Merge pull request #242 from andro404-MC/master
Browse files Browse the repository at this point in the history
Fixed the `Escape` key not working outside of the application (#241)
  • Loading branch information
hmlendea authored Jun 7, 2024
2 parents c1db203 + 131698a commit feb0846
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 38 deletions.
27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
},
"dependencies": {
"discord-rich-presence": "^0.0.8",
"electron-localshortcut": "^3.2.1",
"find-process": "^1.4.7"
}
}
77 changes: 39 additions & 38 deletions scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { app, globalShortcut, BrowserWindow, session } = require('electron');
const { app, BrowserWindow, session } = require('electron');
const electronLocalshortcut = require('electron-localshortcut');
const findProcess = require('find-process');
const fs = require('fs');
const path = require('path');
Expand Down Expand Up @@ -99,59 +100,59 @@ app.whenReady().then(async () => {
}
});

globalShortcut.register('Super+F', async () => {
electronLocalshortcut.register('Super+F', async () => {
switchFullscreenState();
});

globalShortcut.register('F11', async () => {
electronLocalshortcut.register('F11', async () => {
switchFullscreenState();
});

globalShortcut.register('Alt+F4', async () => {
electronLocalshortcut.register('Alt+F4', async () => {
app.quit();
});

globalShortcut.register('Alt+Home', async () => {
electronLocalshortcut.register('Alt+Home', async () => {
BrowserWindow.getAllWindows()[0].loadURL(homePage);
});

globalShortcut.register('F4', async () => {
electronLocalshortcut.register('F4', async () => {
app.quit();
});

globalShortcut.register('Control+Shift+I', () => {
electronLocalshortcut.register('Control+Shift+I', () => {
BrowserWindow.getAllWindows()[0].webContents.toggleDevTools();
});

globalShortcut.register('Esc', async () => {
var window = BrowserWindow.getAllWindows()[0];

window.webContents.sendInputEvent({
type: 'keyDown',
keyCode: 'Esc'
});
window.webContents.sendInputEvent({
type: 'char',
keyCode: 'Esc'
});
window.webContents.sendInputEvent({
type: 'keyUp',
keyCode: 'Esc'
});

window.webContents.sendInputEvent({
type: 'keyDown',
keyCode: 'Esc'
});
window.webContents.sendInputEvent({
type: 'char',
keyCode: 'Esc'
});
window.webContents.sendInputEvent({
type: 'keyUp',
keyCode: 'Esc'
});
});
// electronLocalshortcut.register('Esc', async () => {
// var window = BrowserWindow.getAllWindows()[0];
//
// window.webContents.sendInputEvent({
// type: 'keyDown',
// keyCode: 'Esc'
// });
// window.webContents.sendInputEvent({
// type: 'char',
// keyCode: 'Esc'
// });
// window.webContents.sendInputEvent({
// type: 'keyUp',
// keyCode: 'Esc'
// });
//
// window.webContents.sendInputEvent({
// type: 'keyDown',
// keyCode: 'Esc'
// });
// window.webContents.sendInputEvent({
// type: 'char',
// keyCode: 'Esc'
// });
// window.webContents.sendInputEvent({
// type: 'keyUp',
// keyCode: 'Esc'
// });
// });
});

app.on('browser-window-created', async function (e, window) {
Expand Down Expand Up @@ -185,7 +186,7 @@ app.on('child-process-gone', (event, details) => {
});

app.on('will-quit', async () => {
globalShortcut.unregisterAll();
electronLocalshortcut.unregisterAll();
});

app.on('window-all-closed', async function () {
Expand All @@ -207,4 +208,4 @@ function isDiscordRunning() {
resolve(false);
});
});
}
}

0 comments on commit feb0846

Please sign in to comment.