Can now kill game exe with globalshortcut

This commit is contained in:
Vaclav Siml 2023-02-25 00:00:20 +01:00
parent cc59ade8b6
commit 3e4a7335ea
3 changed files with 61 additions and 28 deletions

View file

@ -1,3 +1,4 @@
//Paths //Paths
var AsphyxiaPath = "C:\\Users\\kryvas\\Downloads\\asphyxia-core-win-x64\\asphyxia.exe" var AsphyxiaPath = "C:\\Users\\kryvas\\Downloads\\asphyxia-core-win-x64\\asphyxia.exe"
var SDVX3Path = "C:\\sdvx\\spice2.lnk" var SDVX3Path = "C:\\sdvx\\spice2.lnk"
@ -10,5 +11,8 @@ var KeyDown = "KeyS"
var KeyLeft = "KeyA" var KeyLeft = "KeyA"
var KeyRight = "KeyD" var KeyRight = "KeyD"
var KeyStart = "KeyE" var KeyStart = "KeyE"
var ExitKey1 = "g" // Only add lowercase name of the key without "Key" part example: "KeyA" becomes "a" var ExitKey1 = "G" // Only add uppercase name of the key without "Key" part example: "KeyA" becomes "A"
var ExitKey2 = "h" // Only add lowercase name of the key without "Key" part example: "KeyA" becomes "a" var ExitKey2 = "H" // Only add uppercase name of the key without "Key" part example: "KeyA" becomes "A"
if(module) // kdyz to neimportujes pres require tak module bude undefined
module.exports = { ExitKey1, ExitKey2 };

View file

@ -46,7 +46,7 @@
<script> <script>
const prvnihra = [...document.querySelectorAll("button")] //creates array from buttons for focus select const prvnihra = [...document.querySelectorAll("button")] //creates array from buttons for focus select
console.log(prvnihra[0]) console.log(prvnihra[0])
prvnihra[0].focus(); prvnihra[0].focus();
</script> </script>
@ -95,18 +95,7 @@
//document.body.requestFullscreen(); //document.body.requestFullscreen();
}) })
let keysPressed = {};
document.addEventListener('keydown', (event) => {
keysPressed[event.key] = true;
if (keysPressed[ExitKey1] && event.key == ExitKey2) {
alert(event.key);
}
});
document.addEventListener('keyup', (event) => {
delete keysPressed[event.key];
});
</script> </script>
@ -118,29 +107,37 @@
const { execFile, exec, spawn } = require('child_process'); const { execFile, exec, spawn } = require('child_process');
function sdvx() { function sdvx() {
console.log("promenna", vers); console.log("promenna", vers);
const { ipcRenderer } = require('electron');
/* Handles Running of apps */ /* Handles Running of apps */
switch (vers) { switch (vers) {
case 3: case 3:
Execounter = 1;
execFile(AsphyxiaPath); execFile(AsphyxiaPath);
exec("start /b " + SDVX3Path); //executes cmd with start and path exec("start /b " + SDVX3Path); //executes cmd with start and path
setTimeout(function () { setTimeout(function () {
exec("taskkill /im " + browser)//kills browser exec("taskkill /im " + browser)//kills browser
}, 2000) }, 2000)
//console.log(vers); //console.log(vers);
ipcRenderer.send("number", Execounter); //sends number to main which tells main what to kill on shortcut
break; break;
case 4: case 4:
Execounter = 2;
execFile(AsphyxiaPath); execFile(AsphyxiaPath);
exec("start /b " + SDVX4Path); exec("start /b " + SDVX4Path);
setTimeout(function () { setTimeout(function () {
exec("taskkill /im " + browser) exec("taskkill /im " + browser)
}, 1200) }, 1200)
ipcRenderer.send("number", Execounter);
break; break;
case 5: case 5:
Execounter = 3;
execFile(AsphyxiaPath); execFile(AsphyxiaPath);
exec("start /b " + SDVX5Path); exec("start /b " + SDVX5Path);
setTimeout(function () { setTimeout(function () {
exec("taskkill /im " + browser) exec("taskkill /im " + browser)
}, 1200) }, 1200)
ipcRenderer.send("number", Execounter);
break; break;
case 6: case 6:

View file

@ -1,7 +1,12 @@
const { app, BrowserWindow } = require('electron'); const { app, BrowserWindow, ipcMain } = require('electron');
const { globalShortcut } = require('electron'); const { globalShortcut } = require('electron');
const createWindow = () => { const createWindow = () => {
// Create the browser window. ipcMain.on("number",(event,data)=>{ //Reads number var from index
console.warn(data)
Execounter = data;
console.warn(Execounter)
})
// Create the browser window.
mainWindow = new BrowserWindow({ mainWindow = new BrowserWindow({
width: 800, width: 800,
height: 600, height: 600,
@ -12,12 +17,39 @@ const createWindow = () => {
}, },
autoHideMenuBar: true autoHideMenuBar: true
}); });
mainWindow.loadFile("index.html") //loadne index.html mainWindow.loadFile("index.html") //loads index.html
}; };
app.whenReady().then(() => { app.whenReady().then(() => {
createWindow(); createWindow();
const { ExitKey1, ExitKey2 } = require("./Vars.js") //imports exitkeys from vars.js
const { execFile, exec, spawn } = require('child_process');
console.log(ExitKey1 + " + " + ExitKey2);
const ret = globalShortcut.register(ExitKey1 + " + " + ExitKey2, () => { //makes globalshortcut from vars in vars.js const ret = globalShortcut.register(ExitKey1 + " + " + ExitKey2, () => { //makes globalshortcut from vars in vars.js
console.log('CommandOrControl+X is pressed') console.log('CommandOrControl+X is pressed')
}); //On shortcut kills game exe
switch(Execounter){
case 1:
console.warn("funguje" + Execounter);
exec("taskkill /im spice.exe")
break;
case 2:
console.warn("funguje" + Execounter);
exec("taskkill /im spice.exe")
break;
case 3:
console.warn("funguje" + Execounter);
exec("taskkill /im spice.exe")
break;
default:
break;
}
})
});