HIDmacros: One key toggle between multiple functions?

Announcements, general discussion
Post Reply
Viper1970
Posts: 6
Joined: 13 Jul 2016, 11:25

HIDmacros: One key toggle between multiple functions?

Post by Viper1970 » 14 Sep 2016, 13:42

Hello to all!

I have a question about a simple toggle function. Is it possible with hidmacros to toggle a key, for example "x", that if you press it one time it generates an "a" the next time a "b" and once again a "c" and so on. I know this must be a script, if its possible at all. If multiple functions not possible, is it possible to switch between two states ( "a" and "b" only ) at least?

With Autohotkey I've done exact this, but AHK could not seperate the devices (keyboards/numpads) connected to the computer.
I want to use this functionality with a selfmade overhead panel to operate multi position rotaries (eg. something like the mags switch in FS).
I have not so many keys available, that I can use one key for one position only.
Built a universal pit for mostly Falcon BMS, but at times I want to fly the big birds, too. So I built a very simple generic overhead panel with the
use of some numpads. Don't want to make the same complex electronics, like in the main pit, once again.

Thanks so much

Viper

P.S: I use the good old FS2004 for civil siming, so FSX variables or sim connect aren't an option in my case.

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

Re: HIDmacros: One key toggle between multiple functions?

Post by admin » 15 Sep 2016, 20:46

It is possible, introduce global variable, when macro is triggered, check its value and send appropriate key. And modify the variable to get ready for next time.
Petr Medek
LUAmacros author

Viper1970
Posts: 6
Joined: 13 Jul 2016, 11:25

Re: HIDmacros: One key toggle between multiple functions?

Post by Viper1970 » 22 Sep 2016, 20:57

Hello Petr,

many thanks for your reply. Have tried what you described, but I'm no programmer at all. Don't now exactly what you mean. The thing
I've tried looks like this:

iKeyStrokeCount = iKeyStrokeCount + 1

iKeyStrokeCount = 1

If iKeyStrokeCount = 1 Then

SendKeys ("A")

End If


If iKeyStrokeCount = 2 Then

SendKeys ("B")

End If

I think (as far as I came with my restricted knowledge) that the script ends after the first send keys, cause with this first keypress its finished. After that it starts from the beginning as a new instance. Don't now how to get the count-function from one instance to the next. Excuse my ignorance, but programming was always a mystery for me.

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

Re: HIDmacros: One key toggle between multiple functions?

Post by admin » 23 Sep 2016, 08:06

Without any testing or checking you should be able to do e.g. something like (there are more ways how to achieve this):

Into global (procedure) section

Code: Select all

macroMode= 1
Into macro definition

Code: Select all

If macroMode = 1 Then
  SendKeys ("A")
  macroMode = 2
Else
  SendKeys ("B")
  macroMode = 1
End If
Or to have more options

Code: Select all

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 If
Petr Medek
LUAmacros author

Viper1970
Posts: 6
Joined: 13 Jul 2016, 11:25

Re: HIDmacros: One key toggle between multiple functions?

Post by Viper1970 » 23 Sep 2016, 16:51

O.k. will try this. Thank's for the examples.

As I said I'm not good in programming, but if I have some code in front of me, of which I know its correct, maybe I get the big intuition :D .

Till now I had absolutely no plan how to begin, but with your code examples I could look how things are working and take my conclusions.

Post Reply