How to program keyboard combinations?

How can be this controlled in that simulator? Can HIDmacros be used with this application?
PeteDowson
Posts: 9
Joined: 07 Feb 2011, 18:18

How to program keyboard combinations?

Post by PeteDowson » 07 Feb 2011, 18:26

Hi,

I'm trying to replace two mini-PCs driving my CDU and RCDU with one more powerful PC.

Each of the devices is identical, with built-in keyboards precoded to match Project Magenta's keyboard input needs. These include A-Z, 0-9 etc, easy ones, and Ctrl+F1-F12.

Enrico, author of PM, has kindly changed the CDU and RCDU so that there is a mode where I can send all of the keypresses to the CDU and it sends specially changed combinations on to the RCDU.

Now all I need to do is connect both keyboards, and have something like HIDmacros change the second keyboard's keypresses to those combinations which the CDU will send on to the RCDU.

This works well for all keys, except the Ctrl+F1 to F12 key combinations. I just cannot find a way to program a combination as INPUT to HID macros, only as Output. I am guessing that the "sending to buffer" option might be involved, but there's no help for that..

So, please, could you tell me how I'd do such a thing, e.g take an input of Ctrl+F1 and send it on as Shift+Ctrl+F1?

Thanks,
Pete

admin
Site Admin
Posts: 530
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic
Contact:

Re: How to program keyboard combinations?

Post by admin » 08 Feb 2011, 09:25

Hi Pete

Talking about keyboard HIDmacros uses single key presses as triggers. It actually uses "key down" event to fire associated macro. So you could have macro for F1 key press or Ctrl key press, but not for combination. This comes from original idea to use additional keyboard for macros to avoid a need for using key combinations.
However I understand your point. The only idea I could get so far is to add a function available in script which would detect current key state (pressed or not). In that case you could have scripted macro on F1 key and in the script you would check whether Ctrl key is pressed or not. Do you think that would help?
Petr Medek
LUAmacros author

PeteDowson
Posts: 9
Joined: 07 Feb 2011, 18:18

Re: How to program keyboard combinations?

Post by PeteDowson » 08 Feb 2011, 11:29

admin wrote: Talking about keyboard HIDmacros uses single key presses as triggers. It actually uses "key down" event to fire associated macro. So you could have macro for F1 key press or Ctrl key press, but not for combination. This comes from original idea to use additional keyboard for macros to avoid a need for using key combinations.
Hi Petr!

Yes, it had occurred to me that this was the reason. My situation is a bit different as I'm not using keyboards as such but built-in keyboard emulators. The CDU's concerned are actually the PFC ones in the 737NG cockpit.
However I understand your point. The only idea I could get so far is to add a function available in script which would detect current key state (pressed or not). In that case you could have scripted macro on F1 key and in the script you would check whether Ctrl key is pressed or not. Do you think that would help?
Yes, it certainly sounds like it would do the job. If you could do that it would be good, thank you. I guess I'll have to read up on VBScript or JScript. I've not even mastered Lua yet, even though I've built it into FSUIPC and WideClient. ;-)

I was looking at adding RawInput facilities into WideClient to do the job for me as an integrated solution (the CDUs are on a Client PC), but whilst the RawInput facilities in Windows makes it really easy to read keypresses on different keyboards and know where they are coming from, and get them even when your program doesn't have focus, it doesn't appear to provide a way to stop another program which does have focus to receive the normal keyboard events. So it starts getting messy, either trying to move the focus or hooking into things. I see you have solved that problem, but it must be a fairly complicated solution.

Thanks for your consideration and freeware program. I will certainly be making a donation -- I started off FSUIPC3 as donation-ware but FSUIPC and WideFS have always been pretty much a full time job, and donations didn''t manage to cover living costs -- nowhere near in fact. I hope you find it worthwhile!

Regards
Pete

admin
Site Admin
Posts: 530
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic
Contact:

Re: How to program keyboard combinations?

Post by admin » 08 Feb 2011, 22:56

Pete,

You can try this experimental build: http://www.hidmacros.eu/HIDMacros.exe
I added function GetKeyState which corresponds to standard windows API routine. So you can check in macro e.g. if control is pressed by code:

Code: Select all

Dim ctrl
ctrl = HIDMacros.GetKeyState(17) and 128
if (ctrl = 0) then
  ' ctrl not pressed
  HIDMacros.SendKeys "ab"
else
  ' ctrl pressed
  HIDMacros.SendKeys "s"
end if
But you must be careful with output of your macro. If Ctrl key is pressed it is not handled by HIDmacros anyhow. If you test macro above e.g. with F1 key and Notepad, you get "ab" chars on F1, and save dialog on Ctrl+F1 :-). That's because Ctrl is down when macro is fired and HIDmacros sends "s" key. So notepad receives ctrl+s = save dialog for untitled file or it directly saves your file.
So it depends what ouput is produced by your macro and also I wonder if keyboard emulation in your devices handles ctrl and other keys in the same way as real keyboard.
Let me know it it helps and in that case I add this feature to next version - maybe with some nice wrappers around raw API call.
Petr Medek
LUAmacros author

PeteDowson
Posts: 9
Joined: 07 Feb 2011, 18:18

Re: How to program keyboard combinations?

Post by PeteDowson » 09 Feb 2011, 00:04

admin wrote: You can try this experimental build: http://www.hidmacros.eu/HIDMacros.exe
Thank you! I will try it and let you know.
But you must be careful with output of your macro. If Ctrl key is pressed it is not handled by HIDmacros anyhow.
Well, in my case that is not a problem because I need it to send Shift+Ctrl+ whatever in any case -- that's the distinction Enrico programmed for the RCDU in the case of the CTRL_F1 - F12 function keys. However, I can see this might limit the general application of the facility.
... also I wonder if keyboard emulation in your devices handles ctrl and other keys in the same way as real keyboard.
Ah, I won't know that exactly for a few days as at present I'm developing the idea separately from the cockpit. If it looks like working well I have to do some re-wiring in the cockpit to route the cables through to the replacement PC. The new PC supports OpenGL, the old two mini-PCs don't and they are becoming unreliable (over 8 years old now and I'm running low on spares! <G>).

The CDU keyboard outputs have PS/2 keyboard connectors and are no doubt not built for USB interconnection so I have purchased a pair of the more expensive PS/2 -> USB adapters which are stated to work even with ancient keyboards, so hopefully they'll be okay. I'm awaiting delivery of a couple of short USB extender cables as the PS/2 cables won't quite reach the new PC position else.
Let me know it it helps and in that case I add this feature to next version - maybe with some nice wrappers around raw API call.
I'll test here with normal keyboards now, and let you know.

Thanks!

Pete

PeteDowson
Posts: 9
Joined: 07 Feb 2011, 18:18

Re: How to program keyboard combinations?

Post by PeteDowson » 09 Feb 2011, 01:10

admin wrote: You can try this experimental build: http://www.hidmacros.eu/HIDMacros.exe
I've tried this, and I must be doing something wrong, because before all of the F1-F12 buttons on the USB keyboard (my "second", though named Keybd1) are being sent as just F1-F12 just like the main keyboard. In other words HIDmacros is doing nothing for them.

All the other keys seem to be working. Before I added the scripts the normal F1-F12 were sent correctly as Shift+F1=F12 from keybd1, so it's something in the scropts which is stopping any translation at all.

I'm just trying to achieve:

F1-F12 from Keybd1 ===> Shift + F1-F12
Ctrl+F1-F12 from Keybd1 ===> Ctrl + Shift + F1-F12

I attach the XML. The all -compiled indication is okay. I don't know what the 'Test' button does -- seems to do nothing for these.
my hidmacrosxml.zip
(1.48 KiB) Downloaded 605 times
Regards
Pete

admin
Site Admin
Posts: 530
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic
Contact:

Re: How to program keyboard combinations?

Post by admin » 10 Feb 2011, 09:09

Hmm, I don't have exactly your setup but this is what I tried:
- used GOM player for testing and configured some action for Shift+F1 and another for Ctrl+Shift+F1
- defined very simple macro for F1 and as action used keyboard sequence +{F1} (no scripting)
- now if I press F1 HIDmacros send Shift+F1 (as my macro is triggered) and action for Shift+F1 in GOM player is executed
- if I press Ctrl+F1then the same macro is triggered, but because I hold Ctrl key on my keyboard action for Ctrl+Shift+F1 in GOM player is executed (Ctrl down on keyboard and Shift+F1 came from HIDmacros)
So looks like solution for problem you have if the Ctrl key press is sent in the same way as pressed manually on real keyboard.
Petr Medek
LUAmacros author

PeteDowson
Posts: 9
Joined: 07 Feb 2011, 18:18

Re: How to program keyboard combinations?

Post by PeteDowson » 10 Feb 2011, 13:15

admin wrote: So looks like solution for problem you have if the Ctrl key press is sent in the same way as pressed manually on real keyboard.
Oh, right. I'll give that a try.

I wonder why the scripting I added, exactly as per your example, actually stopped HIDmacros doing anything for those keypresses at all, then? It didn't throw up an error in the macro or script.

[LATER]
Yes, that solves my specific problem. Thank you.

It isn't a general solution, though. It actually doesn't solve one keypress conversion I wanted, but it isn't essential (Q -> ALT Q but CtrL Q -> Shift Ctrl Q), and I think Enrico will change that for me to accept Ctrl+Alt+Q.

Thanks!

Pete

admin
Site Admin
Posts: 530
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic
Contact:

Re: How to program keyboard combinations?

Post by admin » 10 Feb 2011, 13:54

PeteDowson wrote:I wonder why the scripting I added, exactly as per your example, actually stopped HIDmacros doing anything for those keypresses at all, then? It didn't throw up an error in the macro or script.
I don't know either. But if you have some test case I could reproduce (e.g. normal keyboard and Notepad or similar simple application), I can check what goes wrong.
PeteDowson wrote:It actually doesn't solve one keypress conversion I wanted, but it isn't essential (Q -> ALT Q but CtrL Q -> Shift Ctrl Q)
Try macro on Q with script:

Code: Select all

Dim ctrl
ctrl = HIDMacros.GetKeyState(17) and 128
if (ctrl = 0) then
  ' ctrl not pressed
  HIDMacros.SendKeys "%q" 'send Alt+Q
else
  ' ctrl pressed
  HIDMacros.SendKeys "+q" 'send Ctrl+Shift+Q, Ctrl is already down
end if
I just tested with Pspad editor and seems to send what you need.
Petr Medek
LUAmacros author

PeteDowson
Posts: 9
Joined: 07 Feb 2011, 18:18

Re: How to program keyboard combinations?

Post by PeteDowson » 10 Feb 2011, 14:22

admin wrote:
PeteDowson wrote:I wonder why the scripting I added, exactly as per your example, actually stopped HIDmacros doing anything for those keypresses at all, then? It didn't throw up an error in the macro or script.
I don't know either. But if you have some test case I could reproduce (e.g. normal keyboard and Notepad or similar simple application), I can check what goes wrong.
I usually test such things here using Spyxx, with only keyboard messages logged, to see what arrives in the target focus window. It doesn't really matter what it does with them. There are also little programs around which don't process keys but merely show the keycodes.
Try macro on Q with script:

Code: Select all

Dim ctrl
ctrl = HIDMacros.GetKeyState(17) and 128
if (ctrl = 0) then
  ' ctrl not pressed
  HIDMacros.SendKeys "%q" 'send Alt+Q
else
  ' ctrl pressed
  HIDMacros.SendKeys "+q" 'send Ctrl+Shift+Q, Ctrl is already down
end if
But except for the 'q' instead of '{F1}' that's essentially the same as the scripts which I added which stopped HidMacros even doing the basic key changes for the F1-F12 keys. If those didn't work, why would these? As soon as i deleted the script, they all worked correctly as they did before (and, as you pointed out, the Ctrl key went with the output in any case).

Maybe it's the format for Function keys, like

HIDMacros.SendKeys "+{F1}"

which doesn't work? Have you tried with a function key.

Also, perhaps you could show me the XML <Macro> section for the keypress you programmed and got working using a similar script? Did you check mine? That's why I sent you the complete HidMacros.xml file, so you could see what I was doing wrong. For instance, although I set a script in the GUI I see no way of NOT selecting one of the non-script options too -- so the XML contained both the key sequence to be sent AND the script itself. Is that right? If not, what is, please? There's no radio button saying "use script", so one of the other options is always selected.

Regards
Pete

Post Reply