Anybody here which can help with HIDMacros & VBScript?
-
Hello,
have a small problem here, with which I hope somebody could help me. My pit is
mostly based on Pokeys cards, but I also use two simple USB-Numpads and
one USB-Keyboard in conjunction with HIDMacros for input.HIDMacros is really fantastic, but there is no way to toggle a key between two
or three different states without using a script. As I’m not really good at
programming, this is a real problem for me.Have asked in the HIDMacros-forum but didn’t get a for me understoodable answer.
The problem is, I want to use a single key for example on the numpad, let’s say
its the key “1” and get HIDMacros to do something like this:first keypress –> generate an “A”
second keypress --> generate a “B”
third keypress --> generate a “C”
fourth keypress --> back to “B”
fith keypress --> back to “A”and then once again
–> generate a “B” and so on…
this way I could simulate a rotary-switch with just one button. Have managed it,
to get this running perfectly with AutoHotKey, but AHK makes no difference
between seperate devices, which means if you remap keys on one numpad, they are
remapped on all connected numpads or the numpad-section of a normal keyboard.HidMacros can make a difference between the connected devices and so you could
programm macros to one numpad and totally different macros to another.Have also experimented to use both programs together in a very complex way, with
using remaped buttons to remap those once again with AHK and also managed to get it
running even you could use different devices. But this way you run very fast out of useable
keys and my pit is running a lot of software in the background, so that another bunch of it,
just to do such a simple thing isn’t quiet clever.HIDMacros has the option to execute VBScripts, but as I said I’m not good in
programming. As far as I came, you have to use the IF and THEN varriables
in conjunction with the sendkeys method. Eventually you have to use a count
function to repeat how many keypresses are done.Is here someone, who is good in VBscripting and able to give me a small code snippet
as an example. Just to the third keypress would be nice, the rest I could do by myself
if I see how it operates. Have made it the same way with AHK, but this uses its
own scripting language and isn’t compatible with HIDMacros.Thanks alot
Viper
P.S: I know that you could use a toggle function for this in Falcon BMS (and have only to
use one single key), but I use the pit for many different simulators and some of them
couldn’t use one button for something like a simulated rotary switch or a threeway toggle in
a virtual panel. -
Rather than using the button press to generate a key press directly, assign it to a numeric value instead, increasing by one each press, then redirect the script to a an IF…THEN…ELSE subroutine.
If x=1 then
Keypress = A
Elseif x = 2 then
Keypress = B
…
Else if x = 5 then
Keypress = A
x = 1
End If -
Hallo Malc,
thanks very very much. I’ll try that. Would help me alot to save some buttons. I have built a pit which is likewise a F/A-18 but also have interchangeable HOTAS for different fighters. I have built a very small overhead panel, to fly some of the big military birds like C-5, C-17, C-130 or the C-160 Transall with use of the FSX, too. It has only two numpads and a gaming-keyboard, cause I don’t want to make such a big thing like for Falcon BMS once again.
A little bit of painting and some lettering should be enough of realism for this piece. The pit it self is enough of work. Hope I can do it this way, cause I have mistakenly thought that within FSX or FS9 things are much more simple for cockpit builders since many people build cockpits for this sim over years. Now I’ve seen its totally the other way around. Falcon BMS has one of the best support for cockpit builders ever. No way compareable to the trouble with mouse recording and use of FSUIPC in the MSFS.
-
Hello Marc,
have tried it the way you descripted, but still no luck at all. I’m not good at programming, so its possible that I have misunderstood something or its the problem of hidmacros which has only a limited vbscript support (that’s what I’ve read about it at the AHK forum).
For AHK my test-script looks like this (but AHK has its own script language):
count = 1
x::
If count = 1
{
Send A
count = 2
Return
}
Else If count = 2
{
Send B
count = 3
Return
}
Else If count = 3
{
Send C
count = 4
Return
}
Else If count = 4
{
Send D
count = 5
Return
}
Else If count = 5
{
Send C
count = 6
Return
}
Else If count = 6
{
Send B
count = 1
Return
}
ReturnThis works perfectly, but hidmacros can only use vbscript or jscript. Have tried to learn a little bit of vbscript, but it’s to complex for me, to learn enough to get this running. I’m better at electronics and mechanics
, programming was always a mystery for me
.
Have really tried many different things. A colleague of my girlfriend is a programmer and sents me a little code-example in vbscript, which he means could eventually run. It was for standard use with progs like Excel. Have adapted it for hidmacros with my limited knowledge, but no way.
Now I’ve asked Petr Medek (the author of hidmacros) in his forum again. Actually he ends hidmacros and starts his new LuaMacros project, so I hope he is willing to help with this old program anymore.
Thanks Viper
-
O.k. Petr was gracious and gave me (the old pain in the neck) some code.
Now I have to see if I could get this damned thing running.
Hope so, cause its the only way to get all functions for my pit, without having a million of switches in.
-
Still no luck! Hope I can get it running, otherwise my overhead panel is relatively useless.
I need this to control bigger aircraft, like C-5 or C-130 e.g. , which I want to fly in FSX or FS9. Mostly I have made the cockpit for use with Falcon BMS and EECH AllMods (combat helo sim), but since I’m a fan of all kind of military aircraft, I thought: “Why not use the pit to fly them too?”The idea behind this, was to use the already present fighter/helicopter cockpit, built a small overhead which is only based on a few numpads and running hidmacros to execute the keyboard emulation. It should be as simple as possible, cause I don’t want to built another half pit.
It shouldn’t be very realistic, I just want to have a few switches like the lights, engine starter and some electrics at it. For more complex inputs to the overhead panel of those “military airliners” I connected an external trackpad to it. So you could control the mouse input “overhead” to the virtual panels.
The problem is, that a lot of the switches at those panels are rotaries. So if I want to control some of the more important functions directly, without the circuitous use of the trackpad, I have to find a way to control a rotary with a keyboard key.The idea was to “toggle” the function, in that way the old software of the TM FLCS/TQS or the Cougar could do this with their buttons. Goes something like this, press once and generate an “A”, press twice and generate a “B”, press third a “C” and fourth go back to “B”, than “A” and so on. Up and Down in a loop. This way I could control a rotary with just one keypress. As I have only a limited number of keys at the numpad, I thought this is a clever idea.
But the problem is, the program which could do this, AutoHotkey, could not differ between the connected numpads. Press one key on numpad one, makes the same thing as pressing the according key on numpad two. The up down sequence for my “rotary emulation” runs perfectly.
The other program which can do keyboard emulation is hidmacros. This one could even differ between connected devices, so you could use two numpads and program totally different macros to them. This is actually a fantastic thing, but with its userfriendly GUI you could only do very limited keyboard functions. For more complex things you have to use a vbscript. That’s where the whole thing started.
At first I tried a combination of both. Remap a key on one numpad with hidmacros to an unused keycombination, which fires up an AHK-script with the same keycombination as hotkey and does the toggle function. Runs perfectly, but isn’t a very clever solution. To many things run within the background. Under testing conditions there isn’t a problem, but how does things look like later, if the whole pit is running with a lot more software in the background?
So I have to get this “toggle” running with hidmacros standalone. In this case I must use VBscript!
So if anybody has an idea, please help me!
Many, many thanks
Viper
P.S: I know that you can use the FSUIPC in MSFS, but as most of the switches on more complex birds are “mouse only” switches, you have to create a “mouse macro”. This “mouse macro” you have to fire up with a keyboard hotkey. So at last its again a keyboard emulation.
I also know that we are here at the falcon forum, but I have posted for help on other forums too, have tested the last days around the clock, contacted the author of hidmacros, which said in general it must be possible and sents me a few examples, but also his code doesn’t do the trick:
–--------------------
macroMode= 1
If macroMode = 1 Then
SendKeys (“A”)
macroMode = 2
Else
SendKeys (“B”)
macroMode = 1
End If
or other option:
If macroMode = 1 Then
SendKeys (“A”)
End If
If macroMode = 2 Then
SendKeys (“B”)
End If
If macroMode = 3 Then
SendKeys (“C”)
End If
macroMode = macroMode + 1
If macroMode = 4 Then
macroMode = 1
End IfHave tried it in any combination. Never runs further than to the first keypress.
After all, I mean it could be usefull for all cockpit builders to have a toggle function for use with hidmacros or any other vbscript based software. Make things a lot more easier and saves a lot of buttons.
-
Hi,
EDIT: sorry I did not read your intention to have one button do different things depending on the amount of presses performed - so the post below might not help you
Thanks for the nice inspiration - I might try to implement this when I have some time.check Livrot.com
download LMC (‘Livrot Mic Command’) without buying a license
enter ‘asdf’ for user and password on the license screen in LMC
check ‘get temporary license’ and click ‘connect to livrot.com’
in LMC click on the red ball icon in the toolbar with a ‘K’ in it and press the desired keyboard output that you need to generate for a button
click on the blue ‘+’ icon
open the editor window
open the generated ‘macro 1’ command
click on the hotkey button
press your USB device button and wait for the hotkey recorder to finish (a second or so)now the command generates the desired keyboard output when you press that button
keyboard generated output works for one hour with each temporary license
buy LMC if you like it - it can do much moreregards,
Torvil -
Thanks anyway Torvil!
Will take a look at the program. Its one of the few macro programs I did’nt know, perhaps it has some other features I could use.
Regards Viper
-
Now I have read through your post entirely. LMC can do this for you.
LMC low level hotkeys can:
record a sequence of key / button (any usb device) presses and releases.
the exact sequence of releases and presses must be repeated to trigger the hotkey (refinements to this are permitting modifier key order to be reversed).
the hotkey can be set to be ‘device depended’ (triggered only by the exact HID devices that recorded the hotkey (VID / PID number is used for this) ).
button combinations like ‘button 1 press + button 2 press + button 2 release + button 1 release’ are possible, too.
hotkeys containing only keyboard events can be ‘eaten’ away from the systems input stream with ‘temporary eating’ (a delay can be set for that hotkey) as another refinement.
For more information about LMC hotkeys check the LMC manual ‘Part I : Hotkey options’.To have circular toggled actions you need to program a global integer variable to have a start value in one command (call it ‘cockpit reset’ or whatever)
- just make a simple ‘integer’ ‘assign’ macro event (double click on the empty macro event in the action tab of )and assign the value ‘0’ (zero) to it.
Then in the macro that is triggered by that button,
create a macro event increase that global integer variable by one
create a macro event with a ‘integer’ conditional bracket ‘equals’ and compare it to ‘1’
record a temporary keyboard macro with your keypresses 'click the red ball with a ‘K’ in it
paste the temporary macro behind the conditional bracket event
create an ‘end conditional bracket’ event
do this again for each following press (compare to ‘2’, ‘3’, …)
in the last conditional bracket insert a 'integer assign event to reduce the integer back to ‘0’ to close the ‘button press circle’.
If you can not build this command without further help, check the ‘macro programming crash course’ (Part II) of the manual. The first pages should be sufficient to achieve your goal.
I’m sorry for not reading your post entirely in the first place.
regards,
Torvil - just make a simple ‘integer’ ‘assign’ macro event (double click on the empty macro event in the action tab of )and assign the value ‘0’ (zero) to it.
-
Hello Torvil,
many many thanks for that.
I will take a closer look at the program. It could be the solution for my project. Momentarily I couldn’t test it, cause my son had a little accident this weekend and hurt his knee. He have to use crutches now and needs my help at the moment.
Next weekend, if things go calm, I will do a bit of testing. I will report the results here. Think this could be interesting for many of us, not only for the pit itself, but for controlling anything which makes alot of different inputs necessary.
Regards Viper