programming in T.A.R.G.E.T (which uses C)

This is a discussion on programming in T.A.R.G.E.T (which uses C) within the Game Programming forums, part of the General Programming Boards category; Hello, I have got programmable joysticks. T.16000M - Ambidextrous Joystick - PC USB | Thrustmaster Don't ask me why, but ...

  1. #1
    Registered User
    Join Date
    Mar 2014
    Posts
    5

    programming in T.A.R.G.E.T (which uses C)

    Hello,

    I have got programmable joysticks.
    T.16000M - Ambidextrous Joystick - PC USB | Thrustmaster

    Don't ask me why, but I have two of these to use as dual sticks in games. It seems to have it's advantages. For one, I can program multiple things to happen on one axis. This give me a huge advantage in dogfights. Also I can program the entire keybord letters to my base buttons. No need for keybord...

    But I lack the logic thinking to get my code completed.
    I have multiple issues, and will adress them one at a time.

    My first problem is my POV. That's the little mini thumbjoystick on top of a joystick for your Point of View camera ingame. The thing usually used for switching camera positions.

    The trouble is this: In UPRIGHT position it executes both my UP and my RIGHT programmed stuff. Instead of a different third thing. My Conclusion is that UPRIGHT doens't exist as such, and Software just see that both UP and RIGHT are true, and execute code that says: When both are true, it's an in-between.
    Works ingame, but I need a code that does something else.
    'Cause Up might be 'missiles' , Right might be 'Start Chat', and I don't need missiles fired and chatting while doing UPRIGHT 'Dock to friendly Ship'

    for short: I need a working code that says: When Up=True, and Right =True, both are not executed, and execute ActKey '2' (for example)

    in my main file I got
    Code:
    MapKey(&T16001, H1U, Center_View);
    MapKey(&T16001, H1R, View_Right);
    In my ttm file (where my definitions are grabbed from) I came up with:
    Code:
    define Center_View '1'
    define View_Up '2'
    define View_Right '3'
    In my main file I first had:
    Code:
    MapKey(&T16001, H1UR, View_Up);
    There was no H1UR, so nothing happened.

    Then I tried
    Code:
    MapKey(&T16001, H1U+H1R, View_Up);
    Then I tried
    Code:
    if
    {Center_View=1
    &
    View_Right=1;
    }
    {Center_View=0
    View_Right=0
    ActKey ('2');
    }
    now I tried:
    Code:
    while (MapKey(&T16001, H1U, Center_View) MapKey(&T16001, H1R, View_Right));
    do
    {Center_View=0
    View_Right=0
    Actkey('2')
    };
    and I get '(' and ')' errors all the time about the first line. I tried adding and deleting '(' 's and ')' 's the whole time, and keep getting errors about them
    Not sure when to use too, I tried these too.

    I also have no idea if this is the code I am looking for to do what I need it to do. My study in C and TARGET doesn't give me enough clues about the correct syntaxis.

    Do I need flagging stuff?

    http://ts.thrustmaster.com/eng/index...&pid=285&cid=5
    here is the program and the manual of TARGET (down below at the download stuff)

    and some more ps: The [code/code stuff isn't working in preview]

  2. #2
    Registered User
    Join Date
    Mar 2014
    Posts
    5
    I tried these too.=
    Code:
    {}
    Been tinkering with learning T.A.R.G.E.T. and C code since november. And glad to say I got a lot of stuff already working .
    It feels nice to have some skills you never thought you would ever aquire....

    This part I came up with which seem to work ok..
    Code:
    include "target.tmh"
    include "Macros_kaal_test1.ttm"
    alias T16001; // second T16000 handle, which will be used all mapping commands
     
    //program startup
    int main()
    {
        if(Init(&EventHandle)) return 1; // declare the event handler, return on error
    &T16001 = GetIndexJoy (SelectUsbDevice ("VID_044F&PID_B10A"));  
    
    //right one
    MapAxis(&T16000, JOYX, DX_X_AXIS, AXIS_NORMAL, MAP_ABSOLUTE); 
    MapAxis(&T16000, JOYY, DX_Y_AXIS, AXIS_NORMAL, MAP_ABSOLUTE); 
    SetCustomCurve(&T16000, JOYY, LIST (0,100, 25,75, 50,50, 75,75, 100,100)); 
    KeyAxis(&T16000, JOYY, 0, AXMAP2 (3, USB[0x4B], 0, USB[0x4E])); //PGUP & PGDN 
    MapAxis(&T16000, RUDDER, DX_Z_AXIS, AXIS_NORMAL, MAP_ABSOLUTE); 
    KeyAxis(&T16000, RUDDER, 0, AXMAP2 (3, USB[0x52], 0, USB[0x51])); //'UARROW',0 , 'DARROW'
    
    //left one
    MapAxis(&T16001, JOYX, DX_XROT_AXIS, AXIS_NORMAL, MAP_ABSOLUTE); 
    KeyAxis(&T16001, JOYX, 0, AXMAP2 (3, USB[0x50], 0, USB[0x4F])); //'LARROW', 'RARROW'
    MapAxis(&T16001, JOYY, DX_YROT_AXIS, AXIS_NORMAL, MAP_ABSOLUTE); 
    MapAxis(&T16001, RUDDER, DX_ZROT_AXIS, AXIS_NORMAL, MAP_ABSOLUTE); 
     
    // everything behind two of these is ignored by the program T.A.R.G.E.T.
    //this second (right) POV is not seen at all, need to ask about it to smart people...
    //MapKey(&T16000, H1U, Match_Target_Speed); 
    
    //MapKey(&T16000, H1R, Toggle_Gliding); 
    
    //MapKey(&T16000, H1D, Launch_Countermeasures); 
    
    //MapKey(&T16000, H1L, Afterburners);
    
    
    
    MapKey(&T16000, TS1, Fire_Primary_Weapon);
    MapKey(&T16000, TS2, L_SHIFT); 
    MapKey(&T16000, TS3, L_ALT); 
    MapKey(&T16000, TS4, Cycle_Forward_Primary_Weapon);
    
    
    MapKey(&T16000, B5, Rearm_Me);
    MapKey(&T16000, B6, Augment_Forward_Shield);
    MapKey(&T16000, B7, Equalize_Energy);
    
    MapKey(&T16000, B10, Disarm_My_Target);
    MapKey(&T16000, B9, Attack_My_Target);
    MapKey(&T16000, B8, Capture_My_Target);
     
    MapKey(&T16000, B13, Ignore_My_Target);
    MapKey(&T16000, B12, Communication_Menu);
    MapKey(&T16000, B11, Toggle_Auto_Speed_Matching);
    
    MapKey(&T16000, B14, Engage_the_Enemy);
    MapKey(&T16000, B15, Cover_Me);
    MapKey(&T16000, B16, Return_To_Base);
    
     
    MapKey(&T16001, H1U, Center_View);
    
    MapKey(&T16001, H1R, View_Right);
    
    MapKey(&T16001, H1D, View_Rear);
    
    MapKey(&T16001, H1L, View_Left);
    
    
    
    MapKey(&T16001, TS1, Fire_Secondary_Weapon);
    MapKey(&T16001, TS2, L_SHIFT); 
    MapKey(&T16001, TS3, Cycle_Secundary_Weapon_Bank);
    MapKey(&T16001, TS4, Target_Next_Closest_Hostile_Ship);
    
    
    MapKey(&T16001, B11, Target_Ship_In_Reticle);
    MapKey(&T16001, B12, Target_subsystem_In_Reticle);
    MapKey(&T16001, B13, Target_Targets_Nearest_Attacker);
    
    MapKey(&T16001, B16, Toggle_Auto_Targeting);
    MapKey(&T16001, B15, Target_Last_Ship_That_Transmitted);
    MapKey(&T16001, B14, Target_Next_Live_Turret);
    
    MapKey(&T16001, B7, Target_Next_Ship);
    MapKey(&T16001, B6, Decreaee_View_Distance);
    MapKey(&T16001, B5, Increase_View_Distance);
    
    MapKey(&T16001, B8, Target_Closest_Friendly_Ship);
    MapKey(&T16001, B9, Cycle_Radar_Range);
    MapKey(&T16001, B10, Target_Newest_ship_In_Area);
    
    
    
    }
    
    //event handler
    int EventHandle(int type, alias o, int x)
    {
        DefaultMapping(&o, x);
        
        //add event handling code here
    }
    and my Define file 'Macros_kaal_test1.ttm'

    Code:
    define Center_View '1' 
    define View_Up '2'   
    define View_Right '3' 
    define Free_Look '4' 
    define View_Rear '5' 
    define External_View '6' 
    define View_Left '7' 
    define Current_Target_View '8' 
    
    
    define Fire_Secondary_Weapon '9' 
    define Cycle_Secundary_Weapon_Bank 'm' 
    define Target_Next_Closest_Hostile_Ship 'r' 
    define Target_Ship_In_Reticle 'q'  
    define Target_subsystem_In_Reticle 'w' 
    define Target_Targets_Nearest_Attacker 'e'  
    define Toggle_Auto_Targeting 'a' 
    define Target_Last_Ship_That_Transmitted 's' 
    define Target_Next_Live_Turret 'd' 
    define Target_Next_Ship  't' 
    define Decreaee_View_Distance 'y' 
    define Increase_View_Distance 'u' 
    define Target_Closest_Friendly_Ship 'f' 
    define Cycle_Radar_Range 'g' 
    define Target_Newest_ship_In_Area  'h' 
    
    
    
    define Match_Target_Speed KP1
    define Toggle_Gliding KP3
    define Launch_Countermeasures KP5
    define Afterburners KP7
    
    define Fire_Primary_Weapon KP9
    define Cycle_Forward_Primary_Weapon '0'
    
    define Rearm_Me 'i'
    define Augment_Forward_Shield 'o'
    define Equalize_Energy 'p'
    define Disarm_My_Target 'z' 
    define Attack_My_Target 'x' 
    define Capture_My_Target 'c'
    define Ignore_My_Target 'j' 
    define Communication_Menu 'k' 
    define Toggle_Auto_Speed_Matching 'l' 
    define Engage_the_Enemy 'v' 
    define Cover_Me 'b' 
    define Return_To_Base 'n'
    Last edited by SeaBreak; 03-27-2014 at 06:34 PM. Reason: miswording

  3. #3
    Registered User
    Join Date
    Mar 2014
    Posts
    5
    T.A.R.G.E.T. is software made by the Thrustmaster Joysticks. (the ones I use in the above)
    I asked their helpdesk about helping me with code, but it seems they are non-existant. I get no replies on my emails, and other suffer the same faith... I got a mail last year that what I want can be done, but it was for advanced programing. And a 'good luck' to top it off... (is that a way to say: If you can do it...good for you?)

    The program TARGET makes these additional files when compiling the lot for my joysticks to work.
    (it makes one virtual joystick out of my two physical ones. A 'must' in some games, since they only want to see one joystick)
    But alas... it only let's me use one of my two POV's, and I cannot seem to figure out why.
    If anybody has got a clue how I can get my second POV active in the virtual joystick?

    defines.tmh
    Code:
    // TARGET definitions
    
    // ------------------------------- Virtual keyboard interface ---------------------------------
    define ESC             1041
    define F1             1058
    define F2             1059
    define F3             1060
    define F4             1061
    define F5             1062
    define F6             1063
    define F7             1064
    define F8             1065
    define F9             1066
    define F10             1067
    define F11             1068
    define F12             1069
    define F13             1104
    define F14             1105
    define F15             1106
    define F16             1107
    define F17             1108
    define F18             1109
    define F19             1110
    define F20             1111
    define F21             1112
    define F22             1113
    define F23             1114
    define F24             1115
    define PRNTSCRN     1070
    define SCRLCK         1071
    define BRK             1072
    define BSP             1042
    define TAB             1043
    define CAPS         1057
    define ENT             1040
    define LSHF         1225
    define RSHF         1229
    define LCTL         1224
    define LWIN            1227
    define LALT         1226
    define SHF             1225
    define ALT             1226
    define CTL             1224
    define SPC             1044
    define RALT         1230
    define RWIN            1231
    define RCTL         1228
    define INS             1073
    define HOME         1074
    define PGUP         1075
    define DEL             1076
    define END             1077
    define PGDN         1078
    define UARROW         1082
    define DARROW         1081
    define LARROW         1080
    define RARROW         1079
    define NUML         1083
    define KP0             1098
    define KP1             1089
    define KP2             1090
    define KP3             1091
    define KP4             1092
    define KP5             1093
    define KP6             1094
    define KP7             1095
    define KP8             1096
    define KP9             1097
    define KPENT         1088
    define APPS            1101
    
    // ASCII keycodes, based on USB codes, for different keyboard layouts
    define ASC_SHF            1000
    define ASC_AGR            1500
    
    short USB[256];
    short ASCE[256]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                        1044,                //0x20    <space>
                        1030 + ASC_SHF,        //0x21    ! Exclamation mark
                        1052 + ASC_SHF,        //0x22    " &quot; Double quotes (or speech marks)
                        1032 + ASC_SHF,        //0x23    # Number
                        1033 + ASC_SHF,        //0x24    $ Dollar
                        1034 + ASC_SHF,        //0x25    % Procenttecken
                        1036 + ASC_SHF,        //0x21    & &amp; Ampersand
                        1052,                //0x27    ' Single quote
                        1038 + ASC_SHF,         //0x28    ( Open parenthesis (or open bracket)
                        1039 + ASC_SHF,        //0x29    ) Close parenthesis (or close bracket)
                        1037 + ASC_SHF,        //0x2a    * Asterisk
                        1046 + ASC_SHF,        //0x2b    + Plus
                        1054,                //0x2c    , Comma
                        1045,                //0x2d    - Hyphen
                        1055,                //0x2e    . Period, dot or full stop
                        1056,                //0x2f    / Slash or divide
                        1039,                //0x30    0 Zero
                        1030,                //0x31    1 One
                        1031,                //0x32    2 Two
                        1032,                //0x33    3 Three
                        1033,                //0x34    4 Four
                        1034,                //0x35    5 Five
                        1035,                //0x36    6 Six
                        1036,                //0x37    7 Seven
                        1037,                //0x38    8 Eight
                        1038,                //0x39    9 Nine
                        1051 + ASC_SHF,        //0x3a    : Colon
                        1051,                //0x3b    ; Semicolon
                        1054 + ASC_SHF,        //0x3c    < &lt; Less than (or open angled bracket)
                        1046,                //0x3d    = Equals
                        1055 + ASC_SHF,        //0x3e    > &gt; Greater than (or close angled bracket)
                        1056 + ASC_SHF,        //0x3f    ? Question mark
                        1031 + ASC_SHF,        //0x40    @ At symbol
                        1004 + ASC_SHF,        //0x41    A Uppercase A
                        1005 + ASC_SHF,        //0x42    B Uppercase B
                        1006 + ASC_SHF,        //0x43    C Uppercase C
                        1007 + ASC_SHF,        //0x44    D Uppercase D
                        1008 + ASC_SHF,        //0x45    E Uppercase E
                        1009 + ASC_SHF,        //0x46    F Uppercase F
                        1010 + ASC_SHF,        //0x47    G Uppercase G
                        1011 + ASC_SHF,        //0x48    H Uppercase H
                        1012 + ASC_SHF,        //0x49    I Uppercase I
                        1013 + ASC_SHF,        //0x4a    J Uppercase J
                        1014 + ASC_SHF,        //0x4b    K Uppercase K
                        1015 + ASC_SHF,        //0x4c    L Uppercase L
                        1016 + ASC_SHF,        //0x4d    M Uppercase M
                        1017 + ASC_SHF,        //0x4e    N Uppercase N
                        1018 + ASC_SHF,        //0x4f    O Uppercase O
                        1019 + ASC_SHF,        //0x50    P Uppercase P
                        1020 + ASC_SHF,        //0x51    Q Uppercase Q
                        1021 + ASC_SHF,        //0x52    R Uppercase R
                        1022 + ASC_SHF,        //0x53    S Uppercase S
                        1023 + ASC_SHF,        //0x54    T Uppercase T
                        1024 + ASC_SHF,        //0x55    U Uppercase U
                        1025 + ASC_SHF,        //0x56    V Uppercase V
                        1026 + ASC_SHF,        //0x57    W Uppercase W
                        1027 + ASC_SHF,        //0x58    X Uppercase X
                        1028 + ASC_SHF,        //0x59    Y Uppercase Y
                        1029 + ASC_SHF,        //0x5a    Z Uppercase Z
                        1047,                //0x5b    [ Opening bracket
                        1049,                //0x5c    \ Backslash
                        1048,                //0x5d    ] Closing bracket
                        1035 + ASC_SHF,        //0x5e    ^ Caret - circumflex
                        1045 + ASC_SHF,        //0x5f    _ Underscore
                        1053,                 //0x60    ` Grave accent
                        1004,                //0x61    a Lowercase a
                        1005,                //0x62    b Lowercase b
                        1006,                //0x63    c Lowercase c
                        1007,                //0x64    d Lowercase d
                        1008,                //0x65    e Lowercase e
                        1009,                //0x66    f Lowercase f
                        1010,                //0x67    g Lowercase g
                        1011,                //0x68    h Lowercase h
                        1012,                //0x69    i Lowercase i
                        1013,                //0x6a    j Lowercase j
                        1014,                //0x6b    k Lowercase k
                        1015,                //0x6c    l Lowercase l
                        1016,                //0x6d    m Lowercase m
                        1017,                //0x6e    n Lowercase n
                        1018,                //0x6f    o Lowercase o
                        1019,                //0x70    p Lowercase p
                        1020,                //0x71    q Lowercase q
                        1021,                //0x72    r Lowercase r
                        1022,                //0x73    s Lowercase s
                        1023,                //0x74    t Lowercase t
                        1024,                //0x75    u Lowercase u
                        1025,                //0x76    v Lowercase v
                        1026,                //0x77    w Lowercase w
                        1027,                //0x78    x Lowercase x
                        1028,                //0x79    y Lowercase y
                        1029,                //0x7a    z Lowercase z
                        1047 + ASC_SHF,        //0x7b    { Opening brace
                        1049 + ASC_SHF,        //0x7c    | Vertical bar
                        1048 + ASC_SHF,        //0x7d    } Closing brace
                        1053 + ASC_SHF,        //0x7e    ~ Equivalency sign - tilde
                        1076,                //0x7F    delete
                        0,                    //0x80     &euro; Euro sign
                        0,                    //0x81    
                        0,                    //0x82     &sbquo; Single low-9 quotation mark
                        0,                    //0x83     &fnof; Latin small letter f with hook
                        0,                    //0x84     &bdquo; Double low-9 quotation mark
                        0,                    //0x85     &hellip; Horizontal ellipsis
                        0,                    //0x86     &dagger; Dagger
                        0,                    //0x87     &Dagger; Double dagger
                        0,                    //0x88     &circ; Modifier letter circumflex accent
                        0,                    //0x89     &permil; Per mille sign
                        0,                    //0x8A     &Scaron; Latin capital letter S with caron
                        0,                    //0x8B     &lsaquo; Single left-pointing angle quotation
                        0,                    //0x8C     &OElig; Latin capital ligature OE
                        0,                    //0x8D    
                        0,                    //0x8E     Latin captial letter Z with caron
                        0,                    //0x8F    
                        0,                    //0x90    
                        0,                    //0x91     &lsquo; Left single quotation mark
                        0,                    //0x92     &rsquo; Right single quotation mark
                        0,                    //0x93     &ldquo; Left double quotation mark
                        0,                    //0x94     &rdquo; Right double quotation mark
                        0,                    //0x95     &bull; Bullet
                        0,                    //0x96     &ndash; En dash
                        0,                    //0x97     &mdash; Em dash
                        0,                    //0x98     &tilde; Small tilde
                        0,                    //0x99     &trade; Trade mark sign
                        0,                    //0x9A     &scaron; Latin small letter S with caron
                        0,                    //0x9B     &rsaquo; Single right-pointing angle quotation mark
                        0,                    //0x9C     &oelig; Latin small ligature oe
                        0,                    //0x9D
                        0,                    //0x9E     Latin small letter z with caron
                        0,                    //0x9F     &yuml; Latin capital letter Y with diaeresis
                        0,                    //0xA0      &nbsp; Non-breaking space
                        0,                    //0xA1     &iexcl; Inverted exclamation mark
                        0,                    //0xA2     &cent; Cent sign
                        0,                    //0xA3     &pound; Pound sign
                        0,                    //0xA4     &curren; Currency sign
                        0,                    //0xA5     &yen; Yen sign
                        0,                    //0xA6     &brvbar; Pipe, Broken vertical bar
                        0,                    //0xA7     &sect; Section sign
                        0,                    //0xA8     &uml; Spacing diaeresis - umlaut
                        0,                    //0xA9     &copy; Copyright sign
                        0,                    //0xAA     &ordf; Feminine ordinal indicator
                        0,                    //0xAB     &laquo; Left double angle quotes
                        0,                    //0xAC     &not; Not sign
                        0,                    //0xAD      .. Soft hyphen
                        0,                    //0xAE     &reg; Registered trade mark sign
                        0,                    //0xAF     &macr; Spacing macron - overline
                        0,                    //0xB0     &deg; Degree sign
                        0,                    //0xB1     &plusmn; Plus-or-minus sign
                        0,                    //0xB2      Superscript two - squared
                        0,                    //0xB3      Superscript three - cubed
                        0,                    //0xB4     &acute; Acute accent - spacing acute
                        0,                    //0xB5     &micro; Micro sign
                        0,                    //0xB6     &para; Pilcrow sign - paragraph sign
                        0,                    //0xB7     &middot; Middle dot - Georgian comma
                        0,                    //0xB8     &cedil; Spacing cedilla
                        0,                    //0xB9      Superscript one
                        0,                    //0xBA     &ordm; Masculine ordinal indicator
                        0,                    //0xBB     &raquo; Right double angle quotes
                        0,                    //0xBC      Fraction one quarter
                        0,                    //0xBD      Fraction one half
                        0,                    //0xBE      Fraction three quarters
                        0,                    //0xBF     &iquest; Inverted question mark
                        0,                    //0xC0     &Agrave; Latin capital letter A with grave
                        0,                    //0xC1     &Aacute; Latin capital letter A with acute
                        0,                    //0xC2     &Acirc; Latin capital letter A with circumflex
                        0,                    //0xC3     &Atilde; Latin capital letter A with tilde
                        0,                    //0xC4     &Auml; Latin capital letter A with diaeresis
                        0,                    //0xC5     &Aring; Latin capital letter A with ring above
                        0,                    //0xC6     &AElig; Latin capital letter AE
                        0,                    //0xC7     &Ccedil; Latin capital letter C with cedilla
                        0,                    //0xC8     &Egrave; Latin capital letter E with grave
                        0,                    //0xC9     &Eacute; Latin capital letter E with acute
                        0,                    //0xCA     &Ecirc; Latin capital letter E with circumflex
                        0,                    //0xCB     &Euml; Latin capital letter E with diaeresis
                        0,                    //0xCC     &Igrave; Latin capital letter I with grave
                        0,                    //0xCD     &Iacute; Latin capital letter I with acute
                        0,                    //0xCE     &Icirc; Latin capital letter I with circumflex
                        0,                    //0xCF     &Iuml; Latin capital letter I with diaeresis
                        0,                    //0xD0     &ETH; Latin capital letter ETH
                        0,                    //0xD1     &Ntilde; Latin capital letter N with tilde
                        0,                    //0xD2     &Ograve; Latin capital letter O with grave
                        0,                    //0xD3     &Oacute; Latin capital letter O with acute
                        0,                    //0xD4     &Ocirc; Latin capital letter O with circumflex
                        0,                    //0xD5     &Otilde; Latin capital letter O with tilde
                        0,                    //0xD6     &Ouml; Latin capital letter O with diaeresis
                        0,                    //0xD7     &times; Multiplication sign
                        0,                    //0xD8     &Oslash; Latin capital letter O with slash
                        0,                    //0xD9     &Ugrave; Latin capital letter U with grave
                        0,                    //0xDA     &Uacute; Latin capital letter U with acute
                        0,                    //0xDB     &Ucirc; Latin capital letter U with circumflex
                        0,                    //0xDC     &Uuml; Latin capital letter U with diaeresis
                        0,                    //0xDD     &Yacute; Latin capital letter Y with acute
                        0,                    //0xDE     &THORN; Latin capital letter THORN
                        0,                    //0xDF     &szlig; Latin small letter sharp s - ess-zed
                        0,                    //0xE0     &agrave; Latin small letter a with grave
                        0,                    //0xE1     &aacute; Latin small letter a with acute
                        0,                    //0xE2     &acirc; Latin small letter a with circumflex
                        0,                    //0xE3     &atilde; Latin small letter a with tilde
                        0,                    //0xE4     &auml; Latin small letter a with diaeresis
                        0,                    //0xE5     &aring; Latin small letter a with ring above
                        0,                    //0xE6     &aelig; Latin small letter ae
                        0,                    //0xE7     &ccedil; Latin small letter c with cedilla
                        0,                    //0xE8     &egrave; Latin small letter e with grave
                        0,                    //0xE9     &eacute; Latin small letter e with acute
                        0,                    //0xEA     &ecirc; Latin small letter e with circumflex
                        0,                    //0xEB     &euml; Latin small letter e with diaeresis
                        0,                    //0xEC     &igrave; Latin small letter i with grave
                        0,                    //0xED     &iacute; Latin small letter i with acute
                        0,                    //0xEE     &icirc; Latin small letter i with circumflex
                        0,                    //0xEF     &iuml; Latin small letter i with diaeresis
                        0,                    //0xF0     &eth; Latin small letter eth
                        0,                    //0xF1     &ntilde; Latin small letter n with tilde
                        0,                    //0xF2     &ograve; Latin small letter o with grave
                        0,                    //0xF3     &oacute; Latin small letter o with acute
                        0,                    //0xF4     &ocirc; Latin small letter o with circumflex
                        0,                    //0xF5     &otilde; Latin small letter o with tilde
                        0,                    //0xF6     &ouml; Latin small letter o with diaeresis
                        0,                    //0xF7     &divide; Division sign
                        0,                    //0xF8     &oslash; Latin small letter o with slash
                        0,                    //0xF9     &ugrave; Latin small letter u with grave
                        0,                    //0xFA     &uacute; Latin small letter u with acute
                        0,                    //0xFB     &ucirc; Latin small letter u with circumflex
                        0,                    //0xFC     &uuml; Latin small letter u with diaeresis
                        0,                    //0xFD     &yacute; Latin small letter y with acute
                        0,                    //0xFE     &thorn; Latin small letter thorn
                        0                    //0xFF     &yuml; Latin small letter y with diaeresis
                        };
    
    short ASCF[256]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                        1044,                //0x20    <space>
                        1056,                //0x21    ! Exclamation mark
                        1032,                //0x22    " &quot; Double quotes (or speech marks)
                        1032 + ASC_AGR,        //0x23    # Number
                        1048,                //0x24    $ Dollar
                        1052 + ASC_SHF,        //0x25    % Procenttecken
                        1030,                //0x21    & &amp; Ampersand
                        1033,                //0x27    ' Single quote
                        1034,                 //0x28    ( Open parenthesis (or open bracket)
                        1045,                //0x29    ) Close parenthesis (or close bracket)
                        1049,                //0x2a    * Asterisk
                        1046 + ASC_SHF,        //0x2b    + Plus
                        1016,                //0x2c    , Comma
                        1035,                //0x2d    - Hyphen
                        1054 + ASC_SHF,        //0x2e    . Period, dot or full stop
                        1055 + ASC_SHF,        //0x2f    / Slash or divide
                        1039 + ASC_SHF,        //0x30    0 Zero
                        1030 + ASC_SHF,        //0x31    1 One
                        1031 + ASC_SHF,        //0x32    2 Two
                        1032 + ASC_SHF,        //0x33    3 Three
                        1033 + ASC_SHF,        //0x34    4 Four
                        1034 + ASC_SHF,        //0x35    5 Five
                        1035 + ASC_SHF,        //0x36    6 Six
                        1036 + ASC_SHF,        //0x37    7 Seven
                        1037 + ASC_SHF,        //0x38    8 Eight
                        1038 + ASC_SHF,        //0x39    9 Nine
                        1055,                //0x3a    : Colon
                        1054,                //0x3b    ; Semicolon
                        1100,                //0x3c    < &lt; Less than (or open angled bracket)
                        1046,                //0x3d    = Equals
                        1100 + ASC_SHF,        //0x3e    > &gt; Greater than (or close angled bracket)
                        1016 + ASC_SHF,        //0x3f    ? Question mark
                        1038 + ASC_AGR,        //0x40    @ At symbol
                        1020 + ASC_SHF,        //0x41    A Uppercase A
                        1005 + ASC_SHF,        //0x42    B Uppercase B
                        1006 + ASC_SHF,        //0x43    C Uppercase C
                        1007 + ASC_SHF,        //0x44    D Uppercase D
                        1008 + ASC_SHF,        //0x45    E Uppercase E
                        1009 + ASC_SHF,        //0x46    F Uppercase F
                        1010 + ASC_SHF,        //0x47    G Uppercase G
                        1011 + ASC_SHF,        //0x48    H Uppercase H
                        1012 + ASC_SHF,        //0x49    I Uppercase I
                        1013 + ASC_SHF,        //0x4a    J Uppercase J
                        1014 + ASC_SHF,        //0x4b    K Uppercase K
                        1015 + ASC_SHF,        //0x4c    L Uppercase L
                        1051 + ASC_SHF,        //0x4d    M Uppercase M
                        1017 + ASC_SHF,        //0x4e    N Uppercase N
                        1018 + ASC_SHF,        //0x4f    O Uppercase O
                        1019 + ASC_SHF,        //0x50    P Uppercase P
                        1004 + ASC_SHF,        //0x51    Q Uppercase Q
                        1021 + ASC_SHF,        //0x52    R Uppercase R
                        1022 + ASC_SHF,        //0x53    S Uppercase S
                        1023 + ASC_SHF,        //0x54    T Uppercase T
                        1024 + ASC_SHF,        //0x55    U Uppercase U
                        1025 + ASC_SHF,        //0x56    V Uppercase V
                        1029 + ASC_SHF,        //0x57    W Uppercase W
                        1027 + ASC_SHF,        //0x58    X Uppercase X
                        1028 + ASC_SHF,        //0x59    Y Uppercase Y
                        1026 + ASC_SHF,        //0x5a    Z Uppercase Z
                        1034 + ASC_AGR,        //0x5b    [ Opening bracket
                        1037 + ASC_AGR,        //0x5c    \ Backslash
                        1045 + ASC_AGR,        //0x5d    ] Closing bracket
                        1038 + ASC_AGR,        //0x5e    ^ Caret - circumflex
                        1037,                //0x5f    _ Underscore
                        1036 + ASC_AGR,        //0x60    ` Grave accent
                        1020,                //0x61    a Lowercase a
                        1005,                //0x62    b Lowercase b
                        1006,                //0x63    c Lowercase c
                        1007,                //0x64    d Lowercase d
                        1008,                //0x65    e Lowercase e
                        1009,                //0x66    f Lowercase f
                        1010,                //0x67    g Lowercase g
                        1011,                //0x68    h Lowercase h
                        1012,                //0x69    i Lowercase i
                        1013,                //0x6a    j Lowercase j
                        1014,                //0x6b    k Lowercase k
                        1015,                //0x6c    l Lowercase l
                        1051,                //0x6d    m Lowercase m
                        1017,                //0x6e    n Lowercase n
                        1018,                //0x6f    o Lowercase o
                        1019,                //0x70    p Lowercase p
                        1004,                //0x71    q Lowercase q
                        1021,                //0x72    r Lowercase r
                        1022,                //0x73    s Lowercase s
                        1023,                //0x74    t Lowercase t
                        1024,                //0x75    u Lowercase u
                        1025,                //0x76    v Lowercase v
                        1029,                //0x77    w Lowercase w
                        1027,                //0x78    x Lowercase x
                        1028,                //0x79    y Lowercase y
                        1026,                //0x7a    z Lowercase z
                        1033 + ASC_AGR,        //0x7b    { Opening brace
                        1035 + ASC_AGR,        //0x7c    | Vertical bar
                        1046 + ASC_AGR,        //0x7d    } Closing brace
                        1053 + ASC_SHF,        //0x7e    ~ Equivalency sign - tilde
                        1076,                //0x7F    delete
                        1008 + ASC_AGR,        //0x80     &euro; Euro sign
                        0,                    //0x81    
                        0,                    //0x82     &sbquo; Single low-9 quotation mark
                        0,                    //0x83     &fnof; Latin small letter f with hook
                        0,                    //0x84     &bdquo; Double low-9 quotation mark
                        0,                    //0x85     &hellip; Horizontal ellipsis
                        0,                    //0x86     &dagger; Dagger
                        0,                    //0x87     &Dagger; Double dagger
                        0,                    //0x88     &circ; Modifier letter circumflex accent
                        0,                    //0x89     &permil; Per mille sign
                        0,                    //0x8A     &Scaron; Latin capital letter S with caron
                        0,                    //0x8B     &lsaquo; Single left-pointing angle quotation
                        0,                    //0x8C     &OElig; Latin capital ligature OE
                        0,                    //0x8D    
                        0,                    //0x8E     Latin captial letter Z with caron
                        0,                    //0x8F    
                        0,                    //0x90    
                        0,                    //0x91     &lsquo; Left single quotation mark
                        0,                    //0x92     &rsquo; Right single quotation mark
                        0,                    //0x93     &ldquo; Left double quotation mark
                        0,                    //0x94     &rdquo; Right double quotation mark
                        0,                    //0x95     &bull; Bullet
                        0,                    //0x96     &ndash; En dash
                        0,                    //0x97     &mdash; Em dash
                        0,                    //0x98     &tilde; Small tilde
                        0,                    //0x99     &trade; Trade mark sign
                        0,                    //0x9A     &scaron; Latin small letter S with caron
                        0,                    //0x9B     &rsaquo; Single right-pointing angle quotation mark
                        0,                    //0x9C     &oelig; Latin small ligature oe
                        0,                    //0x9D
                        0,                    //0x9E     Latin small letter z with caron
                        0,                    //0x9F     &yuml; Latin capital letter Y with diaeresis
                        0,                    //0xA0      &nbsp; Non-breaking space
                        0,                    //0xA1     &iexcl; Inverted exclamation mark
                        0,                    //0xA2     &cent; Cent sign
                        1033 + ASC_SHF,        //0xA3     &pound; Pound sign
                        0,                    //0xA4     &curren; Currency sign
                        0,                    //0xA5     &yen; Yen sign
                        0,                    //0xA6     &brvbar; Pipe, Broken vertical bar
                        1056 + ASC_SHF,        //0xA7     &sect; Section sign
                        0,                    //0xA8     &uml; Spacing diaeresis - umlaut
                        0,                    //0xA9     &copy; Copyright sign
                        0,                    //0xAA     &ordf; Feminine ordinal indicator
                        0,                    //0xAB     &laquo; Left double angle quotes
                        0,                    //0xAC     &not; Not sign
                        0,                    //0xAD      .. Soft hyphen
                        0,                    //0xAE     &reg; Registered trade mark sign
                        0,                    //0xAF     &macr; Spacing macron - overline
                        0,                    //0xB0     &deg; Degree sign
                        0,                    //0xB1     &plusmn; Plus-or-minus sign
                        1053,                //0xB2      Superscript two - squared
                        0,                    //0xB3      Superscript three - cubed
                        0,                    //0xB4     &acute; Acute accent - spacing acute
                        1049 + ASC_SHF,        //0xB5     &micro; Micro sign
                        0,                    //0xB6     &para; Pilcrow sign - paragraph sign
                        0,                    //0xB7     &middot; Middle dot - Georgian comma
                        0,                    //0xB8     &cedil; Spacing cedilla
                        0,                    //0xB9      Superscript one
                        0,                    //0xBA     &ordm; Masculine ordinal indicator
                        0,                    //0xBB     &raquo; Right double angle quotes
                        0,                    //0xBC      Fraction one quarter
                        0,                    //0xBD      Fraction one half
                        0,                    //0xBE      Fraction three quarters
                        0,                    //0xBF     &iquest; Inverted question mark
                        0,                    //0xC0     &Agrave; Latin capital letter A with grave
                        0,                    //0xC1     &Aacute; Latin capital letter A with acute
                        0,                    //0xC2     &Acirc; Latin capital letter A with circumflex
                        0,                    //0xC3     &Atilde; Latin capital letter A with tilde
                        0,                    //0xC4     &Auml; Latin capital letter A with diaeresis
                        0,                    //0xC5     &Aring; Latin capital letter A with ring above
                        0,                    //0xC6     &AElig; Latin capital letter AE
                        0,                    //0xC7     &Ccedil; Latin capital letter C with cedilla
                        0,                    //0xC8     &Egrave; Latin capital letter E with grave
                        0,                    //0xC9     &Eacute; Latin capital letter E with acute
                        0,                    //0xCA     &Ecirc; Latin capital letter E with circumflex
                        0,                    //0xCB     &Euml; Latin capital letter E with diaeresis
                        0,                    //0xCC     &Igrave; Latin capital letter I with grave
                        0,                    //0xCD     &Iacute; Latin capital letter I with acute
                        0,                    //0xCE     &Icirc; Latin capital letter I with circumflex
                        0,                    //0xCF     &Iuml; Latin capital letter I with diaeresis
                        0,                    //0xD0     &ETH; Latin capital letter ETH
                        0,                    //0xD1     &Ntilde; Latin capital letter N with tilde
                        0,                    //0xD2     &Ograve; Latin capital letter O with grave
                        0,                    //0xD3     &Oacute; Latin capital letter O with acute
                        0,                    //0xD4     &Ocirc; Latin capital letter O with circumflex
                        0,                    //0xD5     &Otilde; Latin capital letter O with tilde
                        0,                    //0xD6     &Ouml; Latin capital letter O with diaeresis
                        0,                    //0xD7     &times; Multiplication sign
                        0,                    //0xD8     &Oslash; Latin capital letter O with slash
                        0,                    //0xD9     &Ugrave; Latin capital letter U with grave
                        0,                    //0xDA     &Uacute; Latin capital letter U with acute
                        0,                    //0xDB     &Ucirc; Latin capital letter U with circumflex
                        0,                    //0xDC     &Uuml; Latin capital letter U with diaeresis
                        0,                    //0xDD     &Yacute; Latin capital letter Y with acute
                        0,                    //0xDE     &THORN; Latin capital letter THORN
                        0,                    //0xDF     &szlig; Latin small letter sharp s - ess-zed
                        1039,                //0xE0     &agrave; Latin small letter a with grave
                        0,                    //0xE1     &aacute; Latin small letter a with acute
                        0,                    //0xE2     &acirc; Latin small letter a with circumflex
                        0,                    //0xE3     &atilde; Latin small letter a with tilde
                        0,                    //0xE4     &auml; Latin small letter a with diaeresis
                        0,                    //0xE5     &aring; Latin small letter a with ring above
                        0,                    //0xE6     &aelig; Latin small letter ae
                        1038,                //0xE7     &ccedil; Latin small letter c with cedilla
                        1036,                //0xE8     &egrave; Latin small letter e with grave
                        1031,                //0xE9     &eacute; Latin small letter e with acute
                        0,                    //0xEA     &ecirc; Latin small letter e with circumflex
                        0,                    //0xEB     &euml; Latin small letter e with diaeresis
                        0,                    //0xEC     &igrave; Latin small letter i with grave
                        0,                    //0xED     &iacute; Latin small letter i with acute
                        0,                    //0xEE     &icirc; Latin small letter i with circumflex
                        0,                    //0xEF     &iuml; Latin small letter i with diaeresis
                        0,                    //0xF0     &eth; Latin small letter eth
                        0,                    //0xF1     &ntilde; Latin small letter n with tilde
                        0,                    //0xF2     &ograve; Latin small letter o with grave
                        0,                    //0xF3     &oacute; Latin small letter o with acute
                        0,                    //0xF4     &ocirc; Latin small letter o with circumflex
                        0,                    //0xF5     &otilde; Latin small letter o with tilde
                        0,                    //0xF6     &ouml; Latin small letter o with diaeresis
                        0,                    //0xF7     &divide; Division sign
                        0,                    //0xF8     &oslash; Latin small letter o with slash
                        1052,                //0xF9     &ugrave; Latin small letter u with grave
                        0,                    //0xFA     &uacute; Latin small letter u with acute
                        0,                    //0xFB     &ucirc; Latin small letter u with circumflex
                        0,                    //0xFC     &uuml; Latin small letter u with diaeresis
                        0,                    //0xFD     &yacute; Latin small letter y with acute
                        0,                    //0xFE     &thorn; Latin small letter thorn
                        0                    //0xFF     &yuml; Latin small letter y with diaeresis
                        };
    
    short ASCG[256]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                        1044,                //0x20    <space>
                        1030 + ASC_SHF,        //0x21    ! Exclamation mark
                        1031 + ASC_SHF,        //0x22    " &quot; Double quotes (or speech marks)
                        1049,                //0x23    # Number
                        1033 + ASC_SHF,        //0x24    $ Dollar
                        1034 + ASC_SHF,        //0x25    % Procenttecken
                        1035 + ASC_SHF,        //0x21    & &amp; Ampersand
                        1049 + ASC_SHF,        //0x27    ' Single quote
                        1037 + ASC_SHF,         //0x28    ( Open parenthesis (or open bracket)
                        1038 + ASC_SHF,        //0x29    ) Close parenthesis (or close bracket)
                        1048 + ASC_SHF,        //0x2a    * Asterisk
                        1048,                //0x2b    + Plus
                        1054,                //0x2c    , Comma
                        1056,                //0x2d    - Hyphen
                        1055,                //0x2e    . Period, dot or full stop
                        1036 + ASC_SHF,        //0x2f    / Slash or divide
                        1039,                //0x30    0 Zero
                        1030,                //0x31    1 One
                        1031,                //0x32    2 Two
                        1032,                //0x33    3 Three
                        1033,                //0x34    4 Four
                        1034,                //0x35    5 Five
                        1035,                //0x36    6 Six
                        1036,                //0x37    7 Seven
                        1037,                //0x38    8 Eight
                        1038,                //0x39    9 Nine
                        1055 + ASC_SHF,        //0x3a    : Colon
                        1054 + ASC_SHF,        //0x3b    ; Semicolon
                        1100,                //0x3c    < &lt; Less than (or open angled bracket)
                        1039 + ASC_SHF,        //0x3d    = Equals
                        1100 + ASC_SHF,        //0x3e    > &gt; Greater than (or close angled bracket)
                        1045 + ASC_SHF,        //0x3f    ? Question mark
                        1004 + ASC_AGR,        //0x40    @ At symbol
                        1004 + ASC_SHF,        //0x41    A Uppercase A
                        1005 + ASC_SHF,        //0x42    B Uppercase B
                        1006 + ASC_SHF,        //0x43    C Uppercase C
                        1007 + ASC_SHF,        //0x44    D Uppercase D
                        1008 + ASC_SHF,        //0x45    E Uppercase E
                        1009 + ASC_SHF,        //0x46    F Uppercase F
                        1010 + ASC_SHF,        //0x47    G Uppercase G
                        1011 + ASC_SHF,        //0x48    H Uppercase H
                        1012 + ASC_SHF,        //0x49    I Uppercase I
                        1013 + ASC_SHF,        //0x4a    J Uppercase J
                        1014 + ASC_SHF,        //0x4b    K Uppercase K
                        1015 + ASC_SHF,        //0x4c    L Uppercase L
                        1016 + ASC_SHF,        //0x4d    M Uppercase M
                        1017 + ASC_SHF,        //0x4e    N Uppercase N
                        1018 + ASC_SHF,        //0x4f    O Uppercase O
                        1019 + ASC_SHF,        //0x50    P Uppercase P
                        1020 + ASC_SHF,        //0x51    Q Uppercase Q
                        1021 + ASC_SHF,        //0x52    R Uppercase R
                        1022 + ASC_SHF,        //0x53    S Uppercase S
                        1023 + ASC_SHF,        //0x54    T Uppercase T
                        1024 + ASC_SHF,        //0x55    U Uppercase U
                        1025 + ASC_SHF,        //0x56    V Uppercase V
                        1026 + ASC_SHF,        //0x57    W Uppercase W
                        1027 + ASC_SHF,        //0x58    X Uppercase X
                        1029 + ASC_SHF,        //0x59    Y Uppercase Y
                        1028 + ASC_SHF,        //0x5a    Z Uppercase Z
                        1037 + ASC_AGR,        //0x5b    [ Opening bracket
                        1045 + ASC_AGR,        //0x5c    \ Backslash
                        1038 + ASC_AGR,        //0x5d    ] Closing bracket
                        1053,                //0x5e    ^ Caret - circumflex
                        1056 + ASC_SHF,        //0x5f    _ Underscore
                        1046 + ASC_SHF,        //0x60    ` Grave accent
                        1004,                //0x61    a Lowercase a
                        1005,                //0x62    b Lowercase b
                        1006,                //0x63    c Lowercase c
                        1007,                //0x64    d Lowercase d
                        1008,                //0x65    e Lowercase e
                        1009,                //0x66    f Lowercase f
                        1010,                //0x67    g Lowercase g
                        1011,                //0x68    h Lowercase h
                        1012,                //0x69    i Lowercase i
                        1013,                //0x6a    j Lowercase j
                        1014,                //0x6b    k Lowercase k
                        1015,                //0x6c    l Lowercase l
                        1016,                //0x6d    m Lowercase m
                        1017,                //0x6e    n Lowercase n
                        1018,                //0x6f    o Lowercase o
                        1019,                //0x70    p Lowercase p
                        1020,                //0x71    q Lowercase q
                        1021,                //0x72    r Lowercase r
                        1022,                //0x73    s Lowercase s
                        1023,                //0x74    t Lowercase t
                        1024,                //0x75    u Lowercase u
                        1025,                //0x76    v Lowercase v
                        1026,                //0x77    w Lowercase w
                        1027,                //0x78    x Lowercase x
                        1029,                //0x79    y Lowercase y
                        1028,                //0x7a    z Lowercase z
                        1036 + ASC_AGR,        //0x7b    { Opening brace
                        1100 + ASC_AGR,        //0x7c    | Vertical bar
                        1039 + ASC_AGR,        //0x7d    } Closing brace
                        1048 + ASC_AGR,        //0x7e    ~ Equivalency sign - tilde
                        1076,                //0x7F    delete
                        1008 + ASC_AGR,        //0x80     &euro; Euro sign
                        0,                    //0x81    
                        0,                    //0x82     &sbquo; Single low-9 quotation mark
                        0,                    //0x83     &fnof; Latin small letter f with hook
                        0,                    //0x84     &bdquo; Double low-9 quotation mark
                        0,                    //0x85     &hellip; Horizontal ellipsis
                        0,                    //0x86     &dagger; Dagger
                        0,                    //0x87     &Dagger; Double dagger
                        0,                    //0x88     &circ; Modifier letter circumflex accent
                        0,                    //0x89     &permil; Per mille sign
                        0,                    //0x8A     &Scaron; Latin capital letter S with caron
                        0,                    //0x8B     &lsaquo; Single left-pointing angle quotation
                        0,                    //0x8C     &OElig; Latin capital ligature OE
                        0,                    //0x8D    
                        0,                    //0x8E     Latin captial letter Z with caron
                        0,                    //0x8F    
                        0,                    //0x90    
                        0,                    //0x91     &lsquo; Left single quotation mark
                        0,                    //0x92     &rsquo; Right single quotation mark
                        0,                    //0x93     &ldquo; Left double quotation mark
                        0,                    //0x94     &rdquo; Right double quotation mark
                        0,                    //0x95     &bull; Bullet
                        0,                    //0x96     &ndash; En dash
                        0,                    //0x97     &mdash; Em dash
                        0,                    //0x98     &tilde; Small tilde
                        0,                    //0x99     &trade; Trade mark sign
                        0,                    //0x9A     &scaron; Latin small letter S with caron
                        0,                    //0x9B     &rsaquo; Single right-pointing angle quotation mark
                        0,                    //0x9C     &oelig; Latin small ligature oe
                        0,                    //0x9D
                        0,                    //0x9E     Latin small letter z with caron
                        0,                    //0x9F     &yuml; Latin capital letter Y with diaeresis
                        0,                    //0xA0      &nbsp; Non-breaking space
                        0,                    //0xA1     &iexcl; Inverted exclamation mark
                        0,                    //0xA2     &cent; Cent sign
                        0,                    //0xA3     &pound; Pound sign
                        0,                    //0xA4     &curren; Currency sign
                        0,                    //0xA5     &yen; Yen sign
                        0,                    //0xA6     &brvbar; Pipe, Broken vertical bar
                        1032 + ASC_SHF,        //0xA7     &sect; Section sign
                        0,                    //0xA8     &uml; Spacing diaeresis - umlaut
                        0,                    //0xA9     &copy; Copyright sign
                        0,                    //0xAA     &ordf; Feminine ordinal indicator
                        0,                    //0xAB     &laquo; Left double angle quotes
                        0,                    //0xAC     &not; Not sign
                        0,                    //0xAD      .. Soft hyphen
                        0,                    //0xAE     &reg; Registered trade mark sign
                        0,                    //0xAF     &macr; Spacing macron - overline
                        0,                    //0xB0     &deg; Degree sign
                        0,                    //0xB1     &plusmn; Plus-or-minus sign
                        1031 + ASC_AGR,        //0xB2      Superscript two - squared
                        1032 + ASC_AGR,        //0xB3      Superscript three - cubed
                        0,                    //0xB4     &acute; Acute accent - spacing acute
                        1016 + ASC_AGR,        //0xB5     &micro; Micro sign
                        0,                    //0xB6     &para; Pilcrow sign - paragraph sign
                        0,                    //0xB7     &middot; Middle dot - Georgian comma
                        0,                    //0xB8     &cedil; Spacing cedilla
                        0,                    //0xB9      Superscript one
                        0,                    //0xBA     &ordm; Masculine ordinal indicator
                        0,                    //0xBB     &raquo; Right double angle quotes
                        0,                    //0xBC      Fraction one quarter
                        0,                    //0xBD      Fraction one half
                        0,                    //0xBE      Fraction three quarters
                        0,                    //0xBF     &iquest; Inverted question mark
                        0,                    //0xC0     &Agrave; Latin capital letter A with grave
                        0,                    //0xC1     &Aacute; Latin capital letter A with acute
                        0,                    //0xC2     &Acirc; Latin capital letter A with circumflex
                        0,                    //0xC3     &Atilde; Latin capital letter A with tilde
                        1052 + ASC_SHF,        //0xC4     &Auml; Latin capital letter A with diaeresis
                        0,                    //0xC5     &Aring; Latin capital letter A with ring above
                        0,                    //0xC6     &AElig; Latin capital letter AE
                        0,                    //0xC7     &Ccedil; Latin capital letter C with cedilla
                        0,                    //0xC8     &Egrave; Latin capital letter E with grave
                        0,                    //0xC9     &Eacute; Latin capital letter E with acute
                        0,                    //0xCA     &Ecirc; Latin capital letter E with circumflex
                        0,                    //0xCB     &Euml; Latin capital letter E with diaeresis
                        0,                    //0xCC     &Igrave; Latin capital letter I with grave
                        0,                    //0xCD     &Iacute; Latin capital letter I with acute
                        0,                    //0xCE     &Icirc; Latin capital letter I with circumflex
                        0,                    //0xCF     &Iuml; Latin capital letter I with diaeresis
                        0,                    //0xD0     &ETH; Latin capital letter ETH
                        0,                    //0xD1     &Ntilde; Latin capital letter N with tilde
                        0,                    //0xD2     &Ograve; Latin capital letter O with grave
                        0,                    //0xD3     &Oacute; Latin capital letter O with acute
                        0,                    //0xD4     &Ocirc; Latin capital letter O with circumflex
                        0,                    //0xD5     &Otilde; Latin capital letter O with tilde
                        1051 + ASC_SHF,        //0xD6     &Ouml; Latin capital letter O with diaeresis
                        0,                    //0xD7     &times; Multiplication sign
                        0,                    //0xD8     &Oslash; Latin capital letter O with slash
                        0,                    //0xD9     &Ugrave; Latin capital letter U with grave
                        0,                    //0xDA     &Uacute; Latin capital letter U with acute
                        0,                    //0xDB     &Ucirc; Latin capital letter U with circumflex
                        1047 + ASC_SHF,        //0xDC     &Uuml; Latin capital letter U with diaeresis
                        0,                    //0xDD     &Yacute; Latin capital letter Y with acute
                        0,                    //0xDE     &THORN; Latin capital letter THORN
                        1045,                //0xDF     &szlig; Latin small letter sharp s - ess-zed
                        0,                    //0xE0     &agrave; Latin small letter a with grave
                        0,                    //0xE1     &aacute; Latin small letter a with acute
                        0,                    //0xE2     &acirc; Latin small letter a with circumflex
                        0,                    //0xE3     &atilde; Latin small letter a with tilde
                        1052,                //0xE4     &auml; Latin small letter a with diaeresis
                        0,                    //0xE5     &aring; Latin small letter a with ring above
                        0,                    //0xE6     &aelig; Latin small letter ae
                        0,                    //0xE7     &ccedil; Latin small letter c with cedilla
                        0,                    //0xE8     &egrave; Latin small letter e with grave
                        0,                    //0xE9     &eacute; Latin small letter e with acute
                        0,                    //0xEA     &ecirc; Latin small letter e with circumflex
                        0,                    //0xEB     &euml; Latin small letter e with diaeresis
                        0,                    //0xEC     &igrave; Latin small letter i with grave
                        0,                    //0xED     &iacute; Latin small letter i with acute
                        0,                    //0xEE     &icirc; Latin small letter i with circumflex
                        0,                    //0xEF     &iuml; Latin small letter i with diaeresis
                        0,                    //0xF0     &eth; Latin small letter eth
                        0,                    //0xF1     &ntilde; Latin small letter n with tilde
                        0,                    //0xF2     &ograve; Latin small letter o with grave
                        0,                    //0xF3     &oacute; Latin small letter o with acute
                        0,                    //0xF4     &ocirc; Latin small letter o with circumflex
                        0,                    //0xF5     &otilde; Latin small letter o with tilde
                        1051,                //0xF6     &ouml; Latin small letter o with diaeresis
                        0,                    //0xF7     &divide; Division sign
                        0,                    //0xF8     &oslash; Latin small letter o with slash
                        0,                    //0xF9     &ugrave; Latin small letter u with grave
                        0,                    //0xFA     &uacute; Latin small letter u with acute
                        0,                    //0xFB     &ucirc; Latin small letter u with circumflex
                        1047,                //0xFC     &uuml; Latin small letter u with diaeresis
                        0,                    //0xFD     &yacute; Latin small letter y with acute
                        0,                    //0xFE     &thorn; Latin small letter thorn
                        0                    //0xFF     &yuml; Latin small letter y with diaeresis
                        };
    
    alias ASC = &ASCE;    // english keyboard layout as default
    
    // --------------------------------------  virtual joystick interface --------------------------------------
    define DX1            3000                
    define DX2            3001
    define DX3            3002
    define DX4            3003
    define DX5            3004
    define DX6            3005
    define DX7            3006
    define DX8            3007
    define DX9            3008
    define DX10            3009
    define DX11            3010
    define DX12            3011
    define DX13            3012
    define DX14            3013
    define DX15            3014
    define DX16            3015
    define DX17            3016
    define DX18            3017
    define DX19            3018
    define DX20            3019
    define DX21            3020
    define DX22            3021
    define DX23            3022
    define DX24            3023
    define DX25            3024
    define DX26            3025
    define DX27            3026
    define DX28            3027
    define DX29            3028
    define DX30            3029
    define DX31            3030
    define DX32            3031
    define DXHATUP            3032
    define DXHATUPRIGHT     3033
    define DXHATRIGHT        3034
    define DXHATDOWNRIGHT     3035
    define DXHATDOWN        3036
    define DXHATDOWNLEFT     3037
    define DXHATLEFT        3038
    define DXHATUPLEFT        3039
    
    define DX_X_AXIS        1        
    define DX_Y_AXIS        2
    define DX_Z_AXIS        3
    define DX_XROT_AXIS        4
    define DX_YROT_AXIS        5
    define DX_ZROT_AXIS        6
    define DX_THROTTLE_AXIS 7
    define DX_SLIDER_AXIS     8
    
    // ------------------------------------------- virtual mouse interface --------------------------------------
    define MOUSE_LEFT        4000            
    define MOUSE_RIGHT        4001
    define MOUSE_CENTER        4002
    define MOUSE_BTN4        4003
    define MOUSE_BTN5        4004
    define MOUSE_X_AXIS        9
    define MOUSE_Y_AXIS        10
    define MOUSE_Z_AXIS        11
    
    
    
    // ------------------------------------- Warthog Joystick interface -------------------------------------
    define TG1                0
    define S2                1
    define S3                2
    define S4                3
    define S1                4
    define TG2                5
    define H2U                6
    define H2R                7
    define H2D                8
    define H2L                9
    define H3U                10
    define H3R                11
    define H3D                12
    define H3L                13
    define H4U                14
    define H4R                15
    define H4D                16
    define H4L                17
    define H4P                18
    define H1U                29            // 4 virtual keys generated by the joystick HAT
    define H1R                30
    define H1D                31
    define H1L                32
    define JOYX                IN_POSITION_AXIS_X
    define JOYY                IN_POSITION_AXIS_Y
    define POV                 IN_POSITION_HAT
    
    // -----------------------------------  Warthog Throttle interface --------------------------------
    define SC                0
    define MSP                1
    define MSU                2
    define MSR                3
    define MSD                4
    define MSL                5
    define SPDF                6
    define SPDB                7
    define BSF                8
    define BSB                9
    define CHF                10
    define CHB                11
    define PSF                12
    define PSB                13
    define LTB                14
    define EFLNORM            15
    define EFRNORM            16
    define EOLMOTOR            17
    define EORMOTOR            18
    define APUON            19
    define LDGH                20
    define FLAPU            21
    define FLAPD            22
    define EACON            23
    define RDRNRM            24
    define APENG            25
    define APPAT            26
    define APALT            27
    define IDLERON            28
    define IDLELON            29
    define EOLIGN            30
    define EORIGN            31
    define CSU                32    // 4 virtual buttons generated by the HAT
    define CSR                33
    define CSD                34
    define CSL                35
    define EFLOVER            36  // 8 virtual buttons for 2way switches
    define EFROVER            37
    define APUOFF            38
    define EACOFF            39
    define RDRDIS            40
    define APDIS            41
    define IDLEROFF            42
    define IDLELOFF            43
    define EOLNORM            44    // 8 virtual buttons generated by the 3 way switches
    define EORNORM            45
    define FLAPM            46
    define SPDM                47    
    define BSM                48
    define CHM                49
    define PSM                50
    define APAH                51
    define SCX                IN_POSITION_AXIS_X
    define SCY                IN_POSITION_AXIS_Y
    define THR_RIGHT        IN_POSITION_AXIS_Z
    define THR_LEFT            IN_POSITION_AXIS_RZ
    define THR_FC            IN_POSITION_AXIS_SLIDER1
    define CS                IN_POSITION_HAT
    
    // -----------------------------------  Hoats Cougar interface --------------------------------
    //define TG1            0            // joystick buttons, the same names like warthog joystick
    //define S2                1
    //define S3                2
    //define S4                3
    //define S1                4
    //define TG2            5
    //define H2U            6
    //define H2R            7
    //define H2D            8
    //define H2L            9
    //define H3U            10
    //define H3R            11
    //define H3D            12
    //define H3L            13
    //define H4U            14
    //define H4R            15
    //define H4D            16
    //define H4L            17
    //define H4P            18
    //define H1U            29            // 4 virtual keys generated by the joystick HAT
    //define H1R            30
    //define H1D            31
    //define H1L            32
    //define JOYX            IN_POSITION_AXIS_X
    //define JOYY            IN_POSITION_AXIS_Y
    //define POV             IN_POSITION_HAT
    
    define T1                18                // throttle buttons
    define T2                19
    define T3                20
    define T4                21
    define T5                22
    define T6                23
    define T7                24
    define T8                25
    define T9                26
    define T10                27
    define DFM                28                 // 2 virtual buttons
    //define SPDM            47
    define THROTTLE            IN_POSITION_AXIS_Z
    define RDR_X            IN_POSITION_AXIS_RX
    define RDR_Y            IN_POSITION_AXIS_RY
    define RUDDER            IN_POSITION_AXIS_RZ
    define MAN_RNG            IN_POSITION_AXIS_SLIDER1
    define ANT_ELEV            IN_POSITION_AXIS_THROTTLE
    
    // -----------------------------------  T16000 interface --------------------------------
    define TS1                0                
    define TS2                1
    define TS3                2
    define TS4                3
    define B5                4
    define B6                5
    define B7                6
    define B8                7
    define B9                8
    define B10                9
    define B11                10
    define B12                11
    define B13                12
    define B14                13
    define B15                14
    define B16                15
    //define H1U            29                // 4 virtual keys generated by the joystick HAT
    //define H1R            30
    //define H1D            31
    //define H1L            32
    //define JOYX            IN_POSITION_AXIS_X
    //define JOYY            IN_POSITION_AXIS_Y
    //define RUDDER            IN_POSITION_AXIS_RZ
    define THR                IN_POSITION_AXIS_SLIDER1
    define HAT                 IN_POSITION_HAT
    
    
    // -----------------------------------  MFD interface --------------------------------
    define OSB01            0                
    define OSB02            1
    define OSB03            2
    define OSB04            3
    define OSB05            4
    define OSB06            5
    define OSB07            6
    define OSB08            7
    define OSB09            8
    define OSB10            9
    define OSB11            10
    define OSB12            11
    define OSB13            12
    define OSB14            13
    define OSB15            14
    define OSB16            15
    define OSB17            16
    define OSB18            17
    define OSB19            18
    define OSB20            19
    define SYMU                20
    define SYMD                21
    define CONU                22
    define COND                23
    define BRTU                24
    define BRTD                25
    define GAINU            26
    define GAIND            27
    
    // ------------------------------------------- Other constants ------------------------------------------
    define AMAX             32767        // axis values are between -AMAX and AMAX
    define AMAXF            32768.
    define POVU             0            // POV control possible values (clockwise angles in degrees)
    define POVUR             45
    define POVR             90
    define POVDR             135
    define POVD             180
    define POVDL             225
    define POVL             270
    define POVUL             315
    define POVCENTER        -1
    define AXIS_NORMAL        1
    define AXIS_REVERSED    -1
    define MAP_ABSOLUTE        0
    define MAP_RELATIVE        1
    sys.tmh
    Code:
    define    SEEK_SET            0
    define    SEEK_CUR            1
    define    SEEK_END            2
    
    define    MAP_NORMAL        1
    define    MAP_IPTR            2
    define    MAP_IPTR_VPN    3
    define    MAP_THISCALL    4
    
    define    VAR_NONE            0
    define    VAR_CHAR            1
    define    VAR_BYTE            2
    define    VAR_SHORT            3
    define    VAR_WORD            4
    define    VAR_INT                5
    define    VAR_ALIAS            6
    define    VAR_FLOAT            7
    define    VAR_STRUCT        8
    
    // Mapped functions
    int    VARSIZE;
    int putchar(char c){}            // display a character at console
    int sizeof(alias var){}        // return the size of the variable, in bytes
    int elements(alias var){} // returns the number of elements in an array
    float eval(alias s){}            // evaluate an expression in a char[] variable and returns the float result (0 if error)
    int ieval(alias s){}            // evaluate an expression in a char[] variable and returns the int result (0 if error)
    float execute(alias s){}    // execute a statement in a char[] and return the <return> float value
    float iexecute(alias s){} // execute a statement in a char[] and return the <return> int value
    int defined(alias name){} // 0 if variable is not defined. name is a Char array
    int input(alias s){}            // input a string from keyboard
    int dis(alias var){}            // dissasemble a function
    int strname(alias var, alias str){};    // place the var name in a string
    int strlen(alias s){}            // returns the lenght of the string
    int strcat(alias dst, alias src){}        // concatenate 2 strings
    int strsub(alias dst, alias src, int start, int end){}    // get substring
    int strchr(alias s, char c){}                    // return char first occurence in string
    int strdel(alias s, int start, int end){}        // delete characters between start and end
    int strins(alias dst, alias src, int pos){} // insert dst in src at pos
    int strcmp(alias s1, alias s2){} 
    int printf(){}                        // VPN mapped
    int sprintf(){}                        // VPN mapped
    float sin(float f){}
    float cos(float f){}
    float tan(float f){}
    float asin(float f){}
    float acos(float f){}
    float atan(float f){}
    float atan2(float x, float y){}
    float exp(float f){}
    float ln(float f){}        // base e
    float log(float f){}    // base 10
    float pow(float base, float exp){}
    float sqrt(float f){}
    int getmem(int addr, int size){}        // 0< size <=4
    int setmem(int addr, int size, int val){} // 0< size <=4
    int gettype(int var){}                            // returns 0:NOVAR, 1:CHAR, 2:BYTE, 3:SHORT, 4:WORD, 5:INT, 6:ALIAS, 7:FLOAT, 8:STRUCT
    int Dim(alias var, int dim){}                // returns actual set dimension (<MAX_ARRAY_SIZE). Do not initialize the extension, keeps the initial data
    
    int fopen(alias name, alias mode){} // returns file handle, NULL if error
    int fclose(int handle){}                        // returns 0 if OK, -1 on error
    int fgetc(int handle){}                            // returns the character read, or -1 on error or EOF
    int fputc(int c, int handle){}            // returns the written character, -1 on error
    int fread(alias buffer, int size, int count, int handle){}    // returns number of items read
    int fwrite(alias buffer, int size, int count, int handle){}    // returns number of items written
    int ftell(int handle){}                            // returns the file position
    int fseek(int handle, int offset, int origin){}                            // origin: 0=set, 1=cur, 2=end. Returns 0 on success, -1 else
    int feof(int handle){}                            // returns != 0 if EOF
    
    int LoadLibrary(alias filename){}
    int FreeLibrary(int handle){}
    int GetProcAddress(int dll, alias name){}
    int Map(alias object, int address, int mode=1){}        // returns object. mode:MAP_NORMAL=1, MAP_IPTR=2, MAP_IPTR_VPN=3, MAP_THISCALL=4
    int MakeProcInstance(alias proc, int thisAdjust=0){}// returns the instance, or 0 on error. The procedure is seen as _stdcall or _thiscall( if thisAdjust<0). thisAdjust (or ~thisAdjust if <0) substracted from <this> for multiple derivation
    int FreeProcInstance(int instance){}                                // returns 1 if OK, 0 else
    alias ProcInstCallback;                                                            // (int psInterpreter, alias fn) - debugging purpose
    
    float abs(float i)
    {
        if(i<0) return -i;
        return i;
    }
    
    int sgn(int i)
    {
        if(i<0) return 0xffffffff;
        return !!i;
    }
    
    int malloc(int size){}
    int realloc(int addr, int size){}
    int free(int addr){}
    int msize(int addr){}                                                // returns -1 if addr is not allocated
    int memcpy(int dst, int src, int size){}        // use with care, can crash the application
    int system(alias cmd){}

    hid.tmh
    Code:
    define    SEEK_SET            0
    define    SEEK_CUR            1
    define    SEEK_END            2
    
    define    MAP_NORMAL        1
    define    MAP_IPTR            2
    define    MAP_IPTR_VPN    3
    define    MAP_THISCALL    4
    
    define    VAR_NONE            0
    define    VAR_CHAR            1
    define    VAR_BYTE            2
    define    VAR_SHORT            3
    define    VAR_WORD            4
    define    VAR_INT                5
    define    VAR_ALIAS            6
    define    VAR_FLOAT            7
    define    VAR_STRUCT        8
    
    // Mapped functions
    int    VARSIZE;
    int putchar(char c){}            // display a character at console
    int sizeof(alias var){}        // return the size of the variable, in bytes
    int elements(alias var){} // returns the number of elements in an array
    float eval(alias s){}            // evaluate an expression in a char[] variable and returns the float result (0 if error)
    int ieval(alias s){}            // evaluate an expression in a char[] variable and returns the int result (0 if error)
    float execute(alias s){}    // execute a statement in a char[] and return the <return> float value
    float iexecute(alias s){} // execute a statement in a char[] and return the <return> int value
    int defined(alias name){} // 0 if variable is not defined. name is a Char array
    int input(alias s){}            // input a string from keyboard
    int dis(alias var){}            // dissasemble a function
    int strname(alias var, alias str){};    // place the var name in a string
    int strlen(alias s){}            // returns the lenght of the string
    int strcat(alias dst, alias src){}        // concatenate 2 strings
    int strsub(alias dst, alias src, int start, int end){}    // get substring
    int strchr(alias s, char c){}                    // return char first occurence in string
    int strdel(alias s, int start, int end){}        // delete characters between start and end
    int strins(alias dst, alias src, int pos){} // insert dst in src at pos
    int strcmp(alias s1, alias s2){} 
    int printf(){}                        // VPN mapped
    int sprintf(){}                        // VPN mapped
    float sin(float f){}
    float cos(float f){}
    float tan(float f){}
    float asin(float f){}
    float acos(float f){}
    float atan(float f){}
    float atan2(float x, float y){}
    float exp(float f){}
    float ln(float f){}        // base e
    float log(float f){}    // base 10
    float pow(float base, float exp){}
    float sqrt(float f){}
    int getmem(int addr, int size){}        // 0< size <=4
    int setmem(int addr, int size, int val){} // 0< size <=4
    int gettype(int var){}                            // returns 0:NOVAR, 1:CHAR, 2:BYTE, 3:SHORT, 4:WORD, 5:INT, 6:ALIAS, 7:FLOAT, 8:STRUCT
    int Dim(alias var, int dim){}                // returns actual set dimension (<MAX_ARRAY_SIZE). Do not initialize the extension, keeps the initial data
    
    int fopen(alias name, alias mode){} // returns file handle, NULL if error
    int fclose(int handle){}                        // returns 0 if OK, -1 on error
    int fgetc(int handle){}                            // returns the character read, or -1 on error or EOF
    int fputc(int c, int handle){}            // returns the written character, -1 on error
    int fread(alias buffer, int size, int count, int handle){}    // returns number of items read
    int fwrite(alias buffer, int size, int count, int handle){}    // returns number of items written
    int ftell(int handle){}                            // returns the file position
    int fseek(int handle, int offset, int origin){}                            // origin: 0=set, 1=cur, 2=end. Returns 0 on success, -1 else
    int feof(int handle){}                            // returns != 0 if EOF
    
    int LoadLibrary(alias filename){}
    int FreeLibrary(int handle){}
    int GetProcAddress(int dll, alias name){}
    int Map(alias object, int address, int mode=1){}        // returns object. mode:MAP_NORMAL=1, MAP_IPTR=2, MAP_IPTR_VPN=3, MAP_THISCALL=4
    int MakeProcInstance(alias proc, int thisAdjust=0){}// returns the instance, or 0 on error. The procedure is seen as _stdcall or _thiscall( if thisAdjust<0). thisAdjust (or ~thisAdjust if <0) substracted from <this> for multiple derivation
    int FreeProcInstance(int instance){}                                // returns 1 if OK, 0 else
    alias ProcInstCallback;                                                            // (int psInterpreter, alias fn) - debugging purpose
    
    float abs(float i)
    {
        if(i<0) return -i;
        return i;
    }
    
    int sgn(int i)
    {
        if(i<0) return 0xffffffff;
        return !!i;
    }
    
    int malloc(int size){}
    int realloc(int addr, int size){}
    int free(int addr){}
    int msize(int addr){}                                                // returns -1 if addr is not allocated
    int memcpy(int dst, int src, int size){}        // use with care, can crash the application
    int system(alias cmd){}
    target.tmh
    Code:
    // TARGET definitions
    include "hid.tmh"
    include "defines.tmh"
    alias Throttle    = "VID_044F&PID_0404", Joystick    = "VID_044F&PID_0402", LMFD        = "VID_044F&PID_b351";
    alias RMFD         = "VID_044F&PID_b352", HCougar    = "VID_044F&PID_0400", T16000    = "VID_044F&PID_B10A";
    
    define KDATASIZE        13
    define MAXKEYDATA        52*KDATASIZE    // max 52 physical+virtual keys for each device
    define AXDATASIZE        64                // sizeof(sAxis)
    define MAXAXDATA        16*AXDATASIZE    // max 16 physical axis for each device
    struct sAxis
    {
        char dxmap;
        char dir;
        int curvemode;    // 0=none, 1=S, 2=J, else=custom
        char lower, center, upper, curve;             // S curve parameters
        float ab;                                    // J curve parameter, zoom for Scurve
        char locked;
        char relative;
        int trim;
        int val, relpos;
        int key[6];        // ou, iu, om, im, od, id
    }
    struct sDevice
    {
        int keymap[MAXKEYDATA];    // int array
        char axmap[MAXAXDATA];    // sAxis array of 16
    }
    sAxis axdata;
    sDevice devicedata[16], devdata;
    
    // Virtual keyboard interface
    int KeyD(int c){ _key(c, OUT_VALUE_BUTTON_PRESS, 0); }
    int KeyU(int c){ _key(c, OUT_VALUE_BUTTON_RELEASE, 0); }
    int Key(int c, int delay=0){ _key(c, OUT_VALUE_BUTTON_PRESS_RELEASE, delay); }
    int AutoRepeat(int handler, int delay, alias proc, int param){ PostEvent(EV_USR+1+handler, &proc, param, -delay); }
    int StopAutoRepeat(int handler){ RemoveEvent(EV_USR+1+handler); }
    int DeferCall(int delay, alias proc, int param){ PostEvent(EV_USR, &proc, param, delay); }
    int PulseKey(int key, int i=0){ Key(key, kb_pulse); }
    int HoldKey(int key, int press)
    { 
        if(press) KeyD(key); else KeyU(key);
        return press;
    }
    int DX(int index, int value=2){ VirtualOutput(OUT_TYPE_GAME, index, value); } // <index> may be DX button index - 1, axis or POV
    int kb_pulse=32, kb_delay=48;
    int SetKBRate(int pulse_ms=32, int delay_ms=48){ kb_pulse = pulse_ms; kb_delay = delay_ms; }
    int KBLayout[] = {&ASCE, &ASCF, &ASCG};
    define KB_ENG    0
    define KB_FR    1
    define KB_GER    2
    int SetKBLayout(int layout){ &ASC = KBLayout[layout]; }
    
    int layer_sw[9], layer;    //(&&dev[btn], flag, status) * 3
    define    L_SHIFT            0x00010000
    define    R_SHIFT            0x00020000
    define    L_ALT            0x00040000
    define    R_ALT            0x00080000
    define    L_CTL            0x00100000
    define    R_CTL            0x00200000
    define    L_WIN            0x00400000
    define    R_WIN            0x00800000
    define    PULSE            0x01000000
    define    DOWN            0x02000000
    define    UP                0x04000000
    define    PROC            0x08000000
    define    JUMP            0x10000000
    define    DELAY            0x20000000
    define    LOCK            0x40000000
    define    KEYON            0x80000000
    
    int ActKey(int k, int x=0x7fffffff)
    {
        alias hk;
        if(k & PROC)
        {
            &hk = keyalloc[k & 0xffff];
            if(x > AMAX) return hk(&keyalloc, k);
            else return hk(&keyalloc, k, x);
        }
        int press = k<0;
        if((k & (PULSE | DOWN | UP)) == PULSE)
            if(!press) return 0;
            else &hk = &PulseKey;
        else if(k & 0xffffff) &hk = &HoldKey;
            else return 0;
        if(press | !(k & (DOWN | UP)))
        {
            press = press & !(k & UP);
            kb_pulse = kb_pulse + 1;
            LockPulseTimestamps(OUT_TYPE_KEYBOARD, 1);
            if(k & L_SHIFT) hk(LSHF, press);
            if(k & R_SHIFT) hk(RSHF, press);
            if(k & L_ALT) hk(LALT, press);
            if(k & R_ALT) hk(RALT, press);
            if(k & L_CTL) hk(LCTL, press);
            if(k & R_CTL) hk(RCTL, press);
            if(k & L_WIN) hk(LWIN, press);
            if(k & R_WIN) hk(RWIN, press);
            kb_pulse = kb_pulse - 1;
            if(k & 0xffff) hk(k & 0xffff, press);
            LockPulseTimestamps(OUT_TYPE_KEYBOARD, 0);
        }
    }
    
    int DefaultMapping(alias o, int x) 
    {    
        int i, k, ktbl;
        alias a;
        while(i < 9) 
            if(&&o[x] == layer_sw[i]) 
            {
                layer_sw[i+2] = layer_sw[i+2] & layer_sw[i+1] ^ o[x]; 
                if(i>0 & layer_sw[i+2]) layer_sw[11-i] = 0;
                break;
            }
            else i = i+3; 
        k = k + layer_sw[2] + ((layer_sw[8] + !layer_sw[5]) << 1);
        GetDeviceData(&o);
        if(x < IN_POSITION_AXES) 
        {
            i = x*KDATASIZE;
            Map(&ktbl, &&devdata.keymap); Dim(&ktbl, MAXKEYDATA);
            if(o[x]) ktbl[i + KDATASIZE - 1] = k;
            else
            {
                k = ktbl[i + KDATASIZE - 1];
                ActKey(ktbl[i + k]);            // key release
                k = k + 6;                        // /R    
            }
            ActKey(ktbl[i + k] | KEYON);        // key press
        }
        else if(x < IN_POSITION_HAT)
        {
            GetAxisData(&o, x);
            axdata.val = AxisVal(o[x], &axdata);
            if(&o == &Throttle & (x == THR_LEFT | x == THR_RIGHT)) axdata.val = -axdata.val;
            if(!!axdata.dxmap & !axdata.locked & !axdata.relative) DXAxis(axdata.dxmap, axdata.val);
            Map(&ktbl, &&axdata.key); Dim(&ktbl, 6);
            i = 0; while(i<6)
            {
                if(ktbl[i])
                    if(i == k) ActKey(ktbl[i], o[x]);
                    else if(ktbl[i] != ktbl[k]) ActKey(ktbl[i], -AMAX*3);
                i = i+1;
            }
        }
        else; // ignore HAT input
    }
    
    short joy0[296]; // non present joystick dummy
    int GetIndexJoy(int index)
    {
        if(index < 0) return &joy0;
        char t; Dim(&t, 64);
        sprintf(&t, "&joy%u", index+1);
        return ieval(&t);
    }
    
    define MODE_EXCLUDED    0
    define MODE_KEEPENABLED    1
    define MODE_FILTERED    2
    int Exclude(alias a){ Configure(&a, MODE_EXCLUDED); } 
    int Configure(alias a, int mode){ a[0] = mode; }
    int Select(alias id)
    { 
        int i = id[0];
        id[0] = 'V';
        if(i == MODE_EXCLUDED) return -1; 
        else if(i == MODE_KEEPENABLED) return SelectUsbDevice(&id, 1);
        else if(i == MODE_FILTERED) return SelectUsbDevice(&id, 2);
        return SelectUsbDevice(&id);    // 0
    }
    
    //                    BUT  HAT X   Y   Z   Rx  Ry  Rz Thrtl SLD1 SLD2 SLD3 SLD4
    stGameCfg virtualj = { 32, 1,  1,  1,  1,  1,  1,  1,    1,   1,   0,   0,   0};
    define CREATE_JOYSTICK    1
    define CREATE_KEYBOARD    2
    define CREATE_MOUSE        4
    int Init(alias h, int cfg=CREATE_JOYSTICK+CREATE_KEYBOARD+CREATE_MOUSE)
    { 
        &Throttle = GetIndexJoy(Select(&Throttle));    // expect a Warthog Throttle to be plugged on USB
        &Joystick = GetIndexJoy(Select(&Joystick));    // expect a Warthog Stick to be plugged on USB
        &LMFD = GetIndexJoy(Select(&LMFD));            // expect a LMFD to be plugged on USB
        &RMFD = GetIndexJoy(Select(&RMFD));            // expect a RMFD to be plugged on USB
        &HCougar = GetIndexJoy(Select(&HCougar));        // expect a Hotas Cougar to be plugged on USB
        &T16000 = GetIndexJoy(Select(&T16000));        // expect a T16000 to be plugged on USB
        if(cfg & CREATE_JOYSTICK) PlugGame(&virtualj, "Thrustmaster Combined");                        // create a Virtual device
        if(cfg & CREATE_KEYBOARD) PlugKeyboard();
        if(cfg & CREATE_MOUSE) PlugMouse(1);
        &_evh = &h;
        SetEventHandler(&DefEventHandler); 
        SEQ();        // initialize SEQ function as VPN    
        CHAIN();    // initialize CHAIN function as VPN    
        AXMAP2();
        int i; while(i<256) { USB[i] = i+1000; i = i+1; }                    // fill the USB table
        MapList(&Joystick, &JoystickMap);    // default DX buttons mapping for all devices
        MapList(&Throttle, &ThrottleMap);
        MapList(&HCougar, &JoystickMap);
        MapList(&HCougar, &HCougarMap);
        MapList(&LMFD, &MFDMap);
        MapList(&RMFD, &MFDMap);
        MapList(&T16000, &T16000Map);
        i=elements(&vbtntbl); while(i>0)     // initialize Throttle virtual buttons with 1
        {
            i = i-1;
            if(vbtntbl[i]) Throttle[vbtntbl[i]] = 1;
        }
        HCougar[DFM] = 1;                    // initialize Cougar virtual buttons with 1
        HCougar[SPDM] = 1;
        DXAxis(MOUSE_X_AXIS, 0);
        DXAxis(MOUSE_Y_AXIS, 0);
    }
    
    int _gch;        // game callback handler
    int RegisterGameCallback(int TCPPort, alias GameCallback)
    {
        _gch = &GameCallback;
        return InitSocketServer(TCPPort);
    }
    
    alias _evh;
    char h2blookup[9] = {0,1,3,2,6,4,12,8,9}, csStatus[4], h1Status[4], h1cStatus[4], h16000Status[4];
    char vbtntbl[32]={0,0,0,0,0,0,SPDM,SPDM,BSM,BSM,CHM,CHM,PSM,PSM,0,EFLOVER,EFROVER,EOLNORM,EORNORM,APUOFF,0,FLAPM,FLAPM,EACOFF,RDRDIS,APDIS,APAH,APAH,IDLEROFF,IDLELOFF,EOLNORM,EORNORM};
    int DefEventHandler(int e, alias dev, int event) // must be called before any processing in the event handler
    {
        alloc_locked = 1;
        if(e >= EV_USR) return dev(event);
        if(e == EV_GAME_DATA) 
        {
            if(!_gch) return 0;
            e = dev;
            &dev = _gch;
            return dev(e, event);
        }
        if(&dev == &Throttle & (event == THR_LEFT | event == THR_RIGHT)) dev[event] = -dev[event];
        _evh(EV_HID_INPUT_DATA, &dev, event);
        if(&dev == &Throttle)
            if(event <= EORIGN)
                if(vbtntbl[event])            // generate virtual keys
                {
                    dev[vbtntbl[event]] = !dev[event];
                    _evh(EV_HID_INPUT_DATA, &dev, vbtntbl[event]);
                }
                else;
            else if(event == CS)    Hat2Btn(&dev, CS, CSU, &csStatus);        // throttle HAT
            else;
        else if(&dev == &Joystick)
            if(event == POV) Hat2Btn(&dev, POV, H1U, &h1Status);
            else;
        else if(&dev == &HCougar)
            if(event == T7 | event == T8){ dev[DFM] = !dev[event]; _evh(EV_HID_INPUT_DATA, &dev, DFM); }
            else if(event == T9 | event == T10){ dev[SPDM] = !dev[event]; _evh(EV_HID_INPUT_DATA, &dev, SPDM); }
            else if(event == POV) Hat2Btn(&dev, POV, H1U, &h1cStatus);
            else;
        else if(&dev == &T16000)
            if(event == HAT) Hat2Btn(&dev, HAT, H1U, &h16000Status);
            else;
    }
    
    int Hat2Btn(alias dev, int hat, int e, alias status)
    {
        int i; while(i < 4)                    // 4 virtual keys - release
        {
            dev[e+i] = 1 & h2blookup[(dev[hat]+45)/45] >> i;
            if(!dev[e+i] & status[i]) { _evh(EV_HID_INPUT_DATA, &dev, e+i); status[i] = 0; }
            i = i + 1;
        }
        while(i)                                        // 4 virtual keys - press
        {
            i = i - 1;
            if(dev[e+i] & !status[i]) {_evh(EV_HID_INPUT_DATA, &dev, e+i); status[i] = 1; }
        }
    }
    
    int GetDeviceData(alias dev) // fill global devdata alias based on device name (joy1, joy2,...)
    {
        char t; Dim(&t, 16);
        strname(&dev, &t);
        Map(&devdata, &&devicedata[t[3]-'0']);
    }
    
    define IOTOGGLE        1
    define UDTOGGLE     2
    int SetShiftButton(int devI=0, int indexI=0, int devUMD=0, int indexU=0, int indexD=0, int flag=0)
    { 
        alias io = devI, umd = devUMD;
        layer_sw = 0;
        if(devI) layer_sw[0] = &&io + (indexI << 1);
        layer_sw[1] = flag & 1;
        if(devUMD) layer_sw[3] = &&umd + (indexU << 1);
        layer_sw[4] = flag >> 1;
        if(devUMD) layer_sw[6] = &&umd + (indexD << 1);
        layer_sw[7] = layer_sw[4];
    }
    int MapKey(alias dev, int btnidx, int key=0, int layer=0)
    { 
        if(dev[btnidx]){ dev[btnidx] = 0; _evh(EV_HID_INPUT_DATA, &dev, btnidx); }
        layer = GetLayerBits(layer);
        GetDeviceData(&dev);
        Map(&btnidx, &&devdata.keymap+btnidx*KDATASIZE*4 + 24*!!(layer & 0x40)); Dim(&btnidx, 6);
        int i=6; while(i) 
        {
            i = i-1;
            if(layer & 1) btnidx[i] = key;
            layer = layer >> 1;
        }
    }
    int MapKeyIO(alias dev, int btnidx, int keyI=0, int keyO=0){ MapKeyIOUMD(&dev, btnidx, keyI, keyO, keyI, keyO, keyI, keyO); }
    int MapKeyUMD(alias dev, int btnidx, int keyU=0, int keyM=0, int keyD=0){ MapKeyIOUMD(&dev, btnidx, keyU, keyU, keyM, keyM, keyD, keyD); }
    int MapKeyIOUMD(alias dev, int btnidx, int keyIU=0, int keyOU=0, int keyIM=0, int keyOM=0, int keyID=0, int keyOD=0)
    {
        if(dev[btnidx]){ dev[btnidx] = 0; _evh(EV_HID_INPUT_DATA, &dev, btnidx); }
        GetDeviceData(&dev);
        Map(&btnidx, &&devdata.keymap+btnidx*KDATASIZE*4); Dim(&btnidx, 6);
        btnidx[0] = keyOU;
        btnidx[1] = keyIU;
        btnidx[2] = keyOM;
        btnidx[3] = keyIM;
        btnidx[4] = keyOD;
        btnidx[5] = keyID;
    }
    int MapKeyR(alias dev, int btnidx, int key=0){ MapKeyRIOUMD(&dev, btnidx, key, key, key, key, key, key); }
    int MapKeyRIO(alias dev, int btnidx, int keyI=0, int keyO=0){ MapKeyRIOUMD(&dev, btnidx, keyI, keyO, keyI, keyO, keyI, keyO); }
    int MapKeyRUMD(alias dev, int btnidx, int keyU=0, int keyM=0, int keyD=0){ MapKeyRIOUMD(&dev, btnidx, keyU, keyU, keyM, keyM, keyD, keyD); }
    int MapKeyRIOUMD(alias dev, int btnidx, int keyIU=0, int keyOU=0, int keyIM=0, int keyOM=0, int keyID=0, int keyOD=0)
    {
        GetDeviceData(&dev);
        Map(&btnidx, &&devdata.keymap+btnidx*KDATASIZE*4 + 24); Dim(&btnidx, 7);
        btnidx[0] = PULSE | keyOU;
        btnidx[1] = PULSE | keyIU;
        btnidx[2] = PULSE | keyOM;
        btnidx[3] = PULSE | keyIM;
        btnidx[4] = PULSE | keyOD;
        btnidx[5] = PULSE | keyID;
        btnidx[6] = 0;                            // shift status
    }
    
    int keyalloc[16384], kpos, alloc_locked, tmp[4];
    int SEQ(){ Map(&SEQ, MakeProcInstance(&_SEQ), MAP_IPTR_VPN); }
    int _SEQ(int i, int np, int p){ return ASMAlloc(np, p, &seqproc); }
    int CHAIN(){ Map(&CHAIN, MakeProcInstance(&_CHAIN), MAP_IPTR_VPN); }
    int _CHAIN(int i, int np, int p){ return ASMAlloc(np, p, &chainproc); }
    int D(word ms=0){ if(!ms) ms = kb_delay; return ms | DELAY; }
    int TEMPO(int x, int y, int d = 200){ tmp[0]=x; tmp[1]=y; tmp[2]=d; return ASMAlloc(3, &&tmp, &tempoproc); }
    int AXIS(int x, int d, int ms){ tmp[0]=x; tmp[1]=d; tmp[2]=ms; return ASMAlloc(3, &&tmp, &axisproc); }
    int EXEC(alias cmdon, int cmdoff=0){ tmp[0]=&cmdon; tmp[1]=cmdoff; return ASMAlloc(2, &&tmp, &execproc); }
    int execproc(alias v, int p){ p = v[(p+2 & 0xffff) + !(p&KEYON)]; if(p) execute(p); }
    define RNOSTOP    0
    int REXEC(int h, word t, alias cmdon, int rstop=1){ tmp[0]=h; tmp[1]=t; tmp[2]=&cmdon; tmp[3]=rstop; return ASMAlloc(4, &&tmp, &rexecproc); }
    define LED_ONOFF        0
    define LED_INTENSITY    1
    define LED_CURRENT        0x55555555
    define LED0                0x3
    define LED1                0x30
    define LED2                0x300
    define LED3                0x3000
    define LED4                0x30000
    define LED5                0x300000
    int LED(alias dev, int mode, int led){ tmp[0]=&dev; tmp[1]=mode; tmp[2] = led; return ASMAlloc(3, &&tmp, &ledproc); }
    
    int ASMAlloc(int np, int p, alias proc)
    {
        int v, x;    
    //    if(alloc_locked) return 0 & printf("WARNING: you can declare compound key statements (SEQ, CHAIN, EXEC, TEMPO, AXIS) only inside main() call, and not during an event.\xa");
        v = elements(&keyalloc) - kpos - 3;
        if(v < np | !np) return 0;                        // not enough allocation space or no parameters
        Map(&v, p); Dim(&v, np);                        // v = params array
        keyalloc[kpos] = &proc;                            // function
        keyalloc[kpos+1] = kpos + 1 + np;                // parameters index
        while(x < np)
        {
            keyalloc[kpos+2+x] = v[x];
            x = x+1;
        }
        keyalloc[kpos+2+np] = kpos + 2 | JUMP; 
        x = ASMFind(kpos);
        if(x == kpos) kpos = kpos + np + 3;
        return x | PROC;
    }
    
    int ASMFind(int x)
    {
        int i, j, k; while(i < x)
        {
            k = keyalloc[i+1];
            if(keyalloc[i] == keyalloc[x])
                if(k-i == keyalloc[x+1]-x)
                {
                    j = x-i;
                    i = i+2;
                    while(keyalloc[i] == keyalloc[j+i]) i = i+1;
                    if((keyalloc[i] & 0xffff0000) == JUMP) return x-j;
                }
            i = k+2; 
        }
        return x;
    }
    
    int seqproc(alias v, int p)        // key sequence procedure
    {
        int flag = p & (PULSE | KEYON);    
        p = (p & 0xffff) + 1;                                        // params index
        if(flag & KEYON) 
        {
            v[p] = v[p] + 1;
            if(v[v[p]] & JUMP) v[p] = v[v[p]]  & 0xffff;
        }
        p = v[v[p]] | flag;
        if(p & LOCK) chainlock = !chainlock;
        return ActKey(p);
    }
    
    int chainlock;
    int chaincall(int p){ chainproc(&keyalloc, p); }
    int chainproc(alias v, int p)
    {
        int k, press = p & KEYON;
        p = p + 1;
        do
        {
            p = p + 1;
            k = v[p & 0xffff];
            if(!!(k & LOCK) & !!press) chainlock = !chainlock;
            if(k & DELAY)
                if(chainlock) Sleep(k & 0xffff);
                else return DeferCall(k & 0xffff, &chaincall, p-1 | press);
            else if(k & JUMP) break;                            // end chain
            else ActKey(k | p & PULSE | press);
        } while(1);
        chainlock = 0;
    }
    
    int tempo1(int p){ Map(&p, p); Dim(&p, 3); p[0] = 0; ActKey(p[2] | KEYON); }
    int tempoproc(alias v, int p)
    {
        int i = p+1 & 0xffff;
        v[i+2] = v[i+2] | (p & PULSE);
        if(p & KEYON) { v[i] = 1 | PostEvent(EV_USR+100+i, &tempo1, &&v[i], v[i+3]); }
        else 
        {
            RemoveEvent(EV_USR+100+i);
            if(v[i]) ActKey(v[i+1] | KEYON | PULSE);
            else ActKey(v[i+2]);
        }
    }
    
    int rexecproc(alias v, int p)
    { 
        int i = p+2 & 0xffff; 
        if(p & KEYON) AutoRepeat(v[i], v[i+1], &execute, v[i+2]); 
        else if(v[i+3]) StopAutoRepeat(v[i]);
    }
    
    int axis1(int p){ Map(&p, p); Dim(&p, 2); DXAxis(p[0], clip(Axis[p[0]].pos + p[1], -AMAX, AMAX)); }
    int axisproc(alias v, int p)
    {
        int i = p+2 & 0xffff;
        StopAutoRepeat(v[i]+32768+8);
        if(p & KEYON) AutoRepeat(v[i]+32768+8, v[i+2], &axis1, &&v[i]);
    }
    
    char ledcmd[16]={3,3,3,2,3,0,1,0,3,3,3,3,3,1,3,3};
    int ledproc(alias v, int p)
    {
        int k, j, i = p+2 & 0xffff;
        if(p & KEYON)
            if(v[i+1] == LED_INTENSITY) GameOutput(v[i], OUT_ID_LED_INTENSITY, v[i+2]);
            else if(v[i+1] == LED_ONOFF)
            {
                k = v[i+2] & 0xffffff ^ 0x555555; while(k)
                {
                    p = ledcmd[k & 0xf];
                    if(p < 3) GameOutput(v[i], OUT_ID_LED_BACKLIGHT+j, p);
                    k = k >> 4;
                    j = j+1;
                }
            }
    }
    
    int X(int list, int x)
    {
        if(!(list & PROC)) return 0;
        list = list+1 & 0xffff;
        int n = keyalloc
    [list] - list;
        if(x < 0) return n;        // returns elements number
        if(x >= n) return 0;
        return keyalloc
    [list+x+1];
    }
    
    //x=-1..1, lower=0..1, center=0..1, upper=0..1, trim=-1..1, curve=-32..32
    float fcurve(float x, float lower, float center, float upper, float trim, int curve)
    {
        float m, M, cM, cm;
        m = lower+lower - 1;
        M = 1 - upper-upper;
        cM = center;
        cm = -cM;
        if(x < m) x = -1;
        else if(x < cm) 
            if(!curve) x = (x-cm)/(cm-m);
            else x = (1 - exp((cm-x)*curve))/(exp((cm-m)*curve) - 1);
         else if(x < cM) x = 0;
         else if(x < M)
            if(abs(curve) < 0.01) x = (x-cM)/(M-cM);
            else x =(exp((x-cM)*curve) - 1)/(exp((M-cM)*curve) - 1); 
        else x = 1;
        x = x + trim;
         if(x < -1) x = -1;
        else if(x > 1) x = 1;
        return x;
    }
    float P2Curve(float x, float a, float b, float c){ return a*x*x + b*x + c; }
    
    float LI(float x, float y, float X, float Y, float v) { return ((Y-y)*v + X*y - x*Y) / (X-x); } // linear interpolate
    
    int clip(int i, int down, int up)
    {
        if(i<down) return down;
        else if(i>up) return up;
        else return i;
    }
    
    int hatstatus, hatlkup[16]={POVCENTER, POVU, POVR, POVUR, POVD, POVCENTER, POVDR, POVCENTER, POVL, POVUL, POVCENTER, POVCENTER, POVDL, POVCENTER, POVCENTER, POVCENTER};
    int HatUp(int p){ hatstatus = hatstatus & (p ^ 0xffffffff); VirtualOutput(OUT_TYPE_GAME, OUT_ID_HAT, hatlkup[hatstatus]); }
    int _key(int c, int mode, int delay=0)
    {
        if(c >= MOUSE_LEFT) VirtualOutput(OUT_TYPE_MOUSE, c-MOUSE_LEFT, mode, delay);
        else if(c >= DX1) // DX key
            if(c < DXHATUP) VirtualOutput(OUT_TYPE_GAME, c-DX1, mode, delay);
            else 
            {    
                c = h2blookup[c-DXHATUP+1];
                if(mode) hatstatus = hatstatus | c;
                else hatstatus = hatstatus & (c ^ 0xffffffff);
                VirtualOutput(OUT_TYPE_GAME, OUT_ID_HAT, hatlkup[hatstatus]);
                if(mode == OUT_VALUE_BUTTON_PRESS_RELEASE) DeferCall(delay, &HatUp, c);
            }
        else if(c)
        {
            if(c<256) return _key(ASC[c], mode, delay);
            if(mode != OUT_VALUE_BUTTON_RELEASE) 
                if(c > 2500) _key(RALT, mode, delay+1);
                else if(c > 2000) _key(SHF, mode, delay+1);
            VirtualOutput(OUT_TYPE_KEYBOARD, c%500, mode, delay);
            if(mode == OUT_VALUE_BUTTON_RELEASE) 
                if(c > 2500) _key(RALT, OUT_VALUE_BUTTON_RELEASE);
                else if(c > 2000) _key(SHF, OUT_VALUE_BUTTON_RELEASE);
        }
    }
    
    // ------------------------------------------- Axis functions -----------------------------
    struct DXAxisStatus
    {
        int pos, trim;
        char coupling;
        char lock;
        float cos, sin;
    }
    DXAxisStatus Axis[12]; 
    
    int DXAxis(int index, int value)
    {
        if(index < DX_X_AXIS | index > MOUSE_Z_AXIS) return 0;
        if(index == MOUSE_Z_AXIS) return DXSetAxis(index, value); // MOUSE_Z_AXIS is relative
        Axis[index].pos = value;
        value = Axis[index].coupling;
        if(value)
        {
            DXSetAxis(index,  Axis[index].pos*Axis[index].cos + Axis[value].pos*Axis[index].sin + Axis[index].trim);
            DXSetAxis(value, -Axis[index].pos*Axis[index].sin + Axis[value].pos*Axis[index].cos + Axis[value].trim);
        }
        else DXSetAxis(index, Axis[index].pos + Axis[index].trim);
    }
    
    int DXSetAxis(int index, int value)
    {    
        value = clip(value, -AMAX, AMAX);
        if(!Axis[index].lock)
            if(index < MOUSE_X_AXIS) DX(index-1+OUT_ID_AXIS, value);
            else VirtualOutput(OUT_TYPE_MOUSE, index-MOUSE_X_AXIS+OUT_ID_AXIS, value);
    }
    
    int RotateDXAxis(int XAxis, int YAxis, float angle) // clockwise angle, in degrees
    {
        angle = angle * 3.1415926 / 180;
        Axis[XAxis].coupling = YAxis;
        Axis[XAxis].cos = cos(angle);
        Axis[XAxis].sin = -sin(angle);
        Axis[YAxis].coupling = XAxis;
        Axis[YAxis].cos = cos(angle);
        Axis[YAxis].sin = sin(angle);
    }
    
    define CURRENT    0x20000
    int SET(int i){ return i & 0xffff | 0x10000; }
    int TrimDXAxis(int index, int value) // 1024 values
    {
        short t = value;
        if(abs(value) < 0x3ff) Axis[index].trim = Axis[index].trim + (t << 5);
        else if(value > 0)
            if(value & 0x10000) Axis[index].trim = t << 5;
            else if(value & CURRENT) Axis[index].trim = Axis[index].pos + Axis[index].trim;
        Axis[index].trim = clip(Axis[index].trim, -AMAX, AMAX);
        DXAxis(index, Axis[index].pos);
    }
    
    int LockDXAxis(int index, char lock)
    { 
        Axis[index].lock = lock; 
        if(!lock) DXAxis(index, Axis[index].pos);
    }
    
    int GetAxisData(alias o, int x) // maps the global <axdata>
    {
        if(x >= IN_POSITION_AXES & x < IN_POSITION_HAT)
        {
            GetDeviceData(&o);
            Map(&axdata, &&devdata.axmap + (x-IN_POSITION_AXES)*AXDATASIZE);
            return 1;
        }
    }
    
    int MapAxis(alias o, int x, int dx=0, int dir=AXIS_NORMAL, int relative=MAP_ABSOLUTE)
    { 
        if(!GetAxisData(&o, x)) return 0;
        if(!!axdata.dxmap & axdata.relative) StopAutoRepeat(32767+axdata.dxmap);
        axdata.dxmap = dx; 
        axdata.dir = dir - 1;
        axdata.relative = relative;
    //    axdata.relpos = 0;
        if(!!dx & relative) AutoRepeat(32767+dx, 20, &RJLoop, &&axdata);
    }
    
    int SetSCurve(alias o, int x, int lower=0, int center=0, int upper=0, int curve=0, float zoom=0) // all percents, curve = -32..32
    {
        if(!GetAxisData(&o, x)) return 0;
        axdata.curvemode = 1;
        axdata.lower = lower;
        axdata.center = center;
        axdata.upper = upper;
        axdata.curve = curve;
        axdata.ab = zoom;
        axdata.val = AxisVal(o[x], &axdata);
    }
    
    int SetJCurve(alias o, int x, float in, float out) // in, out = percents
    {
        if(!GetAxisData(&o, x)) return 0;
        axdata.curvemode = 2;
        axdata.ab = 50*(in - out) / (in*(in - 100));
        axdata.val = AxisVal(o[x], &axdata);
    }
    
    int SetCustomCurve(alias o, int x, int list)
    {
        if(!GetAxisData(&o, x)) return 0;
        if(list & PROC) axdata.curvemode = list;
        else axdata.curvemode = 0;
        axdata.val = AxisVal(o[x], &axdata);
    }
    
    float GetCustomCurveValue(int p, float v)
    {
        p = p + 1 & 0xffff;
        int n = keyalloc[p];    // list end
        int i = p+1;
        if(i>=n) return v;
        while(i<n)
            if(keyalloc[i] < v) i=i+2;
            else if(i == p+1) return LI(0, 0, keyalloc[i], keyalloc[i+1], v);
            else return LI(keyalloc[i-2], keyalloc[i-1], keyalloc[i], keyalloc[i+1], v);
        return LI(keyalloc[i-2], keyalloc[i-1], 100, 100, v);
    }
    
    int LockAxis(alias o, int x, int lock){ if(GetAxisData(&o, x)) axdata.locked = lock; }
    
    int AxisVal(int v, alias d)
    {
        if(d.curvemode == 0);        // no curve, keeps v unchanged
        else if(d.curvemode == 1) v = AMAX*pow(1.41, d.ab)*fcurve(v/AMAXF, d.lower*0.01, d.center*0.01, d.upper*0.01, 0, d.curve);  
        else if(d.curvemode == 2) v = AMAX*P2Curve(v/AMAXF, -d.ab, 1, d.ab);
        else v = AMAX*GetCustomCurveValue(d.curvemode, v*50/AMAXF + 50)/50 - AMAX;     // custom curve
        return v*(1 + axdata.dir);
    }
    
    int RJLoop(int p)
    {
        Map(&axdata, p);
        p = axdata.val * !axdata.locked;
        axdata.relpos = clip(axdata.relpos + p, -AMAX*10, AMAX*10);
        if(p) DXAxis(axdata.dxmap, axdata.relpos/10);
    }
    
    char gllk[32] = {0x3f, 3, 0xc, 0xf, 0x30, 0x33, 0x3c, 0x3f, 0x2a, 2, 8, 0xa, 0x20, 0x22, 0x28, 0x2a, 0x15, 1, 4, 5, 0x10, 0x11, 0x14, 0x15, 0x3f, 3, 0xc, 0xf, 0x30, 0x33, 0x3c, 0x3f};
    int GetLayerBits(int layer) // layer is a word constant, containing i,o,u,m,d, like 'i', or 'iu'
    {
        layer = layer & 0x7fffffff;
        char c, mask = 0;
        do
        {    
            c = layer & 0xff;
            mask = mask | (1 << strchr("dmuoir", c));
            layer = layer >> 8;
        } 
        while(layer);
        return gllk[mask & 0x1f] | ((mask & 0x20) << 1);    
    }
    
    int KeyAxis(alias o, int x, int layer, int mode)
    {
        if(!GetAxisData(&o, x)) return 0;
        layer = GetLayerBits(layer) & 0x3f;        // ignore 'r' bit
        Map(&x, &&axdata.key + 20);
        while(layer)
        {
            if(layer & 1) x = mode;
            layer = layer >> 1;
            Map(&x, &&x-4);
        }
    }
    
    int AXMAP1(int n, int u, int d, int c=-1){ Dim(&n, 4); n[1]=u; n[2]=d; n[3]=c; return ASMAlloc(4, &&n, &axmap1proc); }
    int axmap1proc(alias v, int p, int x)
    {
        Map(&p, &&v[p + 1 & 0xffff]); Dim(&p, 5);
        int n = p[1], center=p[4]>=0;
        if(n & PROC) 
        {
            n = n + 1 & 0xffff;
            n = v[n] - n - 1;    // list size - 1
            center = center & n;
            x = GetListPos(&v, p[1], (x+AMAX)*100 / (AMAX+AMAX+1)) - 1;
        }
        else 
        {
            center = center & (n + 1);
            n = n + center;
            x = ((x + AMAX)*(n + 1) + AMAX) / (AMAX+AMAX+1) - 1;
        }
        int y = -p[0] >> 1;    // last position
        int up = p[0] & 1;
        if(center) center = n >> 1;
        else center = -1;
        while(y != x) 
        {
            if(y>=0 & y<n)
                if(y==center) ActKey(p[4]); 
                else ActKey(p[3-up]);
            if(x < -1) break;
            up = y < x;
            if(y < -1) y = x;        
            else y = y + (up << 1) - 1;
            if(y>=0 & y<n)
                if(y==center) ActKey(p[4] | KEYON); 
                else ActKey(p[3-up] | KEYON); 
        }
        p[0] = -((x << 1) + up);
    }
    
    define LIST AXMAP2
    int AXMAP2(){ Map(&AXMAP2, MakeProcInstance(&_AXMAP2), MAP_IPTR_VPN); }
    int _AXMAP2(int i, int np, int p){ return ASMAlloc(np, p, &axmap2proc); }
    int axmap2proc(alias v, int p, int x)
    {
        int i = p + 1 & 0xffff;
        Map(&p, &&v[i]); Dim(&p, v[i+1]+2);
        if(p[1] & PROC) x = GetListPos(&v, p[1], (x+AMAX)*100 / (AMAX+AMAX+1)) - 1;
        else x = (x + AMAX) * p[1] / (AMAX+AMAX+1);
        int y = -v[p[0]+1];
        while(y != x)
        {
            if(y>=0 & 1+y<p[0]-i) ActKey(p[2+y]);
            if(x < -1) break;
            if(y < -1) y = x;
            else y = y + ((y<x) << 1) - 1;
            if(y>=0 & 1+y<p[0]-i) ActKey(p[2+y] | KEYON);
        }
        v[p[0]+1] = -x;
    }
    
    int GetListPos(alias v, int p, short x)
    {
        p = (p & 0xffff) + 2;
        if(x < 0) return -1;
        int pos; while(v[p+pos] <= x) pos = pos+1;
        return pos;
    }
    
    // ------------------------------------------- Default button mapping  -----------------------------
    int JoystickMap[]={TG1,DX1, S2,DX2, S3,DX3, S4,DX4, S1,DX5, TG2,DX6, H2U,DX7, H2R,DX8, H2D,DX9, H2L,DX10, H3U,DX11, H3R,DX12, H3D,DX13, H3L,DX14,
                       H4U,DX15, H4R,DX16, H4D,DX17, H4L,DX18, H4P,DX19, H1U,DXHATUP, H1R,DXHATRIGHT, H1D,DXHATDOWN, H1L,DXHATLEFT};
    int ThrottleMap[]={LTB,DX20, SC,DX21, CSU,DX22, CSR,DX23, CSD,DX24, CSL,DX25, MSP,DX26, MSU,DX27, MSR,DX28, MSD,DX29, MSL,DX30, SPDF,DX31, SPDB,DX32};
    int HCougarMap[] ={T1,DX19, T3,DX20, T2,DX21, T4,DX22, T5,DX23, T6,DX24, T7,DX25, T8,DX26, T9,DX27, T10,DX28};
    int MFDMap[]     ={OSB01,DX1, OSB02,DX2, OSB03,DX3, OSB04,DX4, OSB05,DX5, OSB06,DX6, OSB07,DX7, OSB08,DX8, OSB09,DX9, OSB10,DX10, OSB11,DX11, OSB12,DX12,
                       OSB13,DX13, OSB14,DX14, OSB15,DX15, OSB16,DX16, OSB17,DX17, OSB18,DX18, OSB19,DX19, OSB20,DX20, SYMU,DX21, SYMD,DX22, CONU,DX23,
                       COND,DX24, BRTU,DX25, BRTD,DX26, GAINU,DX27, GAIND,DX28};
    int T16000Map[]     ={TS1,DX1, TS2,DX2, TS3,DX3, TS4,DX4, B5,DX5, B6,DX6, B7,DX7, B8,DX8, B9,DX9, B10,DX10, B11,DX11, B12,DX12, B13,DX13, B14,DX14, B15,DX15,
                       B16,DX16};
    
    int MapList(alias dev, alias list)
    {
        int i, e = elements(&list); while(i<e)
        {
            MapKey(&dev, list[i], list[i+1]);
            i = i+2;
        }
    }

    The comment behind some lines suggest it's ok for people to tinker with the code. Just be carefull with it when you do, it says on several places.

    I already changed HAT (at the stGameCfg virtualj part) from 1 to 2 in both Hid.tmh, and target.tmh, in the hope I got my second POV HAT activated in the software. But alas...there seems to be more to it then just adjusting these two values... And I clearly lack skills here...

  4. #4
    Registered User
    Join Date
    Mar 2014
    Posts
    5
    I got a tingling feeling I should have posted this in the C-stuff chapter instead of at the gaming part...
    Should it be relocated?

  5. #5
    Registered User
    Join Date
    Apr 2014
    Posts
    1

    Two hats on two T16000

    Quote Originally Posted by SeaBreak View Post
    I got a tingling feeling I should have posted this in the C-stuff chapter instead of at the gaming part...
    Should it be relocated?
    (Sorry in advance, I don't know how to embed code here)

    It's a kludge, but I got two hats (sort of) recognized.

    Because we use the &T16001 alias, the hat switch checker on line 258 of target.tmh misses the second hat's call.

    It should be set to
    else if(&dev == &T16000 | &dev == &T16001)

    from

    else if(&dev == &T16000)


    Now, Direct X only recognizes a single hat, so what I had to do was map the second hat to keys.

    so in your script_name.tmc file, you need to do something like this

    MapKey(&T16000, H1U,DXHATUP);
    MapKey(&T16000, H1R,DXHATRIGHT);
    MapKey(&T16000, H1D,DXHATDOWN);
    MapKey(&T16000, H1L,DXHATLEFT);

    MapKey(&T16001, H1U,UARROW);
    MapKey(&T16001, H1R,RARROW);
    MapKey(&T16001, H1D,DARROW);
    MapKey(&T16001, H1L,LARROW);


    You should be able to sort it out from here.

    Cheers

  6. #6
    Registered User
    Join Date
    Mar 2014
    Posts
    5
    Quote Originally Posted by KrakkenSmacken View Post
    (Sorry in advance, I don't know how to embed code here)
    Now, Direct X only recognizes a single hat, so what I had to do was map the second hat to keys.
    I was wondering about that....Does this also apply if one has three or more Thrustmaster stuff USBed?
    HOTAS and flightsticks also have hats, right? Only one of them all goes in Direct X?

    I thought TARGET was flexible about using different stuff with it?

    They (Thrustmaster) got weird logic anyway, lol...
    Make ambidex joysticks, but make it hard in their software to use two of them?? Whatthe...?? It...just....makes...no... sense! And when people ask them about it...no updates in their software, manuals or not even replying to help out?? Now there's customer' faced for yah...

    But if you're their underground customer service...nothing but thumbsup for you . You solved a major puzzelpiece.
    You went code...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-11-2012, 02:03 AM
  2. Replies: 4
    Last Post: 12-11-2011, 04:25 PM
  3. small programming job VCPP / Object Oriented Programming
    By calgonite in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 01-04-2006, 11:48 PM
  4. Total newb to programming here... Question about the many programming languages. Ty!
    By tsubotakid1 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 10-05-2003, 11:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21