Shortcuts in-game?

Hi,
there is a way to use windows shortcuts in-game? A plugin can do it?
For example: I have this " %SystemRoot%\System32\shutdown.exe /s " which is a shortcut to turn off my PC; well, can I use this, in some way, in an event in order to turn off the pc in-game?
Thanks
Heeeer,I don't think that would be cool, like I'm playing and my shortcut closes.
How to use a shell or launch processes through nodejs is written inside of the nodejs documentation. I've never gotten either to work, but it is a possibility. You can inject that into an event's script command, the 10 lines capacity it offers should be enough.
Not going to lie but your questions make it seem a lot more like you're making some sort of spyware vs an actual game. Shutting down Windows in this thread, or in your other thread "receive information from the PC". Not saying you are, but er... I don't think anybody here is going to be okay with a game that does stuff like that. :hswt2:
Not going to lie but your questions make it seem a lot more like you're making some sort of spyware vs an actual game. Shutting down Windows in this thread, or in your other thread "receive information from the PC". Not saying you are, but er... I don't think anybody here is going to be okay with a game that does stuff like that. :hswt2:

I don't understand the problem, I never said that the game should shut down the PC at random.
Since I intend to play only with a joystick it is more convenient if I can switch off the PC directly from the game instead of doing it manually.
I could use the command from the pause menu at the end of my game session, for example.
Code:
var path=require('path');
nw.Shell.openExternal(path.resolve("index.html"));
This seems to work. Just replace index.html with whatever you're trying to open.
I haven't tried it with shortcuts, but I've gotten it to run cmd files so just about anything should be possible.
Code:
var path=require('path');
nw.Shell.openExternal(path.resolve("index.html"));
This seems to work. Just replace index.html with whatever you're trying to open.
I haven't tried it with shortcuts, but I've gotten it to run cmd files so just about anything should be possible.

When I put a shortcut in it, it says "nw is not defined" (I must use it as a script call, right?)
When I put a shortcut in it, it says "nw is not defined" (I must use it as a script call, right?)
Yes, a script call.
We must be using different versions. I've adjusted the code.
I also found a problem where my pevious code didn't work in deployed projects, but it should work now.

Try this code:
Code:
var path=require('path');
var nw=require('nw.gui');
nw.Shell.openItem(path.resolve(($gameTemp._isPlaytest?'':'www/')+"test.cmd"));
Once again, just replace test.cmd with the file you want to open.
Yes, a script call.
We must be using different versions. I've adjusted the code.
I also found a problem where my pevious code didn't work in deployed projects, but it should work now.

Try this code:
Code:
var path=require('path');
var nw=require('nw.gui');
nw.Shell.openItem(path.resolve(($gameTemp._isPlaytest?'':'www/')+"test.cmd"));
Once again, just replace test.cmd with the file you want to open.

Thank you very much for your patience and for your help!
I'll test it as soon as possible and I'll let you know if it works! Thank you again ^^
Yes, a script call.
We must be using different versions. I've adjusted the code.
I also found a problem where my pevious code didn't work in deployed projects, but it should work now.

Try this code:
Code:
var path=require('path');
var nw=require('nw.gui');
nw.Shell.openItem(path.resolve(($gameTemp._isPlaytest?'':'www/')+"test.cmd"));
Once again, just replace test.cmd with the file you want to open.

That's awesome, I was able to open a music file while playtesting!
I would like to take this opportunity to ask you a thing;
After I closed the music file the lag during the game test has increased. Is it possible that the script leaves some processes open? Do you have any idea?
However, thank you a lot, cuz this is a great thing! :3
@Mark91
nw.Shell.openItem() should be able to open any file on your computer, you just need to pass in the path as a string.

Note thought that in javascript backslash is used as an escape character, so you either need to escape them:
Code:
nw.Shell.openItem("C:\\Users\\dread\\Documents\\file.txt");
Convert them into forward slashes:
Code:
nw.Shell.openItem("C:/Users/dread/Documents/file.txt");
Or use String.raw:
Code:
nw.Shell.openItem(String.raw`C:\Users\dread\Documents\file.txt`);

---

If you were to distrubute your game, using absolute file paths wouldn't be good because the user likely would have the game installed somewhere different from you. That's where my previous code comes in.
Code:
path.resolve(($gameTemp._isPlaytest?'':'www/')+"test.cmd")
This code gets the full path of the file "test.cmd" in your game directory.
For me it returns "C:\Users\dread\Documents\RPG Maker\RMMV\MV3D\test.cmd"

---

If you want to get the documents folder programmatically, you can do it like this:
Code:
var os = require("os");
var documents = path.resolve(os.homedir(),"Documents");
And then to open a file in that folder,
Code:
nw.Shell.openItem(path.resolve(documents,"file.txt"));

---

After I closed the music file the lag during the game test has increased. Is it possible that the script leaves some processes open? Do you have any idea?
The script just tells the os to open the file with whatever default file associations it has, so there shouldn't be any more lag than from opening the file normally.
However computers typically aren't good at multitasking, so it's possible your computer was running low on memory so it loaded the game's memory into a page file. Then when you switched back to the game it had to read the memory back from the page file.
@Mark91
nw.Shell.openItem() should be able to open any file on your computer, you just need to pass in the path as a string.

Note thought that in javascript backslash is used as an escape character, so you either need to escape them:
Code:
nw.Shell.openItem("C:\\Users\\dread\\Documents\\file.txt");
Convert them into forward slashes:
Code:
nw.Shell.openItem("C:/Users/dread/Documents/file.txt");
Or use String.raw:
Code:
nw.Shell.openItem(String.raw`C:\Users\dread\Documents\file.txt`);

---

If you were to distrubute your game, using absolute file paths wouldn't be good because the user likely would have the game installed somewhere different from you. That's where my previous code comes in.
Code:
path.resolve(($gameTemp._isPlaytest?'':'www/')+"test.cmd")
This code gets the full path of the file "test.cmd" in your game directory.
For me it returns "C:\Users\dread\Documents\RPG Maker\RMMV\MV3D\test.cmd"

---

If you want to get the documents folder programmatically, you can do it like this:
Code:
var os = require("os");
var documents = path.resolve(os.homedir(),"Documents");
And then to open a file in that folder,
Code:
nw.Shell.openItem(path.resolve(documents,"file.txt"));

---


The script just tells the os to open the file with whatever default file associations it has, so there shouldn't be any more lag than from opening the file normally.
However computers typically aren't good at multitasking, so it's possible your computer was running low on memory so it loaded the game's memory into a page file. Then when you switched back to the game it had to read the memory back from the page file.

Well, thank you a lot, it works perfectly for me, and I didn't expect such help!
If you have any donation links let me know and I'll give my contribution! ^^
Thank you again

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/shortcuts-in-game.114469/