#3316861 - 06/12/11 04:04 AM
Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET?
|
Joined: Jan 2001
Posts: 1,124
Lancelot
Member
|
Member
Joined: Jan 2001
Posts: 1,124
Buenos Aires, Argentina
|
I tried using the same as foxy, and compiled fine, but when i run the script i get a runtime error indicating that does not recognize the symbol (H1UR, or H1DR, or H1DL or H1UL). Code example MapKeyIO(&HCougar, H1UR, View_Right_Front_Up, View_Front_Right);I searched the entire manual but could not find it. Thanks in advance.
Si hay que huir, YO PRIMERO!!!
|
|
#3317229 - 06/12/11 07:11 PM
Re: Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET?
[Re: Lancelot]
|
Joined: May 2011
Posts: 6
ivanwfr
Junior Member
|
Junior Member
Joined: May 2011
Posts: 6
|
The mistake is: H1URThis switch is not right, Throttle and Joystick switch numbers are declared in the file defines.tmh which is in the script folder near target.tmh included file.
// ------- Warthog Joystick -------------
.../...
define H1U 29
define H1R 30
define H1D 31
define H1L 32
.../...
But you can handle cornered hat:
include "target.tmh"
int main() {
if(Init(&EventHandle)) return 1;
}
int EventHandle(int type, alias o, int x)
{
if ((&o==&Joystick) & (x>=H1U) & (x<=H1L)) // H1[URDL]
handleHat(H1U);
else if((&o==&Joystick) & (x>=H2U) & (x<=H2L)) // H2[URDL]
handleHat(H2U);
else if((&o==&Joystick) & (x>=H3U) & (x<=H3L)) // H3[URDL]
handleHat(H3U);
else if((&o==&Joystick) & (x>=H4U) & (x<=H4P)) // H4[URDLP] = [14-18] -- !order=URDL -- @see defines.tmh
handleHat(H4U);
else
DefaultMapping(&o, x);
}
int ActHatKeyCalled = 0;
int handleHat(int hat)
{
if( !ActHatKeyCalled ) {
ActHatKeyCalled = 1;
DeferCall(2 * kb_delay, &ActHatKey, hat);
}
else {
// just wait for the pending one to happen
}
}
int ActHatKey(int hat) {
int u = Joystick[hat ];
int r = Joystick[hat+1];
int d = Joystick[hat+2];
int l = Joystick[hat+3];
int num = 0;
if (u & r) num = 9;
else if(u & l) num = 7;
else if(d & l) num = 1;
else if(d & r) num = 3;
else if( u ) num = 8;
else if( d ) num = 2;
else if( l ) num = 4;
else if( r ) num = 6;
if(num != 0) {
if(num == view_locked) unlock_view();
else lock_view(hat, num);
}
ActHatKeyCalled = 0;
}
int view_locked = 0;
int lock_view(int hat, int num)
{
// Enter/Keep "snap view mode"
if(view_locked==0) {
printf("[SNAP ON-%d]", hat);
ActKey(LOCK);
ActKey(KEYON+ R_CTL+ 0);
ActKey(KEYON+ KP0); Sleep( 10 );
ActKey( KP0);
ActKey( R_CTL+ 0);
}
if(num) {
ActKey(LOCK);
ActKey(KEYON+ KPENT+num); Sleep( kb_delay );
ActKey( KPENT+num);
ActKey(LOCK);
view_locked = num;
printf(" %d", view_locked);
}
}
int unlock_view()
{
// Leave "snap view mode"
printf(" OFF]\xa", view_locked);
ActKey(LOCK);
ActKey(KEYON+ KP0 ); Sleep( kb_delay );
ActKey( KP0 );
ActKey(LOCK);
view_locked = 0;
}
Last edited by ivanwfr; 06/14/11 05:45 PM. Reason: added example
|
|
#3322177 - 06/19/11 02:54 AM
Re: Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET?
[Re: Lancelot]
|
Joined: Jan 2001
Posts: 1,124
Lancelot
Member
|
Member
Joined: Jan 2001
Posts: 1,124
Buenos Aires, Argentina
|
Thanks ivanwfr, but... Do i have to use all that code to handle diagonal positions of the trim hat? (cornered hat as you put it?. Cant i just define H1UR, H1DR, H1DL and H1UL on the "defines.tmh" file and use those names on the tmc file?
Also, where are defined KP+, KP-. KP/, KP* and KP. (or KP DEL)?
Si hay que huir, YO PRIMERO!!!
|
|
#3323163 - 06/20/11 03:33 PM
Re: Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET?
[Re: Lancelot]
|
Joined: Oct 2010
Posts: 83
Nicu
Junior Member
|
Junior Member
Joined: Oct 2010
Posts: 83
|
TARGET converts HAT1 8 positions in 4 virtual buttons (H1U, H1R, H1D, H1L). You still can use corners with EXEC, like in the following example, which presses the key 'a' while H1UR is pressed: define H1URKey 'a'
...
MapKey(&Joystick, H1U, EXEC("if(Joystick[H1R]) ActKey(KEYON+H1URKey);", "if(Joystick[H1R]) ActKey(H1URKey);"));
MapKey(&Joystick, H1R, EXEC("if(Joystick[H1U]) ActKey(KEYON+H1URKey);", "if(Joystick[H1U]) ActKey(H1URKey);")); This construct can be used also for non real hat controls (which have only 4 positions, not 8 like a real HAT), like H2, H3, H4. If only pulses are required, you can write more simpler: MapKey(&Joystick, H1U, EXEC("if(Joystick[H1R]) ActKey(KEYON+PULSE+H1URKey);"));
MapKey(&Joystick, H1R, EXEC("if(Joystick[H1U]) ActKey(KEYON+PULSE+H1URKey);")); If you don't know how to produce a certain key, you can use the TARGET GUI and the virtual keyboard. Then you generate the script and view it. It is possible some keys to be accessible only with the USB code.
Last edited by Nicu; 06/20/11 03:47 PM.
|
|
#3329853 - 06/27/11 11:29 PM
Re: Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET?
[Re: Lancelot]
|
Joined: Jan 2001
Posts: 1,124
Lancelot
Member
|
Member
Joined: Jan 2001
Posts: 1,124
Buenos Aires, Argentina
|
Thanks Nicu, i will try it!
Si hay que huir, YO PRIMERO!!!
|
|
#3331343 - 06/29/11 04:38 PM
Re: Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET?
[Re: Lancelot]
|
Joined: May 2011
Posts: 6
ivanwfr
Junior Member
|
Junior Member
Joined: May 2011
Posts: 6
|
Hi Lancelot, sorry, I'm late but these SimHQ forum is so quiet compared to ED forums that I miss some new messages here. The code I mentioned above is the result of a study about what we can expect from TM hats and the way to handle the different cases. There are only 2 good reasons to use this complicated code instead of Nicu's macros. 1- Some hats can activate only one of their 4 switches a any single time and others can close 2 of them when pushed into a corner. You can monitor this with DeviceAnalyzer. It means that you will sometimes have 2 depressed switches when you push a hat into a corner. Which comes first is random... I don't like random when selecting TAD or HUD as SOI. That lead you to random MVCD display... not good! 2- ActKey() is MUCH quicker than EXEC macros... here too random missing key press drive me crazy. But I agree, this is not casual programming and if you want to understand all of it, it's another layer of hard work for this sim, again! But you don't really need to. We have 2 options here: 1. Either keep it simple enough to master it and keep it bellow the pain in the ass threshold. 2. Or just ask some geeks like me for something cool you would like to experiment. For option 2, I opened a thread in ED forum. But it happens to be scary enough to drive readers away TARGET - Advanced programming...My own code is attached at the bottom of first thread and I keep it up to date with new experimentation. Currently trying to "Export.lua" DCS parameters to TARGET and see where it can get us.
|
|
#3333125 - 07/01/11 11:46 PM
Re: Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET?
[Re: Lancelot]
|
Joined: Jan 2001
Posts: 1,124
Lancelot
Member
|
Member
Joined: Jan 2001
Posts: 1,124
Buenos Aires, Argentina
|
Thanks Ivan for all the clarifications, they are very welcome. I will start to follow your thread on ED forums, i'm very interested on learning deeply target, my biggest problem its my lack of time and the fact i'm very untalented about programming. .
Si hay que huir, YO PRIMERO!!!
|
|
#3998970 - 08/21/14 07:02 PM
Re: Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET?
[Re: Lancelot]
|
Joined: Aug 2014
Posts: 2
aw65863
Junior Member
|
Junior Member
Joined: Aug 2014
Posts: 2
New York
|
Apologies for necro, have not been able to find any other place where HAT diagonals is discussed in depth. I copied one of the suggestions above and made a test script. the weird thing is that when i map the 4 axis only 3 of the 4 actually work. whatever one I place first ion my test program always fails. i post it here to see if anyone can comment.
include "target.tmh"
alias T16001; // second T16000 handle, which will be used all mapping commands
// Define virtual diagonal HAT key and its keyboard mapping
define H1URKey 't' // upper right = cycle hostile
define H1LRKey 'g' // lower right = pin target
define H1ULKey 'r' // upper left = next target
define H1LLKey 'y' // lower left = cycle friendlies
//program startup
int main()
{
if(Init(&EventHandle)) return 1; // declare the event handler, return on error
//add initialization code here for the second T16000 I am running, you can remove
&T16001 = GetIndexJoy (SelectUsbDevice ("VID_044F&PID_B10A")); //pc expects a joystick on this adress
// mapping for diagonal HAT upper left
MapKey(&T16000, H1U, EXEC("if(T16000[H1L]) ActKey(KEYON+PULSE+H1ULKey);"));
MapKey(&T16000, H1L, EXEC("if(T16000[H1U]) ActKey(KEYON+PULSE+H1ULKey);"));
// mapping for diagonal HAT lower left
MapKey(&T16000, H1D, EXEC("if(T16000[H1L]) ActKey(KEYON+PULSE+H1LLKey);"));
MapKey(&T16000, H1L, EXEC("if(T16000[H1D]) ActKey(KEYON+PULSE+H1LLKey);"));
// mapping for diagonal HAT upper right
MapKey(&T16000, H1U, EXEC("if(T16000[H1R]) ActKey(KEYON+PULSE+H1URKey);"));
MapKey(&T16000, H1R, EXEC("if(T16000[H1U]) ActKey(KEYON+PULSE+H1URKey);"));
// mapping for diagonal HAT lower right
MapKey(&T16000, H1D, EXEC("if(T16000[H1R]) ActKey(KEYON+PULSE+H1LRKey);"));
MapKey(&T16000, H1R, EXEC("if(T16000[H1D]) ActKey(KEYON+PULSE+H1LRKey);"));
}
//event handler
int EventHandle(int type, alias o, int x)
{
DefaultMapping(&o, x);
//add event handling code here
}
|
|
#4014910 - 09/26/14 11:04 PM
Re: Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET?
[Re: Lancelot]
|
Joined: Dec 2000
Posts: 529
RogueSqdn
USAF Veteran
|
USAF Veteran
Member
Joined: Dec 2000
Posts: 529
Advance, NC
|
That's failing because you have buttons programmed twice. It's only recognizing the last one in the file.
Last edited by RogueSqdn; 09/26/14 11:05 PM.
Jared ----- FalconNW MachV, Obutto R3volution
DEFENSOR FORTIS
|
|
#4017626 - 10/03/14 04:18 PM
Re: Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET?
[Re: RogueSqdn]
|
Joined: Aug 2014
Posts: 2
aw65863
Junior Member
|
Junior Member
Joined: Aug 2014
Posts: 2
New York
|
That's failing because you have buttons programmed twice. It's only recognizing the last one in the file. I do not understand your feedback. Can you be more specific?
|
|
#4029671 - 10/31/14 12:51 AM
Re: Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET?
[Re: Lancelot]
|
Joined: Dec 2000
Posts: 529
RogueSqdn
USAF Veteran
|
USAF Veteran
Member
Joined: Dec 2000
Posts: 529
Advance, NC
|
I mean that you have multiple MapKey statements for each button. You have MapKey(&T16000, H1D....) and the others listed multiple times. It's only going to read the last one.
Jared ----- FalconNW MachV, Obutto R3volution
DEFENSOR FORTIS
|
|
|
|