02 Using Script One Liners to send keys

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 Using Script One Liners to send keys

Post by Baobob » 30 Nov 2011, 01:58

Ok,

Just like we did in "01" we are going to look at using a script to send keystrokes rather than just relying on the "predefined" section "Send Keyboard Sequence". And just like in "01" we are going to look at doing so with the simple HIDMacros "one liner" approach.

I'm going to try without the pictures this time, but if you feel you need them just send me a PM and I'll edit the post to include them if I can.

I have found however that the rules are different than in the predefined section so you may have to do some playing around to get the result you want. One example of this is that in the predefined section, just as it states in the help file, +abc only adds the shift key modifier to the "a" at the beginning of the string of letters, while +(abc) will apply the shift modifier to all three letters. In other words:

+abc = Abc and +(abc) = ABC

When using HIDMacros.SendKeys however this does not seem to be the case.

+abc = Abc and +a+b+c = ABC

It's important to remember that this is is a "modifier" key which means that the point is not to send a capitol letter so much as it is to send multiple keys at the same time. If all you want to do is send a capitol letter to notepad... just use a capitol letter in you string...

Code: Select all

HIDMacros.SendKeys "Baobob Miller"
= Baobob Miller


Another thing to be careful of is timing.

Scripts are faster at reading than typing and they try to do everything at once unless told otherwise. which is why if you don't do something to stop it... things can get messy. Take the following example:

Code: Select all

HIDMacros.SendKeys "Baobob Miller"
HIDMacros.SendKeys "Baobob Miller"
= BaoBBoabo bMObi lMLeirller

The problem is that we didn't tell the script to slow down. Who do we do that you ask? I'm glad you asked. We tell the script to slow down with another great "one liner"... sleep. As in

Code: Select all

sleep 100
which is more than enough time for most things. in fact I usually only use 10:

Code: Select all

HIDMacros.SendKeys "Baobob Miller "
sleep 10
HIDMacros.SendKeys "Baobob Miller "
sleep 10
HIDMacros.SendKeys "Baobob Miller "
= Baobob Miller Baobob Miller Baobob Miller


Just remember, since we are running simulators and application software with our macro-scripts we want to use the modifier keys not just type capitol letters. Which also means we don't usually have to worry about pauses as much as we need to worry about modifiers... multiple modifiers for a single key. The problem is, while the predefined "Send Keyboard Sequence" will do that... As far as I can tell vbscript won't at least not without invoking SendSystemKeys which I can't find a way to do from inside HID Macros. So while using the script method for sending keys when you need to combine SIMPLE keysending with other items (like FSX events etc.) works great, If you need to send more complex keys (such as shift+crtl+alt+z) it's not the best answer. If anyone has an insight to the contrary PLEASE let me know and I will re-write this tutorial.

So what are we to do...

I'll tell you the answer in the next episode...

02.5 Adding NirCmd to your Arsenal
Fly Well,
Bao

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

Post Reply