02.5 Adding NirCmd to your Arsenal

How can be this controlled in that simulator? Can HIDmacros be used with this application?
Post Reply
Baobob
Posts: 15
Joined: 12 Oct 2011, 02:59

02.5 Adding NirCmd to your Arsenal

Post by Baobob » 30 Nov 2011, 03:33

You may have heard of a little freeware program called NirCmd. I first heard of it right here in these forums. What I didn't hear was just how pwoerful a tool it is when combined with the already amazing HID macros. Well let me tell you with the two of them combined I HID macros can even start my car... No kidding, the real one out in my driveway. It can control the lighting in my home, set my thermostat, boot my 14 year old son off YouTube and send him a message to get back to his schoolwork...

So just imagine what together they can do for your flight simulator...

Remember in the last episode when we ran into difficulty processing certain hotkey combinations from the scripting portion of HID macros? Well what if it was as easy as

Code: Select all

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run ("nircmd.exe sendkeypress shift+ctrl+a+b")
= Ctrl + Shift + A + B

Three things right off the bat...

First it's not a "one liner" there are two lines of code here!
Second, for those of you who already know better, there darn well should be three lines of code there!!
Third... What the hell is a+b doing in that last line of code???

Well first... Relax you had to move out of one liners eventually and It's a lot simpler than it may seem at first glance.
Second... I'll fix it in a minute, I just didn't want the people already upset over this not being a one liner to fall off their chairs and begin convulsing on the floor due to the sheer overwhelming nature of a third line of code. What do you mean it's not overwhelming? I have you know that just last week I saw the heads of three co workers literally explode at the very thought of switching to Office 2010 from Office 2007.
Finally... Third, If you don't know what it's doing there... you're in for a treat.

So onward to fix and explain as best I can... And don't be afraid to correct me. I'm just trying to get as much information out there in a way that people can learn from it as I can. The code should really look like this:

Code: Select all

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run ("nircmd.exe sendkeypress shift+ctrl+a+b")
LIne 01 From what I can gather line 1 is just a declaration of a variable... "DON"T ANYBODY USE WshShell IT"S MINE!@!! - why it's spelled Dim is beyond me. I could have just as easily put "Dim SmellySock" and it would have made no difference. So great, I've declared it... Now what... Lets create something with it.

Line 02 Here we define what we want... an object named WshShell that we can boss around and we want that object to be a spacific type of object WScript.Shell

Line 3 Line three is the action script, where we get to boss our object around. We could make our object do lots of fun things, and different objects are able to do different kinds of things, but in this case we want it to run a little program called NirCmd.exe with a few command line parameters attached to it. That's right, the stuff inside the quotes. If I open up an command prompt and type in nircmd.exe sendkeypress shift+ctrl+a+b it would do the same thing as this scropt. The program we are running is NirCmd, the command we are giving that program (as per the programs design) is sendkeypress, and the keys to be pressed are shift+ctrl+a+b. The reason I don't have a path in front of the program is because I use it so much I put it in my windows directory. Putting NirCmd in your HID macros directory will have the same effect when using NirCmd from within HID macros. since the script is being run be a program in that folder that is the first place windows looks for the exe if no path is specified.

Don't forget this same script can be used to run other programs as well, just replace the path and file with whatever it is you want to run:

Code: Select all

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run ("YourPathAndFileHere")
Have you figured it out yet? All I did is just show you how to run an application from the script rather than from the predefined "Run Application" box. Not that there is anything wrong with doing it that way if you only have one thing to do. But I want to show you this way so you can do MORE than one thing... like three FSX events a few key combos and... well it's a surprise.

Now... on to the NirCmd.exe itself I could write all day about the possibilities on key combinations alone, Instead I'll just point you in the direction of their website and let them explain it. But first let me get back to something I left out...

Item three from out list up top. What's up with the a+b in my key combination anyway? I was absolutely shocked when I started flying on myltiplayer servers at the number of people who even after flying for YEARS had no idea that FSX can use ANY regular key as a modifier. Actually it cheats and just allows two regular keys when pressed together, but the effect is the same... Keys to freaking spare if you are willing to let FSX handle them. For example "A" can be assigned "B" can be assigned and "A + B" can be assigned. Up to two normal modifiers and up to two regular keys all at the same time.

All that being said I present to you http://www.nirsoft.net/utils/nircmd.zip and http://www.nirsoft.net/utils/nircmd-x64.zip

The main "help file" page is http://www.nirsoft.net/utils/nircmd2.html#using but I find the reference section http://nircmd.nirsoft.net/sendkeypress.html to be much easier to find things on.
Fly Well,
Bao

"Getting it up there is all well and good. Lets just get it back down in one piece shall we?"

jagian
Posts: 3
Joined: 02 Apr 2015, 12:39

Re: 02.5 Adding NirCmd to your Arsenal

Post by jagian » 02 Apr 2015, 12:52

Hi:

Very insteresting post. I'm new in here, but i've tested the scripts with NirCmd and works nice.
But, the scripts to run apps doesn't work for me:

Code: Select all

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run ("YourPathAndFileHere")
..i put a path for an application (copied directly from a shortcut or Hidmacros itself (from predefined/run application), and doesn't work.
The message that i see each time is: "the system cannot find the file specified".

So i ask you if you could post a specific example of how i must type the correct path in this script?...i confirm that if i use the same path from the predefined (not the scripted) option, and it works perfectly...so maybe i m doing something wrong ? or the script doesnt work?

Thanks in advanced.

loban
Posts: 1
Joined: 24 Jul 2015, 20:44

Re: 02.5 Adding NirCmd to your Arsenal

Post by loban » 24 Jul 2015, 20:54

May be a bit late, but it should look like this:

Code: Select all

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run ("C:\Windows\notepad.exe")
Did you make shure to include the file extension (probably ".exe" in this case).

Greeting
Loban

Post Reply