Index: tools/kbdtool/data.c
===================================================================
--- tools/kbdtool/data.c	(revision 66876)
+++ tools/kbdtool/data.c	(working copy)
@@ -13,44 +13,152 @@
 /* GLOBALS ********************************************************************/
 
 /* Table of Virtual Key Names */
-VKNAME VKName[] =
+VKNAME VKName[MAX_VKKEY_NAMES] =
 {
-    {0x08, "BACK"},
-    {0x03, "CANCEL"},
-    {0x1b, "ESCAPE"},
-    {0x0d, "RETURN"},
-    {0x20, "SPACE"},
-    {0x6e, "DECIMAL"},
-    {0xba, "OEM_1"},
-    {0xbb, "OEM_PLUS"},
-    {0xbc, "OEM_COMMA"},
-    {0xbd, "OEM_MINUS"},
-    {0xbe, "OEM_PERIOD"},
-    {0xbf, "OEM_2"},
-    {0xc0, "OEM_3"},
-    {0xdb, "OEM_4"},
-    {0xdc, "OEM_5"},
-    {0xdd, "OEM_6"},
-    {0xde, "OEM_7"},
-    {0xdf, "OEM_8"},
-    {0xe2, "OEM_102"},
-    {0xc1, "ABNT_C1"},
-    {0xc2, "ABNT_C2"},
-    {0x10, "SHIFT"},
-    {0xa0, "LSHIFT"},
-    {0xa1, "RSHIFT"},
-    {0x12, "MENU"},
-    {0xa4, "LMENU"},
-    {0xa5, "RMENU"},
-    {0x11, "CONTROL"},
-    {0xa2, "LCONTROL"},
-    {0xa3, "RCONTROL"},
-    {0x6c, "SEPARATOR"},
-    {0xe4, "ICO_00"},
-    {0x2e, "DELETE"},
-    {0x2d, "INSERT"},
-    {0xe5, "GROUPSHIFT"},
-    {0xe6, "RGROUPSHIFT"}
+    { 0x01, "LBUTTON"},
+    { 0x02, "RBUTTON"},
+    { 0x03, "CANCEL"},
+    { 0x04, "MBUTTON"},
+    { 0x05, "XBUTTON1"},
+    { 0x06, "XBUTTON2"},
+    { 0x08, "BACK"},
+    { 0x09, "TAB"},
+    { 0x0C, "CLEAR"},
+    { 0x0D, "RETURN"},
+    { 0x10, "SHIFT"},
+    { 0x11, "CONTROL"},
+    { 0x12, "MENU"},
+    { 0x13, "PAUSE"},
+    { 0x14, "CAPITAL"},
+    { 0x15, "KANA"},
+    { 0x15, "HANGUEL"},
+    { 0x15, "HANGUL"},
+    { 0x17, "JUNJA"},
+    { 0x18, "FINAL"},
+    { 0x19, "HANJA"},
+    { 0x19, "KANJI"},
+    { 0x1B, "ESCAPE"},
+    { 0x1C, "CONVERT"},
+    { 0x1D, "NONCONVERT"},
+    { 0x1E, "ACCEPT"},
+    { 0x1F, "MODECHANGE"},
+    { 0x20, "SPACE"},
+    { 0x21, "PRIOR"},
+    { 0x22, "NEXT"},
+    { 0x23, "END"},
+    { 0x24, "HOME"},
+    { 0x25, "LEFT"},
+    { 0x26, "UP"},
+    { 0x27, "RIGHT"},
+    { 0x28, "DOWN"},
+    { 0x29, "SELECT"},
+    { 0x2A, "PRINT"},
+    { 0x2B, "EXECUTE"},
+    { 0x2C, "SNAPSHOT"},
+    { 0x2D, "INSERT"},
+    { 0x2E, "DELETE"},
+    { 0x2F, "HELP"},
+    { 0x5B, "LWIN"},
+    { 0x5C, "RWIN"},
+    { 0x5D, "APPS"},
+    { 0x5F, "SLEEP"},
+    { 0x60, "NUMPAD0"},
+    { 0x61, "NUMPAD1"},
+    { 0x62, "NUMPAD2"},
+    { 0x63, "NUMPAD3"},
+    { 0x64, "NUMPAD4"},
+    { 0x65, "NUMPAD5"},
+    { 0x66, "NUMPAD6"},
+    { 0x67, "NUMPAD7"},
+    { 0x68, "NUMPAD8"},
+    { 0x69, "NUMPAD9"},
+    { 0x6A, "MULTIPLY"},
+    { 0x6B, "ADD"},
+    { 0x6C, "SEPARATOR"},
+    { 0x6D, "SUBTRACT"},
+    { 0x6E, "DECIMAL"},
+    { 0x6F, "DIVIDE"},
+    { 0x70, "F1"},
+    { 0x71, "F2"},
+    { 0x72, "F3"},
+    { 0x73, "F4"},
+    { 0x74, "F5"},
+    { 0x75, "F6"},
+    { 0x76, "F7"},
+    { 0x77, "F8"},
+    { 0x78, "F9"},
+    { 0x79, "F10"},
+    { 0x7A, "F11"},
+    { 0x7B, "F12"},
+    { 0x7C, "F13"},
+    { 0x7D, "F14"},
+    { 0x7E, "F15"},
+    { 0x7F, "F16"},
+    { 0x80, "F17"},
+    { 0x81, "F18"},
+    { 0x82, "F19"},
+    { 0x83, "F20"},
+    { 0x84, "F21"},
+    { 0x85, "F22"},
+    { 0x86, "F23"},
+    { 0x87, "F24"},
+    { 0x90, "NUMLOCK"},
+    { 0x91, "SCROLL"},
+    { 0x90, "NUMLOCK"},
+    { 0x91, "SCROLL"},
+    { 0xA0, "LSHIFT"},
+    { 0xA1, "RSHIFT"},
+    { 0xA2, "LCONTROL"},
+    { 0xA3, "RCONTROL"},
+    { 0xA4, "LMENU"},
+    { 0xA5, "RMENU"},
+    { 0xA6, "BROWSER_BACK"},
+    { 0xA7, "BROWSER_FORWARD"},
+    { 0xA8, "BROWSER_REFRESH"},
+    { 0xA9, "BROWSER_STOP"},
+    { 0xAA, "BROWSER_SEARCH"},
+    { 0xAB, "BROWSER_FAVORITES"},
+    { 0xAC, "BROWSER_HOME"},
+    { 0xAD, "VOLUME_MUTE"},
+    { 0xAE, "VOLUME_DOWN"},
+    { 0xAF, "VOLUME_UP"},
+    { 0xB0, "MEDIA_NEXT_TRACK"},
+    { 0xB1, "MEDIA_PREV_TRACK"},
+    { 0xB2, "MEDIA_STOP"},
+    { 0xB3, "MEDIA_PLAY_PAUSE"},
+    { 0xB4, "LAUNCH_MAIL"},
+    { 0xB5, "LAUNCH_MEDIA_SELECT"},
+    { 0xB6, "LAUNCH_APP1"},
+    { 0xB7, "LAUNCH_APP2"},
+    { 0xBA, "OEM_1"},
+    { 0xBB, "OEM_PLUS"},
+    { 0xBC, "OEM_COMMA"},
+    { 0xBD, "OEM_MINUS"},
+    { 0xBE, "OEM_PERIOD"},
+    { 0xBF, "OEM_2"},
+    { 0xC0, "OEM_3"},
+    { 0xc1, "ABNT_C1"},
+    { 0xc2, "ABNT_C2"},
+    { 0xDB, "OEM_4"},
+    { 0xDC, "OEM_5"},
+    { 0xDD, "OEM_6"},
+    { 0xDE, "OEM_7"},
+    { 0xDF, "OEM_8"},
+    { 0xE2, "OEM_102"},
+    { 0xE5, "PROCESSKEY"},
+    { 0xE7, "PACKET"},
+    { 0xF6, "ATTN"},
+    { 0xF7, "CRSEL"},
+    { 0xF8, "EXSEL"},
+    { 0xF9, "EREOF"},
+    { 0xFA, "PLAY"},
+    { 0xFB, "ZOOM"},
+    { 0xFC, "NONAME"},
+    { 0xFD, "PA1"},
+    { 0xFE, "OEM_CLEAR"},
+    { 0xEB, "OEM_PA1"},
+    { 0xEC, "OEM_PA2"},
+    { 0xED, "OEM_PA3"},
 };
 /* Table of modifiers */
 VKNAME Modifiers[] =
@@ -57,9 +165,18 @@
 {
     {0x10, "KBDSHIFT"},
     {0x11, "KBDCTRL"},
-    {0x12, "KBDALT"}
+    {0x12, "KBDALT"},
+    {0, NULL}
 };
 
+PCHAR Attributes[MAX_ATTRIBUTES] =
+{
+    "0",
+    "KLLF_ALTGR",
+    "KLLF_SHIFTLOCK",
+    "KLLF_LRM_RLM"
+};
+
 /* Table of states */
 PCHAR StateLabel[] =
 {
@@ -258,6 +375,142 @@
     {0xFFFF, 0x00, NULL, FALSE}
 };
 
+
+INT ReactosOrderTable[MAX_ORDER_TABLE] =
+{
+    0x31, //    1
+    0x32, //    2
+    0x33, //    3
+    0x34, //    4
+    0x35, //    5
+    0x36, //    6
+    0x37, //    7
+    0x38, //    8
+    0x39, //    9
+    0x30, //    0
+    0x41, //    A
+    0x42, //    B
+    0x43, //    C
+    0x44, //    D
+    0x45, //    E
+    0x46, //    F
+    0x47, //    G
+    0x48, //    H
+    0x49, //    I
+    0x4A, //    J
+    0x4B, //    K
+    0x4C, //    L
+    0x4D, //    M
+    0x4E, //    N
+    0x4F, //    O
+    0x50, //    P
+    0x51, //    Q
+    0x52, //    R
+    0x53, //    S
+    0x54, //    T
+    0x55, //    U
+    0x56, //    V
+    0x57, //    W
+    0x58, //    X
+    0x59, //    Y
+    0x5A, //    Z
+    0xBE, //    OEM_PERIOD
+    0xBB, //    OEM_PLUS
+    0xBA, //    OEM_1
+    0xE2, //    OEM_102
+    0xBF, //    OEM_2
+    0xC0, //    OEM_3
+    0xDB, //    OEM_4
+    0xDC, //    OEM_5
+    0xDD, //    OEM_6
+    0xDE, //    OEM_7
+    0xDF, //    OEM_8
+};
+
+PCHAR ScancodeTable[0x080] =
+{
+    /* 00 01 */
+    "VK_EMPTY", "VK_ESCAPE",
+    /* First Row*/
+    /*  02    03     04   05  06
+        07    08     09   0A  0B
+        0C(-) 0D(+)  0E   */
+    "VK_EMPTY", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY",
+    "VK_EMPTY", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY",
+    "VK_EMPTY", "VK_EMPTY", "VK_EMPTY",
+    /*  Second Row */
+    /*  0F    10    11    12   13
+        14    15    16    17   18
+        19    1A([) 1B(]) */
+    "VK_TAB"  , "VK_EMPTY", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY",
+    "VK_EMPTY", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY",
+    "VK_EMPTY", "VK_EMPTY", "VK_EMPTY",
+    /*  1C         1D          */
+    "VK_RETURN", "VK_LCONTROL",
+    /*  Third Row */
+    /*  1E    1F    20    21    22
+        23    24    25    26    27(:)
+        28(') 29(~)*/
+    "VK_EMPTY", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY",
+    "VK_EMPTY", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY",
+    "VK_EMPTY", "VK_EMPTY",
+    /*  Fourth row */
+    /*  2A    2B(\) 2C    2D   2E
+        2F    30    31    32   33(,)
+        32(.) 35(?)  36  */
+
+    "VK_LSHIFT", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY",
+    "VK_EMPTY",  "VK_EMPTY", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY",
+    "VK_EMPTY",  "VK_EMPTY", "VK_RSHIFT",
+    /*  Bottom Row */
+    /*  37 (Keypad*) 38(L_ALT) 39        3A CapsLock */
+    "VK_MULTIPLY", "VK_LMENU", "VK_EMPTY", "VK_CAPITAL",
+    /*  Top Row */
+    /*  3B     3C     3D     3E     3F
+        40     41     42     43     44     */
+    "VK_F1", "VK_F2", "VK_F3", "VK_F4", "VK_F5",
+    "VK_F6", "VK_F7", "VK_F8", "VK_F9", "VK_F10",
+    /*  Locks */
+    /*  45                  46 */
+    "VK_NUMLOCK | KMEXT", "VK_SCROLL | KBDMULTIVK",
+    /*  Number Pad */
+    /*  47 (KeyPad 7)    48(KeyPad 8)   49 (KeyPad 9)     4A (KeyPad -)  */
+    "VK_HOME | KNUMS", "VK_UP | KNUMS", "VK_PRIOR | KNUMS", "VK_SUBTRACT",
+    /*  4B (KeyPad 4)    4C (KeyPad 5)     4D (KeyPad 6)     4E (KeyPad +)  */
+    "VK_LEFT | KNUMS", "VK_CLEAR | KNUMS", "VK_RIGHT | KNUMS", "VK_ADD",
+    /*  4F (KeyPad 1)   50(KeyPad 2)     51 (KeyPad 3) */
+    "VK_END | KNUMS", "VK_DOWN | KNUMS", "VK_NEXT | KNUMS",
+    /*  52 (KeyPad 0)      53(KeyPad .) */
+    "VK_INSERT | KNUMS", "VK_DELETE | KNUMS",
+    /*  54 (Print Screen)  */
+    "VK_SNAPSHOT",
+    /*  Oddities, and the remaining standard F-Keys */
+    /*  55 (OEM?) 56 (OEM?)   57      58   */
+    "VK_EMPTY", "VK_EMPTY", "VK_F11", "VK_F12",
+    /*  Keyboard Vendor Specific */
+    /*  59    5A    5B    5C   5D
+        5E    5F    60    61   62  */
+    "VK_CLEAR", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY",
+    "VK_EMPTY", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY",
+    /*  Even more F-Keys (for example, NCR keyboards from the early 90's) */
+    /*  63    64    65    66   67
+        68    69    6A    6B   6C
+        6D    6E  */
+    "VK_HELP", "VK_F13", "VK_F14", "VK_F15", "VK_F16",
+    "VK_F17",  "VK_F18", "VK_F19", "VK_F20", "VK_F21",
+    "VK_F22",  "VK_F23",
+    /*  More Keyboard Vendor Specific */
+    /*  6F    70    71    72   73
+        74    75    76   */
+    "VK_EMPTY", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY",
+    "VK_EMPTY", "VK_EMPTY", "VK_F24",
+    /*  77    78    79    7A   7B
+        7C    7D    7E    7F   */
+    "VK_EMPTY", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY",
+    "VK_EMPTY", "VK_EMPTY", "VK_EMPTY", "VK_EMPTY"
+};
+
+
 /* FUNCTIONS ******************************************************************/
 
 /* EOF */
Index: tools/kbdtool/kbdtool.h
===================================================================
--- tools/kbdtool/kbdtool.h	(revision 66876)
+++ tools/kbdtool/kbdtool.h	(working copy)
@@ -23,6 +23,10 @@
 #define CHAR_INVALID_KEY  3
 #define CHAR_LIGATURE_KEY 4
 
+#define MAX_VKKEY_NAMES 144
+#define MAX_ORDER_TABLE 47
+#define MAX_ATTRIBUTES 4
+
 typedef struct tagKEYNAME
 {
     ULONG Code;
@@ -72,11 +76,31 @@
     IN BOOLEAN Prefix
 );
 
-extern BOOLEAN Verbose, UnicodeFile, SanityCheck, FallbackDriver;
+typedef struct tagDEADKEY
+{
+    ULONG Key;
+    ULONG Source;
+    ULONG Target;
+    struct tagDEADKEY* Next;
+} DEADKEY, *PDEADKEY;
+
+typedef struct tagLIGATURE
+{
+    ULONG Key;
+    INT Modifier;
+    ULONG Characters[10];
+    INT CharCount;
+    struct tagLIGATURE* Next;
+} LIGATURE, *PLIGATURE;
+
+
+extern BOOLEAN Verbose, UnicodeFile, SanityCheck, FallbackDriver, ReactosOrder;
 extern PCHAR gpszFileName;
+extern CHAR BaseFileName[FILENAME_MAX];
 extern FILE* gfpInput;
 extern VKNAME VKName[];
 extern VKNAME Modifiers[];
+extern PCHAR Attributes[];
 extern SCVK ScVk[];
 extern PCHAR StateLabel[];
 extern PCHAR CapState[];
@@ -87,6 +111,8 @@
 extern CHAR gDescription[256];
 extern CHAR gCompany[256];
 extern CHAR gLocaleName[256];
+extern INT ReactosOrderTable[MAX_ORDER_TABLE];
 extern ULONG gVersion, gSubVersion;
+extern PCHAR ScancodeTable[0x080];
 
 /* EOF */
Index: tools/kbdtool/main.c
===================================================================
--- tools/kbdtool/main.c	(revision 66876)
+++ tools/kbdtool/main.c	(working copy)
@@ -14,18 +14,38 @@
 
 /* Internal tool data */
 ULONG gVersion = 3;
-ULONG gSubVersion = 40;
+ULONG gSubVersion = 50;
 
 /* Input file */
 PCHAR gpszFileName;
 FILE* gfpInput;
+/* Base file: no path or extension */
+CHAR BaseFileName[FILENAME_MAX];
 
 /* Command-line parameters */
-BOOLEAN UnicodeFile, Verbose, NoLogo, FallbackDriver, SanityCheck, SourceOnly;
+BOOLEAN UnicodeFile, Verbose, NoLogo, FallbackDriver, SanityCheck, SourceOnly, ReactosOrder;
 ULONG BuildType;
 
 /* FUNCTIONS ******************************************************************/
+VOID SetBaseFileName(CHAR *FileName)
+{
+    CHAR *Pointer = FileName;
+    CHAR *Temp;
+    /* skip directory */
+    Temp = strstr(Pointer, "\\");
+    while (Temp != NULL)
+    {
+        Pointer = Temp + 1;
+        Temp = strstr(Pointer, "\\");
+    }
+    /* Now Pointer point to the file name */
+    strcpy(BaseFileName, Pointer);
+    /* remove the extension */
+    Temp = strstr(BaseFileName, ".");
+    *Temp = '\0';
+}
 
+
 VOID
 PrintUsage(VOID)
 {
@@ -45,7 +65,8 @@
     printf("\t[-i] Builds for IA64\n");
     printf("\t[-m] Builds for AMD64\n");
     printf("\t[-o] Builds for WOW64\n");
-    printf("\t[-s] Generate Source files (no build)\n\n");
+    printf("\t[-s] Generate Source files (no build)\n");
+    printf("\t[-r] Use ReactOs order in source files (no build)\n\n");
     printf("\tFILE The source keyboard file (required)\n\n");
 
     /* Extra hints */
@@ -145,7 +166,10 @@
             case 's':
                 SourceOnly = 1;
                 break;
-
+            case 'R':
+            case 'r':
+                ReactosOrder = 1;
+                break;
             default:
                 /* If you got here, the options are invalid or missing */
                 PrintUsage();
@@ -167,6 +191,9 @@
     /* Save the file name */
     gpszFileName = argv[i];
 
+    /* Set the base file name */
+    SetBaseFileName(gpszFileName);
+
     /* Open either as binary or text */
     OpenFlags = "rb";
     if (!UnicodeFile) OpenFlags = "rt";
Index: tools/kbdtool/output.c
===================================================================
--- tools/kbdtool/output.c	(revision 66876)
+++ tools/kbdtool/output.c	(working copy)
@@ -19,14 +19,21 @@
 struct tm *Now;
 CHAR gCharName[32];
 
+INT ReorderTable[110];
+INT ReorderTableCount = 0;
+BOOL OutputModTable[8];
 /* FUNCTIONS ******************************************************************/
 
+#define WCH_ADD_ZERO 1
+#define WCH_USE_LONG 2
+
 PCHAR
 WChName(IN ULONG Char,
-        IN BOOLEAN AddZero)
+        IN UINT Flags)
 {
     PCHAR p;
-
+    BOOL AddZero = Flags & WCH_ADD_ZERO;
+    BOOL UseLong = Flags & WCH_USE_LONG;
     /* Check for invalid character */
     if (Char == -1)
     {
@@ -33,10 +40,12 @@
         /* No name */
         strcpy(gCharName, "WCH_NONE");
     }
-    else if ((Char > 31) && (Char < 128))
+    else if ((Char > 31) && (Char < 127))
     {
         /* Use our global buffer */
         p = gCharName;
+        /* Add 'L' if using unicode strings */
+        if (UseLong) *p++ = 'L';
 
         /* Add the first quote unless this was a zero-string */
         if (!AddZero) *p++ = '\'';
@@ -159,14 +168,13 @@
         /* Is this a dead key? */
         if (DeadKey)
         {
-            /* Not yet handled */
-            printf("Dead keys not yet handled\n");
-            exit(1);
+            /* Print the entry */
+            fprintf(FileHandle, "    L\"\\x%04x\"\tL%s,\n", KeyName->Code, CharBuffer);
         }
         else
         {
             /* Print the entry */
-            fprintf(FileHandle, "    0x%02x,    L%s,\n", KeyName->Code, CharBuffer);
+            fprintf(FileHandle, "    { 0x%02x, L%s },\n", KeyName->Code, CharBuffer);
         }
 
         /* Cleanup allocation */
@@ -180,18 +188,199 @@
     /* Is this a dead key? */
     if (DeadKey)
     {
-        /* Not yet handled */
-        printf("Dead keys not yet handled\n");
-        exit(1);
+        /* Terminate the table */
+        fprintf(FileHandle, "    NULL\n");
     }
     else
     {
         /* Terminate the table */
-        fprintf(FileHandle, "    0   ,    NULL\n");
+        fprintf(FileHandle, "    { 0, NULL }\n");
     }
 }
 
+
+INT getOrderedEntry(INT Index)
+{
+    return ReorderTable[Index];
+}
+
+INT EvaulateReactosOrder(INT VirtualKeyX, INT VirtualKeyY)
+{
+    INT IndexX, IndexY;
+    INT i;
+    if (VirtualKeyX == VirtualKeyY)
+    {
+        printf("Error! Duplicate VirtualKey while sorting");
+        exit(1);
+    }
+
+    IndexY = IndexY = MAX_ORDER_TABLE +1;
+    /* search ScanCodeX in the table and return index */
+    for (i = 0; i<MAX_ORDER_TABLE; i++)
+    {
+        if (ReactosOrderTable[i] == VirtualKeyX)
+        {
+            IndexX = i;
+            break;
+        }
+    }
+    /* search ScanCodeY in the table and return index */
+    for (i = 0; i<MAX_ORDER_TABLE; i++)
+    {
+        if (ReactosOrderTable[i] == VirtualKeyY)
+        {
+            IndexY = i;
+            break;
+        }
+    }
+    if ((IndexX >= MAX_ORDER_TABLE) && (IndexY >= MAX_ORDER_TABLE))
+    {
+        /* both values not found in table sort by ScanCode */
+        if (VirtualKeyX > VirtualKeyY )
+        {
+            return 1;
+        }
+        else
+        {
+            return -1;
+        };
+
+    }
+    else
+    {
+        if (IndexX >  IndexY )
+        {
+            return 1;
+        }
+        else
+        {
+            return -1;
+        }
+    }
+}
+
+INT addOrderEntry(IN PLAYOUT Layout, INT Index)
+{
+    INT Current, Tail;
+    INT VirtualKeyX, VirtualKeyY;
+    if (ReorderTableCount < 2)
+    {
+       if (ReorderTableCount == 0)
+       {
+           ReorderTable[0] = Index;
+           ReorderTableCount++;
+           return 0;
+       }
+       else
+       {
+           VirtualKeyX = Layout->Entry[Index].VirtualKey;
+           VirtualKeyY = Layout->Entry[ReorderTable[0]].VirtualKey;
+           if (EvaulateReactosOrder(VirtualKeyX, VirtualKeyY) > 0 )
+           {   // if it's bigger insert as last
+               ReorderTable[ReorderTableCount] = Index;
+               ReorderTableCount++;
+               return 1;
+           }
+           else
+           {   // if it's smaller insert as first
+               ReorderTable[ReorderTableCount] = ReorderTable[0];
+               ReorderTable[0] = Index;
+               ReorderTableCount++;
+               return 0;
+           }
+       }
+    }
+    else
+    {
+        Current = 0;
+        VirtualKeyX = Layout->Entry[Index].VirtualKey;
+        VirtualKeyY = Layout->Entry[ReorderTable[Current]].VirtualKey;
+        while (EvaulateReactosOrder(VirtualKeyX, VirtualKeyY) > 0)
+        {
+            //printf("VirtualKey %02x > %02x\n",VirtualKeyX,VirtualKeyY);
+            Current++;
+            if (Current >= ReorderTableCount)
+                break;
+            VirtualKeyY = Layout->Entry[ReorderTable[Current]].VirtualKey;
+        }
+        if (Current == ReorderTableCount)
+        {   // it's the bigger than all
+            ReorderTable[ReorderTableCount] = Index;
+            ReorderTableCount++;
+            return ReorderTableCount;
+        }
+        else
+        {   // it's in the middle;
+            // move all element after Current up;
+
+            for (Tail = ReorderTableCount; Tail > Current; Tail--)
+            {
+                ReorderTable[Tail] = ReorderTable[Tail-1];
+            }
+            ReorderTable[Current] = Index;
+            ReorderTableCount++;
+            return Current;
+        }
+
+    }
+}
+
+
+VOID OrderEntryes(IN PLAYOUT Layout)
+{
+    INT i,x;
+    ReorderTableCount = 0;
+    for (i = 0; i < 110; i++)
+    {
+        ReorderTable[i] = 0xFFFF;
+    }
+    for (i = 0; i < 110; i++)
+    {
+        if (Layout->Entry[i].StateCount > 0)
+        {
+            x = addOrderEntry(Layout, i);
+            //printf("Entry %d[0x%02x] Inserted in position %d/%d \n",i,Layout->Entry[i].ScanCode, x,ReorderTableCount);
+        }
+    }
+    for (i = 0; i < 110; i++)
+    {
+        if (Layout->Entry[i].StateCount <= 0)
+        {
+            ReorderTable[ReorderTableCount] = i;
+            ReorderTableCount++;
+        }
+    }
+}
+
+
 BOOLEAN
+kbd_spec(VOID)
+{
+    CHAR OutputFile[25];
+    FILE *FileHandle;
+
+    /* Build the keyboard name */
+    strcpy(OutputFile, BaseFileName);
+    strcat(OutputFile, ".spec");
+    /* Open it */
+    FileHandle = fopen(OutputFile, "wt");
+    if (!FileHandle)
+    {
+        /* Fail */
+        printf(" %12s : can't open for write.\n", OutputFile);
+        return FALSE;
+    }
+
+    fprintf(FileHandle,"@ stdcall KbdLayerDescriptor()");
+
+    /* Cleanup and close */
+    fclose(FileHandle);
+
+    /* We made it */
+    return TRUE;
+}
+
+BOOLEAN
 kbd_h(IN PLAYOUT Layout)
 {
     CHAR OutputFile[13];
@@ -215,19 +404,21 @@
 
     /* Print the module header */
     fprintf(FileHandle,
-            "/****************************** Module Header ******************************\\\n"
-            "* Module Name: %s\n*\n* keyboard layout header\n"
+            "/*\n"
+            "* ReactOS %s Keyboard layout header\n"
             "*\n"
             "* Copyright (c) 2009, ReactOS Foundation\n"
             "*\n"
-            "* Various defines for use by keyboard input code.\n*\n* History:\n"
+            "* created by KBDTOOL v%d.%02d %s\n"
             "*\n"
-            "* created by KBDTOOL v%d.%02d %s*\n"
-            "\\***************************************************************************/\n\n",
-            OutputFile,
+            "* Module Name: %s\n"
+            "*\n"
+            "*/\n\n",
+            gKBDName,
             gVersion,
             gSubVersion,
-            asctime(Now));
+            asctime(Now),
+            OutputFile);
 
     /* Print out the includes and defines */
     fprintf(FileHandle,
@@ -314,8 +505,98 @@
     return TRUE;
 }
 
+VOID ScancodeVKComments(FILE *FileHandle, INT Scancode)
+{
+    switch(Scancode)
+    {
+        case 0x02:
+            fprintf(FileHandle,
+            "\n/* First Row*/\n"
+            "/*  02   03   04   05   06  07   08   09   0A   0B   0C (-)        0D (+)       0E    */\n    ");
+            break;
+        case 0x0F:
+            fprintf(FileHandle,
+            "\n/*  Second Row */\n"
+            "/*  0F      10   11   12   13   14   15   16   17   18   19   1A ([)    1B (]) */\n    ");
+            break;
+        case 0x1C:
+            fprintf(FileHandle,
+            "\n/*  1C         1D          */\n");
+            break;
+        case 0x1E:
+            fprintf(FileHandle,
+            "\n/*  Third Row */\n"
+            "/*  1E   1F   20   21   22   23   24   25   26   27 (:)    28 (')    29 (~)*/\n    ");
+            break;
+        case 0x2A:
+            fprintf(FileHandle,
+            "\n/*  Fourth row */\n"
+            "/*  2A         2B (\\)    2C   2D   2E   2F   30   31   32   33 (,)        32 (.)         35 (?)    36      */\n    ");
+            break;
+        case 0x37:
+            fprintf(FileHandle,
+            "\n/*  Bottom Row */\n"
+            "/*  37 (Keypad*) 38(L_ALT) 39        3A CapsLock */\n    ");
+            break;
+        case 0x3B:
+            fprintf(FileHandle,
+            "\n/*  Top Row */\n"
+            "/*  3B     3C     3D     3E     3F     40     41     42     43     44     */\n    ");
+            break;
+        case 0x45:
+            fprintf(FileHandle,
+            "\n/*  Locks */\n    "
+            "/*  45                  46 */\n    ");
+            break;
+        case 0x47:
+            fprintf(FileHandle,
+            "\n/*  Number Pad */\n"
+            "/*  47 (KeyPad 7)    48(KeyPad 8)   49 (KeyPad 9)     4A (KeyPad -)  */\n    ");
+            break;
+        case 0x4B:
+            fprintf(FileHandle,
+            "\n/*  4B (KeyPad 4)    4C (KeyPad 5)     4D (KeyPad 6)     4E (KeyPad +)  */\n    ");
+            break;
+        case 0x4F:
+            fprintf(FileHandle,
+            "\n/*  4F (KeyPad 1)   50(KeyPad 2)     51 (KeyPad 3) */\n    ");
+            break;
+        case 0x52:
+            fprintf(FileHandle,
+            "\n/*  52 (KeyPad 0)      53(KeyPad .) */\n    ");
+            break;
+        case 0x54:
+            fprintf(FileHandle,
+            "\n/*  54 (Print Screen)  */\n    ");
+            break;
+        case 0x55:
+            fprintf(FileHandle,
+            "\n/*  Oddities, and the remaining standard F-Keys */\n"
+            "/*  55 (OEM?) 56 (OEM?)   57      58   */\n    ");
+            break;
+        case 0x59:
+            fprintf(FileHandle,
+            "\n/*  Keyboard Vendor Specific */\n"
+            "/*  59        5A        5B        5C        5D        5E        5F        60        61        62     */\n    ");
+            break;
+        case 0x63:
+            fprintf(FileHandle,
+            "/*  Even more F-Keys (for example, NCR keyboards from the early 90's) */\n    "
+            "/*  63       64       65      66      67      68      69      6A      6B      6C      6D      6E  */\n    ");
+            break;
+        case 0x6F:
+            fprintf(FileHandle,
+            "\n/*  More Keyboard Vendor Specific */\n"
+            "/*  6F        70        71        72        73        74        75        76   */\n    ");
+            break;
+        case 0x77:
+            fprintf(FileHandle,
+            "\n/*  77        78        79        7A        7B        7C        7D        7E        7F     */\n    ");
+    }
+}
+
 BOOLEAN
-kbd_rc(IN PKEYNAME DescriptionData,
+kbd_rc_ex(IN PKEYNAME DescriptionData,
        IN PKEYNAME LanguageData)
 {
     CHAR OutputFile[13];
@@ -516,6 +797,66 @@
 }
 
 BOOLEAN
+kbd_rc(IN PKEYNAME DescriptionData,
+       IN PKEYNAME LanguageData)
+{
+    CHAR OutputFile[13];
+    CHAR InternalName[13];
+    CHAR TimeBuffer[5];
+    FILE *FileHandle;
+    ULONG Length;
+    PCHAR p;
+    PKEYNAME NextDescription, NextLanguage;
+
+    /* Build the keyboard name and internal name */
+    strcpy(OutputFile, BaseFileName);
+    strcat(OutputFile, ".rc");
+    strcpy(InternalName, BaseFileName);
+    for (p = InternalName; *p; p++) *p = tolower(*p);
+
+    /* Open it */
+    FileHandle = fopen(OutputFile, "wb");
+    if (!FileHandle)
+    {
+        /* Fail */
+        printf(" %12s : can't open for write.\n", OutputFile);
+        return FALSE;
+    }
+
+    /* Check if we have copyright */
+    Length = strlen(gCopyright);
+    if (!Length)
+    {
+        /* Set time string */
+        strftime(TimeBuffer, 5, "%Y", Now);
+
+        /* Add copyright character */
+        strcpy(gCopyright, "(C)");
+
+        /* Add the year */
+        strcat(gCopyright, TimeBuffer);
+
+        /* Add blank company */
+        strcat(gCopyright, " ");
+    }
+
+    /* Write the resource file header */
+    fprintf(FileHandle,
+            "#define REACTOS_VERSION_DLL\n"
+            "#define REACTOS_STR_FILE_DESCRIPTION  \"ReactOS %s Keyboard Layout\"\n"
+            "#define REACTOS_STR_INTERNAL_NAME     \"%s\"\n"
+            "#define REACTOS_STR_ORIGINAL_FILENAME \"%s.dll\"\n"
+            "#include <reactos/version.rc>\n",
+            gDescription,
+            InternalName,
+            InternalName);
+
+    /* We're done! */
+    fclose(FileHandle);
+    return TRUE;
+}
+
+BOOLEAN
 kbd_def(VOID)
 {
     CHAR OutputFile[13];
@@ -546,13 +887,15 @@
     return TRUE;
 }
 
+
 BOOLEAN
 kbd_c(IN ULONG StateCount,
       IN PULONG ShiftStates,
-      IN PVOID AttributeData,
+      IN INT AttributeData,
       IN PLAYOUT Layout,
-      IN PVOID DeadKeyData,
-      IN PVOID LigatureData,
+      IN PDEADKEY DeadKeyData,
+      IN PLIGATURE LigatureData,
+      INT LigatureCount,
       IN PKEYNAME KeyNameData,
       IN PKEYNAME KeyNameExtData,
       IN PKEYNAME KeyNameDeadData)
@@ -561,16 +904,21 @@
     CHAR KeyNameBuffer[50];
     CHAR LineBuffer[256];
     BOOLEAN NeedPlus;
+    BOOLEAN NeedDeadLine;
     FILE *FileHandle;
     ULONG States[8];
-    ULONG i, j, k;
+    ULONG i, j, k, w;
     ULONG HighestState;
     PVKNAME Entry;
     PCHAR p;
+    PDEADKEY DeadKeyEntry;
+    ULONG LastDeadKey;
+    PLIGATURE LigatureEntry;
+    BOOL Found;
 
     /* Build the keyboard name and internal name */
-    strcpy(OutputFile, gKBDName);
-    strcat(OutputFile, ".C");
+    strcpy(OutputFile, BaseFileName);
+    strcat(OutputFile, ".c");
 
     /* Open it */
     FileHandle = fopen(OutputFile, "wt");
@@ -583,18 +931,20 @@
 
     /* Print the header */
     fprintf(FileHandle,
-            "/***************************************************************************\\\n"
-            "* Module Name: %s\n*\n* keyboard layout\n"
-            "*\n"
+            "/*\n"
+            "* ReactOS %s Keyboard layout\n"
             "* Copyright (c) 2009, ReactOS Foundation\n"
             "*\n"
-            "* History:\n"
-            "* KBDTOOL v%d.%02d - Created  %s"
-            "\\***************************************************************************/\n\n",
-            OutputFile,
+            "* created by KBDTOOL v%d.%02d %s"
+            "*\n"
+            "* This File is generated by KBDTOOL from %s\n"
+            "* Please do not edit\n"
+            "*/\n\n",
+            gDescription,
             gVersion,
             gSubVersion,
-            asctime(Now));
+            asctime(Now),
+            gpszFileName);
 
     /* What kind of driver is this? */
     if (FallbackDriver)
@@ -606,9 +956,11 @@
     {
         /* Add the includes */
         fprintf(FileHandle,
-                "#include <windows.h>\n"
-                "#include \"kbd.h\"\n"
-                "#include \"%s.h\"\n\n",
+                "#define WIN32_NO_STATUS\n"
+                "#include <stdarg.h>\n"
+                "#include <windef.h>\n"
+                "#include <winuser.h>\n"
+                "#include <ndk/kbd.h>\n\n",
                 gKBDName);
     }
 
@@ -624,88 +976,69 @@
     {
         /* Section and attributes depend on architecture */
         fprintf(FileHandle,
-                "#if defined(_M_IA64)\n"
-                "#pragma section(\"%s\")\n"
-                "#define ALLOC_SECTION_LDATA __declspec(allocate(\"%s\"))\n"
+                "#ifdef _M_IA64\n"
+                "#define ROSDATA static __declspec(allocate(\".data\"))\n"
                 "#else\n"
-                "#pragma data_seg(\"%s\")\n"
-                "#define ALLOC_SECTION_LDATA\n"
-                "#endif\n\n",
-                ".data",
-                ".data",
-                ".data");
+                "#ifdef _MSC_VER\n"
+                "#pragma data_seg(\".data\")\n"
+                "#define ROSDATA static\n"
+                "#else\n"
+                "#define ROSDATA static __attribute__((section(\".data\")))\n"
+                "#endif\n"
+                "#endif\n\n");
     }
 
+
+    fprintf(FileHandle,
+            "#define VK_EMPTY  0xff   /* The non-existent VK */\n\n"
+            "#define KNUMS     KBDNUMPAD|KBDSPECIAL /* Special + number pad */\n"
+            "#define KMEXT     KBDEXT|KBDMULTIVK    /* Multi + ext */\n\n");
     /* Scan code to virtual key conversion table header */
     fprintf(FileHandle,
             "/***************************************************************************\\\n"
-            "* ausVK[] - Virtual Scan Code to Virtual Key conversion table\n"
+            "* scancode_to_vk[] - Virtual Scan Code to Virtual Key conversion table\n"
             "\\***************************************************************************/\n\n");
 
     /* Table begin */
     fprintf(FileHandle,
-            "static ALLOC_SECTION_LDATA USHORT ausVK[] = {\n"
-            "    T00, T01, T02, T03, T04, T05, T06, T07,\n"
-            "    T08, T09, T0A, T0B, T0C, T0D, T0E, T0F,\n"
-            "    T10, T11, T12, T13, T14, T15, T16, T17,\n"
-            "    T18, T19, T1A, T1B, T1C, T1D, T1E, T1F,\n"
-            "    T20, T21, T22, T23, T24, T25, T26, T27,\n"
-            "    T28, T29, T2A, T2B, T2C, T2D, T2E, T2F,\n"
-            "    T30, T31, T32, T33, T34, T35,\n\n");
+            "ROSDATA USHORT scancode_to_vk[] =\n"
+            "{\n"
+            "/*  00(Error) 01 */\n");
+    fprintf(FileHandle,"    %s, ",ScancodeTable[0]);
+    for (i = 1; i < 0x80; i++)
+    {
+        ScancodeVKComments(FileHandle,i);
+        Found = 0;
+        for (j = 0; (j<110) && (i != 0x53) ; j++) // 0x53 is VK_DECIMAL an exception
+        {
+            /* Check Scancode */
+            if (Layout->Entry[j].ScanCode == i)
+            {
+                /* Which is mapped */
+                if (Layout->Entry[j].VirtualKey != 0xFF)
+                {
+                    /* Output it */
+                    fprintf(FileHandle,
+                            "%s, ",
+                           getVKName(Layout->Entry[j].VirtualKey,TRUE));
+                    Found = TRUE;
+                    break;
+                }
+            }
 
-    /* Table continue */
+        }
+        if (!Found)
+        {
+            fprintf(FileHandle,"%s, ",ScancodeTable[i]);
+        }
+    }
+     /* Table finish */
     fprintf(FileHandle,
-            "    /*\n"
-            "     * Right-hand Shift key must have KBDEXT bit set.\n"
-            "     */\n"
-            "    T36 | KBDEXT,\n\n"
-            "    T37 | KBDMULTIVK,               // numpad_* + Shift/Alt -> SnapShot\n\n"
-            "    T38, T39, T3A, T3B, T3C, T3D, T3E,\n"
-            "    T3F, T40, T41, T42, T43, T44,\n\n");
+            "\n    0\n};\n\n");
 
-    /* Table continue */
-    fprintf(FileHandle,
-            "    /*\n"
-            "     * NumLock Key:\n"
-            "     *     KBDEXT     - VK_NUMLOCK is an Extended key\n"
-            "     *     KBDMULTIVK - VK_NUMLOCK or VK_PAUSE (without or with CTRL)\n"
-            "     */\n"
-            "    T45 | KBDEXT | KBDMULTIVK,\n\n"
-            "    T46 | KBDMULTIVK,\n\n");
 
-    /* Numpad table */
-    fprintf(FileHandle,
-            "    /*\n"
-            "     * Number Pad keys:\n"
-            "     *     KBDNUMPAD  - digits 0-9 and decimal point.\n"
-            "     *     KBDSPECIAL - require special processing by Windows\n"
-            "     */\n"
-            "    T47 | KBDNUMPAD | KBDSPECIAL,   // Numpad 7 (Home)\n"
-            "    T48 | KBDNUMPAD | KBDSPECIAL,   // Numpad 8 (Up),\n"
-            "    T49 | KBDNUMPAD | KBDSPECIAL,   // Numpad 9 (PgUp),\n"
-            "    T4A,\n"
-            "    T4B | KBDNUMPAD | KBDSPECIAL,   // Numpad 4 (Left),\n"
-            "    T4C | KBDNUMPAD | KBDSPECIAL,   // Numpad 5 (Clear),\n"
-            "    T4D | KBDNUMPAD | KBDSPECIAL,   // Numpad 6 (Right),\n"
-            "    T4E,\n"
-            "    T4F | KBDNUMPAD | KBDSPECIAL,   // Numpad 1 (End),\n"
-            "    T50 | KBDNUMPAD | KBDSPECIAL,   // Numpad 2 (Down),\n"
-            "    T51 | KBDNUMPAD | KBDSPECIAL,   // Numpad 3 (PgDn),\n"
-            "    T52 | KBDNUMPAD | KBDSPECIAL,   // Numpad 0 (Ins),\n"
-            "    T53 | KBDNUMPAD | KBDSPECIAL,   // Numpad . (Del),\n\n");
-
-    /* Table finish */
-    fprintf(FileHandle,
-            "    T54, T55, T56, T57, T58, T59, T5A, T5B,\n"
-            "    T5C, T5D, T5E, T5F, T60, T61, T62, T63,\n"
-            "    T64, T65, T66, T67, T68, T69, T6A, T6B,\n"
-            "    T6C, T6D, T6E, T6F, T70, T71, T72, T73,\n"
-            "    T74, T75, T76, T77, T78, T79, T7A, T7B,\n"
-            "    T7C, T7D, T7E\n\n"
-            "};\n\n");
-
     /* Key name table header */
-    fprintf(FileHandle, "static ALLOC_SECTION_LDATA VSC_VK aE0VscToVk[] = {\n");
+    fprintf(FileHandle, "ROSDATA VSC_VK extcode0_to_vk[] =\n{\n");
 
     /* Loop 110-key table */
     for (i = 0; i < 110; i++)
@@ -721,10 +1054,9 @@
                 {
                     /* Output them */
                     fprintf(FileHandle,
-                            "        { 0x%02X, X%02X | KBDEXT              },  // %s\n",
-                            Layout->Entry[i].ScanCode,
-                            Layout->Entry[i].ScanCode,
-                            Layout->Entry[i].Name);
+                            "    { 0x%02X, %s | KBDEXT },\n",
+                            Layout->Entry[i].ScanCode & 0xFF,
+                            getVKName(Layout->Entry[i].VirtualKey,TRUE));
                 }
             }
         }
@@ -731,10 +1063,10 @@
     }
 
     /* Key name table finish */
-    fprintf(FileHandle, "        { 0,      0                       }\n};\n\n");
+    fprintf(FileHandle, "    { 0, 0 }\n};\n\n");
 
     /* Extended key name table header */
-    fprintf(FileHandle, "static ALLOC_SECTION_LDATA VSC_VK aE1VscToVk[] = {\n");
+    fprintf(FileHandle, "ROSDATA VSC_VK extcode1_to_vk[] =\n{\n");
 
     /* Loop 110-key table */
     for (i = 0; i < 110; i++)
@@ -750,10 +1082,9 @@
                 {
                     /* Output them */
                     fprintf(FileHandle,
-                            "        { 0x%02X, Y%02X | KBDEXT            },  // %s\n",
-                            Layout->Entry[i].ScanCode,
-                            Layout->Entry[i].ScanCode,
-                            Layout->Entry[i].Name);
+                            "    { 0x%02X, %s | KBDEXT },\n",
+                            Layout->Entry[i].ScanCode & 0xFF,
+                            getVKName(Layout->Entry[i].VirtualKey,TRUE));
                 }
             }
         }
@@ -761,13 +1092,13 @@
 
     /* Extended key name table finish */
     fprintf(FileHandle,
-            "        { 0x1D, Y1D                       },  // Pause\n"
-            "        { 0   ,   0                       }\n};\n\n");
+            "    { 0x1D, VK_PAUSE },\n"
+            "    { 0, 0 }\n};\n\n");
 
     /* Modifier table description */
     fprintf(FileHandle,
             "/***************************************************************************\\\n"
-            "* aVkToBits[]  - map Virtual Keys to Modifier Bits\n"
+            "* modifier_keys[]  - map Virtual Keys to Modifier Bits\n"
             "*\n"
             "* See kbd.h for a full description.\n"
             "*\n"
@@ -778,7 +1109,7 @@
             "\\***************************************************************************/\n");
 
     /* Modifier table header */
-    fprintf(FileHandle, "static ALLOC_SECTION_LDATA VK_TO_BIT aVkToBits[] = {\n");
+    fprintf(FileHandle, "ROSDATA VK_TO_BIT modifier_keys[] =\n{\n");
 
     /* Loop modifier table */
     i = 0;
@@ -787,7 +1118,7 @@
     {
         /* Print out entry */
         fprintf(FileHandle,
-                "    { %-12s,   %-12s },\n",
+                "    { %-12s, %-12s },\n",
                 getVKName(Entry->VirtualKey, 1),
                 Entry->Name);
 
@@ -801,7 +1132,7 @@
     /* Modifier conversion table description */
     fprintf(FileHandle,
             "/***************************************************************************\\\n"
-            "* aModification[]  - map character modifier bits to modification number\n"
+            "* modifier_bits[]  - map character modifier bits to modification number\n"
             "*\n"
             "* See kbd.h for a full description.\n"
             "*\n"
@@ -810,18 +1141,36 @@
     /* Zero out local state data */
     for (i = 0; i < 8; i++) States[i] = -1;
 
-    /* Find the highest set state */
-    for (HighestState = 1, i = 0; (i < 8) && (ShiftStates[i] != -1); i++)
+    /* transpose states */
+    /* in klc there is ColumnX -> ModifierK in source
+       ModifierK -> (ColumnY-4) skipping invalid states
+       Klc:  1	//Column  5 :	Shft
+             2	//Column  6 :	     Ctrl
+             5	//Column  7 :	Shft Alt
+
+       Source:     {NoModifier,SHIFT,CTRL,SHIFT+CTRL,ALT    ,ALT+SH,ALT+CTRL,ALT+CTRL+SH)
+                   {         0,    1,   2,   INVALID,INVALID,3}
+       */
+
+    HighestState = 0;
+    for(i = 0; i < 8; i++)
     {
-        /* Save all state values */
-        States[ShiftStates[i]] = i;
-        if (ShiftStates[i] > HighestState) HighestState = ShiftStates[i];
+        for (j = 0; j < StateCount; j++)
+        {
+           if (ShiftStates[j] == i)
+           {
+              States[i]=j;
+              if (Verbose) printf("States [%d] column [%d] mapped to ShiftState [%d] Column [%d]\n",j,ShiftStates[j],i,States[i]);
+              if (i > HighestState)
+                HighestState= i;
+           }
+        }
     }
 
     /* Modifier conversion table header */
     fprintf(FileHandle,
-            "static ALLOC_SECTION_LDATA MODIFIERS CharModifiers = {\n"
-            "    &aVkToBits[0],\n"
+            "ROSDATA MODIFIERS modifier_bits =\n{\n"
+            "    modifier_keys,\n"
             "    %d,\n"
             "    {\n"
             "    //  Modification# //  Keys Pressed\n"
@@ -835,7 +1184,7 @@
         if (States[i] == -1)
         {
             /* Invalid state header */
-            fprintf(FileHandle, "        SHFT_INVALID, // ");
+            fprintf(FileHandle, "        SHFT_INVALID, // \n");
         }
         else
         {
@@ -853,9 +1202,8 @@
 
             /* State 1 or higher? */
             if (i >= 1)
-            {
-                /* J is the loop variable, K is the double */
-                for (NeedPlus = 0, j = 0, k = 1; (1 << j) <= i; j++, k = (1 << j))
+            {   NeedPlus = 0;
+                for (j = 1, k = 0; j <= i; j*=2 , k++)
                 {
                     /* Do we need to add a plus? */
                     if (NeedPlus)
@@ -866,10 +1214,10 @@
                     }
 
                     /* Check if it's time to add a modifier */
-                    if (i & k)
+                    if (i & j)
                     {
                         /* Get the key state name and copy it into our buffer */
-                        strcpy(KeyNameBuffer, getVKName(Modifiers[j].VirtualKey, 1));
+                        strcpy(KeyNameBuffer, Modifiers[k].Name);
 
                         /* Go go the 4th char (past the "KBD") and lower name */
                         for (p = &KeyNameBuffer[4]; *p; p++) *p = tolower(*p);
@@ -890,22 +1238,22 @@
 
 
     /* Modifier conversion table end */
-    fprintf(FileHandle,"     }\n" "};\n\n");
+    fprintf(FileHandle,"     }\n};\n\n");
 
     /* Shift state translation table description */
     fprintf(FileHandle,
             "/***************************************************************************\\\n"
             "*\n"
-            "* aVkToWch2[]  - Virtual Key to WCHAR translation for 2 shift states\n"
-            "* aVkToWch3[]  - Virtual Key to WCHAR translation for 3 shift states\n"
-            "* aVkToWch4[]  - Virtual Key to WCHAR translation for 4 shift states\n");
+            "* key_to_chars_2mod[]  - Virtual Key to WCHAR translation for 2 shift states\n"
+            "* key_to_chars_3mod[]  - Virtual Key to WCHAR translation for 3 shift states\n"
+            "* key_to_chars_4mod[]  - Virtual Key to WCHAR translation for 4 shift states\n");
 
     /* Check if there's exta shift states */
-    for (i = 5; i < HighestState; i++)
+    for (i = 5; i <= HighestState; i++)
     {
         /* Print out extra information */
         fprintf(FileHandle,
-                "* aVkToWch%d[]  - Virtual Key to WCHAR translation for %d shift states\n",
+                "* key_to_chars_%dmod[]  - Virtual Key to WCHAR translation for %d shift states\n",
                 i,
                 i);
     }
@@ -932,52 +1280,91 @@
             "*\n"
             "\\***************************************************************************/\n\n");
 
+    /* Order the entry as in current sources*/
+    if (ReactosOrder)
+    {
+        OrderEntryes(Layout);
+    }
+    /* output section 2 by default */
+    OutputModTable[2]=TRUE;
     /* Loop all the states */
     for (i = 2; i <= StateCount; i++)
     {
+
         /* Check if this something else than state 2 */
         if (i != 2)
-        {
+            /* do not output any section > 2 by default */
+        {   OutputModTable[i]=FALSE;
             /* Loop all the scan codes */
             for (j = 0; j < 110; j++)
             {
                 /* Check if this is the state for the entry */
-                if (i == Layout->Entry[j].StateCount) break;
+                if (i == Layout->Entry[j].StateCount)
+                {
+                    /* output this section */
+                    OutputModTable[i]=TRUE;
+                    break;
+                }
             }
         }
+        /* don't output this table it's empty */
+        if (!OutputModTable[i]) goto endmodtable;
 
         /* Print the table header */
         fprintf(FileHandle,
-                "static ALLOC_SECTION_LDATA VK_TO_WCHARS%d aVkToWch%d[] = {\n"
-                "//                      |         |  Shift  |",
+                "ROSDATA VK_TO_WCHARS%d key_to_chars_%dmod[] =\n{\n"
+                "//                           |          |   Shift  |",
                 i,
                 i);
 
         /* Print the correct state label */
-        for (k = 2; k < i; k++) fprintf(FileHandle, "%-9.9s|",
-                                        StateLabel[ShiftStates[k]]);
+        w = 1;
+        for (k = 2; k < i; k++){
+            w++;
+            while(States[w]==-1){
+                w++;
+                if (w > HighestState) {
+                    printf("Valid States < %d\n",StateCount);
+                    exit(1);
+                }
+            }
+            fprintf(FileHandle, " %-9.9s|", StateLabel[w]);
 
+        }
+
         /* Print the next separator */
-        fprintf(FileHandle, "\n//                      |=========|=========|");
+        fprintf(FileHandle, "\n//                           |==========|==========|");
 
         /* Check for extra states and print their separators too */
-        for (k = 2; k < i; k++) fprintf(FileHandle, "=========|");
+        for (k = 2; k < i; k++) fprintf(FileHandle, "==========|");
 
         /* Finalize the separator header */
         fprintf(FileHandle, "\n");
 
         /* Loop all the scan codes */
-        for (j = 0; j < 110; j++)
+        for (w = 0; w < 110; w++)
         {
+            if (!ReactosOrder)
+            {
+                j = w;
+            }
+            else
+            {
+                j = getOrderedEntry(w);
+                //printf ("index %d return state %d\n",w,j);
+            }
+
             /* Check if this is the state for the entry */
             if (i != Layout->Entry[j].StateCount) continue;
 
+            /* reset DeadKey Flag */
+            NeedDeadLine = FALSE;
+
             /* Print out the entry for this key */
             fprintf(FileHandle,
-                    "  {%-13s,%-7s",
+                    "    { %-13s,%-7s, {",
                     getVKName(Layout->Entry[j].VirtualKey, 1),
                     CapState[Layout->Entry[j].Cap]);
-
             /* Initialize the buffer for this line */
             *LineBuffer = '\0';
 
@@ -985,33 +1372,72 @@
             for (k = 0; k < i; k++)
             {
                 /* Check for dead key data */
-                if (DeadKeyData)
+                if (Layout->Entry[j].DeadCharData[k])
                 {
-                    /* Not yet supported */
-                    printf("Dead key data not supported!\n");
-                    exit(1);
+                    /* Print out WCH_DEAD and set the flag */
+                    fprintf(FileHandle,
+                            " %-9s","WCH_DEAD");
+                    NeedDeadLine = TRUE;
+                }/* Check if it's a ligature key */
+                else if (Layout->Entry[j].LigatureCharData[k])
+                {
+                     /* Print out WCH_LGTR */
+                    fprintf(FileHandle,
+                            " %-9s","WCH_LGTR");
                 }
-
-                /* Check if it's a ligature key */
-                if (Layout->Entry[j].LigatureCharData[k])
+                else
                 {
-                    /* Not yet supported */
-                    printf("Ligature key data not supported!\n");
-                    exit(1);
+                    /* Print out the WCH_ name */
+                    fprintf(FileHandle,
+                            " %-9s",
+                            WChName(Layout->Entry[j].CharData[k], 0));
                 }
-
-                /* Print out the WCH_ name */
-                fprintf(FileHandle,
-                        ",%-9s",
-                        WChName(Layout->Entry[j].CharData[k], 0));
-
+                if (k != i-1)
+                    fprintf(FileHandle,",");
                 /* If we have something on the line buffer by now, add WCH_NONE */
                 if (*LineBuffer != '\0') strcpy(LineBuffer, "WCH_NONE ");
             }
 
             /* Finish the line */
-            fprintf(FileHandle, "},\n");
+            fprintf(FileHandle, "} },\n");
 
+            if (NeedDeadLine)
+            {
+                /* Print out the dead key entry for this key */
+                fprintf(FileHandle,
+                        "    { %-13s,%-7s, {",
+                        "VK_EMPTY","0");
+                /* Initialize the buffer for this line */
+                *LineBuffer = '\0';
+
+                /* Loop states */
+                for (k = 0; k < i; k++)
+                {
+                    /* Check for dead key data */
+                    if (Layout->Entry[j].DeadCharData[k])
+                    {
+                        /* Print out the WCH_ name */
+                        fprintf(FileHandle,
+                                " %-9s",
+                                WChName(Layout->Entry[j].CharData[k], 0));
+                    }
+                    else
+                    {
+                        /* Print out WCH_NONE */
+                        fprintf(FileHandle,
+                                " %-9s",
+                                "WCH_NONE");
+                    }
+                    if (k != i-1)
+                        fprintf(FileHandle,",");
+                    /* If we have something on the line buffer by now, add WCH_NONE */
+                    if (*LineBuffer != '\0') strcpy(LineBuffer, "WCH_NONE ");
+                }
+
+                /* Finish the line */
+                fprintf(FileHandle, "} },\n");
+            }
+
             /* Do we have any data at all? */
             if (*LineBuffer != '\0')
             {
@@ -1033,65 +1459,72 @@
         {
             /* Print out the built-in table */
             fprintf(FileHandle,
-                    "  {VK_TAB       ,0      ,'\\t'     ,'\\t'     },\n"
-                    "  {VK_ADD       ,0      ,'+'      ,'+'      },\n"
-                    "  {VK_DIVIDE    ,0      ,'/'      ,'/'      },\n"
-                    "  {VK_MULTIPLY  ,0      ,'*'      ,'*'      },\n"
-                    "  {VK_SUBTRACT  ,0      ,'-'      ,'-'      },\n");
+                    "    { VK_TAB       ,0      , { '\\t'     , '\\t'     } },\n"
+                    "    { VK_ADD       ,0      , { '+'      , '+'      } },\n"
+                    "    { VK_DIVIDE    ,0      , { '/'      , '/'      } },\n"
+                    "    { VK_MULTIPLY  ,0      , { '*'      , '*'      } },\n"
+                    "    { VK_SUBTRACT  ,0      , { '-'      , '-'      } },\n");
         }
 
         /* Terminate the table */
-        fprintf(FileHandle, "  {0            ,0      ");
-        for (k = 0; k < i; k++) fprintf(FileHandle, ",0        ");
+        fprintf(FileHandle, "    { 0, 0 }\n");
 
         /* Terminate the structure */
-        fprintf(FileHandle, "}\n" "};\n\n");
+        fprintf(FileHandle, "};\n\n");
+
+        endmodtable:
+            continue;
     }
 
     /* Numpad translation table */
     fprintf(FileHandle,
             "// Put this last so that VkKeyScan interprets number characters\n"
-            "// as coming from the main section of the kbd (aVkToWch2 and\n"
-            "// aVkToWch5) before considering the numpad (aVkToWch1).\n\n"
-            "static ALLOC_SECTION_LDATA VK_TO_WCHARS1 aVkToWch1[] = {\n"
-            "    { VK_NUMPAD0   , 0      ,  '0'   },\n"
-            "    { VK_NUMPAD1   , 0      ,  '1'   },\n"
-            "    { VK_NUMPAD2   , 0      ,  '2'   },\n"
-            "    { VK_NUMPAD3   , 0      ,  '3'   },\n"
-            "    { VK_NUMPAD4   , 0      ,  '4'   },\n"
-            "    { VK_NUMPAD5   , 0      ,  '5'   },\n"
-            "    { VK_NUMPAD6   , 0      ,  '6'   },\n"
-            "    { VK_NUMPAD7   , 0      ,  '7'   },\n"
-            "    { VK_NUMPAD8   , 0      ,  '8'   },\n"
-            "    { VK_NUMPAD9   , 0      ,  '9'   },\n"
-            "    { 0            , 0      ,  '\\0'  }\n"
+            "// as coming from the main section of the kbd (key_to_chars_2mod and\n"
+            "// key_to_chars_5mod) before considering the numpad (keypad_numbers).\n\n"
+            "ROSDATA VK_TO_WCHARS1 keypad_numbers[] =\n{\n"
+            "    { VK_NUMPAD0, 0, {'0'} },\n"
+            "    { VK_NUMPAD1, 0, {'1'} },\n"
+            "    { VK_NUMPAD2, 0, {'2'} },\n"
+            "    { VK_NUMPAD3, 0, {'3'} },\n"
+            "    { VK_NUMPAD4, 0, {'4'} },\n"
+            "    { VK_NUMPAD5, 0, {'5'} },\n"
+            "    { VK_NUMPAD6, 0, {'6'} },\n"
+            "    { VK_NUMPAD7, 0, {'7'} },\n"
+            "    { VK_NUMPAD8, 0, {'8'} },\n"
+            "    { VK_NUMPAD9, 0, {'9'} },\n"
+            "    { 0, 0 }\n"
             "};\n\n");
 
     /* Translation tables header */
-    fprintf(FileHandle,"static ALLOC_SECTION_LDATA VK_TO_WCHAR_TABLE aVkToWcharTable[] = {\n");
+    fprintf(FileHandle,"#define vk_master(n, x) { (PVK_TO_WCHARS1)x, n, sizeof(x[0]) }\n\n");
 
-    /* Loop states higher than 3 */
+    fprintf(FileHandle,"ROSDATA VK_TO_WCHAR_TABLE vk_to_wchar_master_table[] =\n{\n");
+
+
+
+    /* Loop states higher than 2 */
     for (i = 3; i <= StateCount; i++)
     {
-        /* Print out the extra tables */
-        fprintf(FileHandle,
-                "    {  (PVK_TO_WCHARS1)aVkToWch%d, %d, sizeof(aVkToWch%d[0]) },\n",
-                i,
-                i,
-                i);
+        /* Print out the extra tables if are not empty */
+        if (OutputModTable[i])
+            fprintf(FileHandle,
+                    "    vk_master(%d, key_to_chars_%dmod),\n",
+                    i,
+                    i);
     }
 
     /* Array of translation tables */
     fprintf(FileHandle,
-            "    {  (PVK_TO_WCHARS1)aVkToWch2, 2, sizeof(aVkToWch2[0]) },\n"
-            "    {  (PVK_TO_WCHARS1)aVkToWch1, 1, sizeof(aVkToWch1[0]) },\n"
-            "    {                       NULL, 0, 0                    },\n"
+            "    vk_master(%d, key_to_chars_%dmod),\n"
+            "    vk_master(1, keypad_numbers),\n",2,2);
+    /* Terminate The Array of translation tables */
+    fprintf(FileHandle,
+            "    { 0, 0, 0 }\n"
             "};\n\n");
-
     /* Scan code to key name conversion table description */
     fprintf(FileHandle,
             "/***************************************************************************\\\n"
-            "* aKeyNames[], aKeyNamesExt[]  - Virtual Scancode to Key Name tables\n"
+            "* key_names[], extended_key_names[]  - Virtual Scancode to Key Name tables\n"
             "*\n"
             "* Table attributes: Ordered Scan (by scancode), null-terminated\n"
             "*\n"
@@ -1103,7 +1536,7 @@
     if (KeyNameData)
     {
         /* Table header */
-        fprintf(FileHandle, "static ALLOC_SECTION_LDATA VSC_LPWSTR aKeyNames[] = {\n");
+        fprintf(FileHandle, "ROSDATA VSC_LPWSTR key_names[] =\n{\n");
 
         /* Print table */
         PrintNameTable(FileHandle, KeyNameData, FALSE);
@@ -1116,7 +1549,7 @@
     if (KeyNameExtData)
     {
         /* Table header */
-        fprintf(FileHandle, "static ALLOC_SECTION_LDATA VSC_LPWSTR aKeyNamesExt[] = {\n");
+        fprintf(FileHandle, "ROSDATA VSC_LPWSTR extended_key_names[] =\n{\n");
 
         /* Print table */
         PrintNameTable(FileHandle, KeyNameExtData, FALSE);
@@ -1128,68 +1561,138 @@
     /* Check for dead key name data */
     if (KeyNameDeadData)
     {
-        /* Not yet supported */
-        printf("Dead key name data not supported!\n");
-        exit(1);
+        /* Table header */
+        fprintf(FileHandle, "ROSDATA DEADKEY_LPWSTR dead_key_names[] =\n{\n");
+
+        /* Print table */
+        PrintNameTable(FileHandle, KeyNameDeadData, TRUE);
+
+        /* Table end */
+        fprintf(FileHandle, "};\n\n");
     }
 
     /* Check for dead key data */
     if (DeadKeyData)
     {
-        /* Not yet supported */
-        printf("Dead key data not supported!\n");
-        exit(1);
+        fprintf(FileHandle,
+                "/***************************************************************************\\\n"
+                "* deadkey[]  Dead Key Table n"
+                "*\n"
+                "* Table attributes: null-terminated\n"
+                "*\n"
+                "* Source Scancode, Dead Key Scancode , Target Scancode, Flags \n"
+                "\\***************************************************************************/\n\n");
+
+        fprintf(FileHandle, "#define DEADTRANS(ch, accent, comp, flags) MAKELONG(ch, accent), comp, flags\n\n");
+        /* Table header */
+        fprintf(FileHandle, "ROSDATA DEADKEY deadkey[] =\n{");
+        /* Print the table */
+        DeadKeyEntry = DeadKeyData;
+        LastDeadKey = 0;
+        while (DeadKeyEntry != NULL)
+        {
+            if (LastDeadKey != DeadKeyEntry->Key)
+                fprintf(FileHandle,"\n");
+            fprintf(FileHandle,"    { DEADTRANS(");
+            fprintf(FileHandle,"0x%04x, ", DeadKeyEntry->Source);
+            fprintf(FileHandle,"0x%04x, ", DeadKeyEntry->Key);
+            fprintf(FileHandle,"0x%04x, ", DeadKeyEntry->Target);
+            // Fix Me Flags not handled/
+            fprintf(FileHandle,"0x0000) }\n");
+            LastDeadKey = DeadKeyEntry->Key;
+            DeadKeyEntry = DeadKeyEntry->Next;
+        }
+        /* Table end */
+        fprintf(FileHandle,"    { 0, 0 }\n");
+        fprintf(FileHandle, "};\n\n");
     }
 
     /* Check for ligature data */
     if (LigatureData)
     {
-        /* Not yet supported */
-        printf("Ligature key data not supported!\n");
-        exit(1);
-    }
+        /* Ligature table description */
+        fprintf(FileHandle,
+                "/***************************************************************************\\\n"
+                "* LIGATURE%d Ligature[] - Ligature data table\n"
+                "*\n"
+                "* Table attributes: null-terminated\n"
+                "*\n"
+                "* ScanCode, Shiftstate, Char1, .. , CharN  \n"
+                "\\***************************************************************************/\n\n"
+                ,LigatureCount);
 
-    /* Main keyboard table descriptor type */
-    fprintf(FileHandle, "static ");
+        /* Table Header */
+        fprintf(FileHandle, "ROSDATA LIGATURE%d Ligature[] =\n{\n" , LigatureCount);
+        LigatureEntry = LigatureData;
+        while (LigatureEntry != NULL)
+        {
+            /* Start Ligature Entry */
+            fprintf(FileHandle, "    {");
+            /* Ligature Entry ScanCode */
+            fprintf(FileHandle, " %s, ", getVKName(LigatureEntry->Key,1));
+            /* Ligature Entry Modifier */
+            fprintf(FileHandle, " %d, {", LigatureEntry->Modifier);
+            /* Ligature Entry Characters */
+            for (k = 0; k < LigatureEntry->CharCount; k++)
+            {
+                fprintf(FileHandle, " 0x%04x  ", LigatureEntry->Characters[k]);
+                /* is not the last */
+                if (k < (LigatureCount-1))
+                {
+                    fprintf(FileHandle, ",");
+                }
+            }
+            /* Complete the entry */
+            for (; k < LigatureCount; k++)
+            {
+                fprintf(FileHandle, " WCH_NONE");
+                /* is not the last */
+                if (k < (LigatureCount-1))
+                {
+                    fprintf(FileHandle, ",");
+                }
+            }
 
-    /* FIXME? */
+            /* End Ligature Entry */
+            fprintf(FileHandle, " } },\n", LigatureData->Modifier);
+            /* Go to Next */
+            LigatureEntry = LigatureEntry->Next;
+        }
 
+
+        /* Table End */
+        fprintf(FileHandle, "    {0, 0}\n};\n");
+    }
+
     /* Main keyboard table descriptor header */
     fprintf(FileHandle,
-            "ALLOC_SECTION_LDATA KBDTABLES KbdTables%s = {\n"
-            "    /*\n"
-            "     * Modifier keys\n"
-            "     */\n"
-            "    &CharModifiers,\n\n"
-            "    /*\n"
-            "     * Characters tables\n"
-            "     */\n"
-            "    aVkToWcharTable,\n\n"
-            "    /*\n"
-            "     * Diacritics\n"
-            "     */\n",
+            "/* Finally, the master table */\n"
+            "ROSDATA KBDTABLES keyboard_layout_table =\n{\n"
+            "    /* modifier assignments */\n"
+            "    &modifier_bits,\n\n"
+            "    /* character from vk tables */\n"
+            "    vk_to_wchar_master_table,\n\n"
+            "    /* diacritical marks -- currently implemented by wine code */\n",
             FallbackDriver ? "Fallback" : "" );
 
     /* Descriptor dead key data section */
     if (DeadKeyData)
     {
-        fprintf(FileHandle, "    aDeadKey,\n\n");
+        fprintf(FileHandle, "    deadkey,\n\n");
     }
     else
     {
-        fprintf(FileHandle, "    NULL,\n\n");
+        fprintf(FileHandle, "    /* %s doesn't have any  */\n    NULL,\n\n",gKBDName );
     }
 
     /* Descriptor key name comment */
     fprintf(FileHandle,
-            "    /*\n"
-            "     * Names of Keys\n"
-            "     */\n");
+            "    /* Key names */\n");
 
     /* Descriptor key name section */
     if (KeyNameData)
     {
-        fprintf(FileHandle, "    aKeyNames,\n");
+        fprintf(FileHandle, "    (VSC_LPWSTR *) key_names,\n");
     }
     else
     {
@@ -1199,7 +1702,7 @@
     /* Descriptor extended key name section */
     if (KeyNameExtData)
     {
-        fprintf(FileHandle, "    aKeyNamesExt,\n");
+        fprintf(FileHandle, "    (VSC_LPWSTR *) extended_key_names,\n");
     }
     else
     {
@@ -1209,44 +1712,40 @@
     /* Descriptor dead key name section */
     if ((DeadKeyData) && (KeyNameDeadData))
     {
-        fprintf(FileHandle, "    aKeyNamesDead,\n\n");
+        fprintf(FileHandle, "    dead_key_names,\n\n");
     }
     else
     {
-        fprintf(FileHandle, "    NULL,\n\n");
+        fprintf(FileHandle, "    NULL, /* Dead key names */\n\n");
     }
 
     /* Descriptor conversion table section  */
     fprintf(FileHandle,
-            "    /*\n"
-            "     * Scan codes to Virtual Keys\n"
-            "     */\n"
-            "    ausVK,\n"
-            "    sizeof(ausVK) / sizeof(ausVK[0]),\n"
-            "    aE0VscToVk,\n"
-            "    aE1VscToVk,\n\n"
-            "    /*\n"
-            "     * Locale-specific special processing\n"
-            "     */\n");
+            "    /* scan code to virtual key maps */\n"
+            "    scancode_to_vk,\n"
+            "    sizeof(scancode_to_vk) / sizeof(scancode_to_vk[0]),\n"
+            "    extcode0_to_vk,\n"
+            "    extcode1_to_vk,\n"
+            "    \n");
 
-    /* FIXME: AttributeData and KLLF_ALTGR stuff */
-
     /* Descriptor locale-specific section */
-    fprintf(FileHandle, "    MAKELONG(%s, KBD_VERSION),\n\n", "0");  /* FIXME */
+    fprintf(FileHandle, "    MAKELONG(%s, 1),  /* Version 1.0 */\n\n", Attributes[AttributeData]);
 
     /* Descriptor ligature data comment */
-    fprintf(FileHandle, "    /*\n     * Ligatures\n     */\n    %d,\n", 0); /* FIXME */
+    fprintf(FileHandle, "    /* Ligatures */\n");
 
     /* Descriptor ligature data section */
     if (!LigatureData)
     {
         fprintf(FileHandle, "    0,\n");
+        fprintf(FileHandle, "    0,\n");
         fprintf(FileHandle, "    NULL\n");
     }
     else
     {
-        fprintf(FileHandle, "    sizeof(aLigature[0]),\n");
-        fprintf(FileHandle, "    (PLIGATURE1)aLigature\n");
+        fprintf(FileHandle, "    %d,\n", LigatureCount);
+        fprintf(FileHandle, "    sizeof(Ligature[0]),\n");
+        fprintf(FileHandle, "    (PLIGATURE1) Ligature\n");
     }
 
     /* Descriptor finish */
@@ -1254,10 +1753,10 @@
 
     /* Keyboard layout callback function */
     if (!FallbackDriver) fprintf(FileHandle,
-                                 "PKBDTABLES KbdLayerDescriptor(VOID)\n"
+                                 "PKBDTABLES WINAPI KbdLayerDescriptor(VOID)\n"
                                  "{\n"
-                                 "    return &KbdTables;\n"
-                                 "}\n");
+                                 "    return &keyboard_layout_table;\n"
+                                 "}\n\n");
 
     /* Clean up */
     fclose(FileHandle);
@@ -1269,9 +1768,10 @@
          IN PULONG ShiftStates,
          IN PKEYNAME DescriptionData,
          IN PKEYNAME LanguageData,
-         IN PVOID AttributeData,
-         IN PVOID DeadKeyData,
-         IN PVOID LigatureData,
+         IN INT LigatureCount,
+         IN INT AttributeData,
+         IN PDEADKEY DeadKeyData,
+         IN PLIGATURE LigatureData,
          IN PKEYNAME KeyNameData,
          IN PKEYNAME KeyNameExtData,
          IN PKEYNAME KeyNameDeadData)
@@ -1286,8 +1786,9 @@
     if (!FallbackDriver)
     {
         /* It's not, create header file */
-        if (!kbd_h(&g_Layout)) FailureCode = 1;
-
+        // if (!kbd_h(&g_Layout)) FailureCode = 1; it's not needed anymore
+        /* Create spec file */
+        if (!kbd_spec()) FailureCode = 1;
         /* Create the resource file */
         if (!kbd_rc(DescriptionData, LanguageData)) FailureCode = 2;
     }
@@ -1299,6 +1800,7 @@
                &g_Layout,
                DeadKeyData,
                LigatureData,
+               LigatureCount,
                KeyNameData,
                KeyNameExtData,
                KeyNameDeadData))
@@ -1307,12 +1809,12 @@
         FailureCode = 3;
     }
 
-    /* Check if this just a fallback driver*/
-    if (!FallbackDriver)
-    {
-        /* Generate the definition file */
-        if (!kbd_def()) FailureCode = 4;
-    }
+    /* Check if this just a fallback driver */
+    //if (!FallbackDriver) // it's not needed anymore
+    //{
+    //    /* Generate the definition file */
+    //    if (!kbd_def()) FailureCode = 4;
+    //}
 
     /* Done */
     return FailureCode;
Index: tools/kbdtool/parser.c
===================================================================
--- tools/kbdtool/parser.c	(revision 66876)
+++ tools/kbdtool/parser.c	(working copy)
@@ -92,7 +92,7 @@
     }
 
     /* Loop all virtual keys */
-    for (i = 0; i < 36; i++)
+    for (i = 0; i < MAX_VKKEY_NAMES; i++)
     {
         /* Check if this key matches */
         if (VKName[i].VirtualKey == VirtualKey)
@@ -105,6 +105,7 @@
 
     /* If we got here, then we failed, so print out an error name */
     strcpy(gVKeyName, "#ERROR#");
+    printf("ERROR: VKeyName not found for %d\n", VirtualKey);
     return gVKeyName;
 }
 
@@ -136,10 +137,10 @@
     }
 
     /* Otherwise, scan our virtual key names */
-    for (i = 0; i < 36; i++)
+    for (i = 0; i < MAX_VKKEY_NAMES; i++)
     {
         /* Check if we have a match */
-        if (!strcmp(VKName[i].Name, p)) return VKName[i].VirtualKey;
+        if (strcmp(VKName[i].Name, p)==0) return VKName[i].VirtualKey;
     }
 
     /*  Check if this is a hex string */
@@ -149,7 +150,7 @@
         *(p + 1) = 'x';
         if (sscanf(p, "0x%x", &KeyNumber) == 1) return KeyNumber;
     }
-
+    printf("Unknown Virtual Key %s",p);
     /* No hope: fail */
     return -1;
 }
@@ -179,8 +180,8 @@
         }
         else if (StateChar == '%')
         {
-            /* This is another key */
-            CharInfo = CHAR_OTHER_KEY;
+            /* This is ligature key */
+            CharInfo = CHAR_LIGATURE_KEY;
         }
     }
 
@@ -189,15 +190,10 @@
     {
         /* Scan for extended character code entry */
         if ((sscanf(State, "%6x", &CharCode) == 1) &&
-            ((Length == 5) && (State[0] == '0') ||
+            (((Length == 5) && (State[0] == '0') && !(CharInfo == CHAR_DEAD_KEY))||
              (Length == 6) && ((State[0] == '0') && (State[1] == '0'))))
         {
-            /* Handle a ligature key */
-            CharInfo = CHAR_LIGATURE_KEY;
-
-            /* Not yet handled */
-            printf("Ligatured character entries not yet supported!\n");
-            exit(1);
+            if (EntryChar) *EntryChar = CharCode;
         }
         else
         {
@@ -636,10 +632,10 @@
         if (KeyWord < KEYWORD_COUNT) break;
 
         /* Now scan for the shift state */
-        if (sscanf(gBuf, " %1s[012367]", Token) != 1)
+        if (sscanf(gBuf, " %1s[012367-]", Token) != 1)
         {
             /* We failed -- should we warn? */
-            if (Verbose) printf("An invalid shift state '%s' was found (use 0, 1, 2, 3, 6, or 7.)\n", Token);
+            if (Verbose) printf("An invalid shift state '%s' was found (use 0, 1, 2, 3, 4, 5, 6, ,7.)\n", Token);
             continue;
         }
 
@@ -646,6 +642,7 @@
         /* Now read the state */
         ShiftState = atoi(Token);
 
+
         /* Scan existing states */
         for (i = 0; i < *StateCount; i++)
         {
@@ -672,9 +669,9 @@
     }
 
     /* Debug only */
-    DPRINT1("Found %d Shift States: [", *StateCount);
-    for (i = 0; i < *StateCount; i++) DPRINT1("%d ", ShiftStates[i]);
-    DPRINT1("]\n");
+    if (Verbose) printf("Found %d Shift States: [", *StateCount);
+    for (i = 0; i < *StateCount; i++) if (Verbose) printf("%d ", ShiftStates[i]);
+    if (Verbose) printf("]\n");
 
     /* We are done */
     return KeyWord;
@@ -681,17 +678,171 @@
 }
 
 ULONG
-DoLIGATURE(PVOID LigatureData)
+DoLIGATURE(IN PLIGATURE *LigatureData, IN OUT INT *LigatureCount)
 {
-    printf("LIGATURE support is not yet implemented. Please bug Arch to fix it\n");
-    return SkipLines();
+    INT i;
+    ULONG KeyWord = 0;
+    CHAR Token[32];
+    ULONG CharacterCode;
+    CHAR VKey[32];
+    INT Modifier;
+    CHAR Temp[10][20];
+    PLIGATURE LigatureKey, LastLigatureKey;
+    UCHAR LigatureChar;
+    UCHAR CharacterType;
+
+    /* Go to the end of the list */
+    LigatureKey = *LigatureData;
+    while (LigatureKey != NULL)
+    {
+        LastLigatureKey = LigatureKey;
+        LigatureKey = LigatureKey->Next;
+    }
+
+    /* Start scanning */
+    while (NextLine(gBuf, 256, gfpInput))
+    {
+        /* Search for token */
+        if (sscanf(gBuf, "%s", Token) != 1) continue;
+
+        /* Make sure it's not just a comment */
+        if (*Token == ';') continue;
+
+        /* Make sure it's not a keyword */
+        KeyWord = isKeyWord(Token);
+        if (KeyWord < KEYWORD_COUNT) break;
+
+        /* Now scan for the source code */
+        if (sscanf(Token, "%s", VKey) != 1)
+        {
+            /* Skip */
+            printf("An invalid ligature source code was specified in [%s].\n",gBuf);
+            continue;
+        }
+
+        /* Now scan for the modifier */
+        if (sscanf(gBuf, "%*s %4d ", &Modifier) != 1)
+        {
+            /* Skip */
+            printf("An invalid ligature modifier was specified in [%s].\n",gBuf);
+            continue;
+        }
+
+        /* Now allocate the ligature key */
+        LigatureKey = malloc(sizeof(LIGATURE));
+        if (!LigatureKey)
+        {
+            /* Fail */
+            printf("Unable to allocate the LIGATURE struct (out of memory?).\n");
+            exit(1);
+        }
+        /* initialize characters */
+        LigatureKey->Characters[0] = LigatureKey->Characters[1] =
+        LigatureKey->Characters[2] = LigatureKey->Characters[3] =
+        LigatureKey->Characters[4] = LigatureKey->Characters[5] =
+        LigatureKey->Characters[6] = LigatureKey->Characters[7] =
+        LigatureKey->Characters[8] = LigatureKey->Characters[9] = 0xFFFF;
+
+        /* Fill out the structure */
+        LigatureKey->Key = getVKNum(VKey);
+        LigatureKey->Modifier = Modifier;
+        LigatureKey->Next = NULL;
+        LigatureKey->CharCount = sscanf(gBuf, "%*s %*4d %s %s %s %s %s %s %s %s %s %s",
+                                        &Temp[0],
+                                        &Temp[1],
+                                        &Temp[2],
+                                        &Temp[3],
+                                        &Temp[4],
+                                        &Temp[5],
+                                        &Temp[6],
+                                        &Temp[7],
+                                        &Temp[8],
+                                        &Temp[9]
+                                        );
+        /* set the maximum CharCount */
+        if (*LigatureCount < LigatureKey->CharCount)
+        {
+             *LigatureCount = LigatureKey->CharCount;
+        }
+
+        /* Transform string Characters to ULONG */
+        for (i = 0;  i < LigatureKey->CharCount ; i++ )
+        {
+            CharacterType = getCharacterInfo(Temp[i],
+                                             &LigatureKey->Characters[i],
+                                             &LigatureChar);
+
+            if ((CharacterType == CHAR_DEAD_KEY) || (CharacterType == CHAR_LIGATURE_KEY))
+            {
+                printf("DeadKey and Ligatures Not Supported in Ligatures\n");
+                exit(1);
+            }
+        }
+
+        /* Debug only */
+        DPRINT("LIGATURE: Code:[%4x] State:[%d] Count:[%d]\n", LigatureKey->Key, LigatureKey->Modifier, LigatureKey->CharCount);
+        DPRINT("%4x %4x %4x %4x %4x %4x %4x %4x %4x %4x \n\n", LigatureKey->Characters[0],
+                        LigatureKey->Characters[1],
+                        LigatureKey->Characters[2],
+                        LigatureKey->Characters[3],
+                        LigatureKey->Characters[4],
+                        LigatureKey->Characters[5],
+                        LigatureKey->Characters[6],
+                        LigatureKey->Characters[7],
+                        LigatureKey->Characters[8],
+                        LigatureKey->Characters[9]);
+
+
+        /* Point to it and advance the pointer */
+        if (*LigatureData == NULL)
+        {
+            *LigatureData = LigatureKey;
+        }
+        else
+        {
+            LastLigatureKey->Next = LigatureKey;
+        }
+        LastLigatureKey = LigatureKey;
+    }
+
+    /* We are done */
+    return KeyWord;
 }
 
-ULONG
-DoATTRIBUTES(PVOID AttributeData)
+INT DoATTRIBUTES(INT *AttributeData)
 {
-    printf("ATTRIBUTES support is not yet implemented. Please bug Arch to fix it\n");
-    return SkipLines();
+    INT i;
+    ULONG KeyWord = 0;
+    CHAR Token[32];
+    PCHAR p;
+
+    /* Start scanning */
+    while (NextLine(gBuf, 256, gfpInput))
+    {
+        /* Search for token */
+        if (sscanf(gBuf, "%s", Token) != 1) continue;
+
+        /* Make sure it's not just a comment */
+        if (*Token == ';') continue;
+
+        /* Make sure it's not a keyword */
+        KeyWord = isKeyWord(Token);
+        if (KeyWord < KEYWORD_COUNT) break;
+
+        /* search it in the attribute list */
+        for(i = 1; i < MAX_ATTRIBUTES; i++)
+        {
+            p = Attributes[i];
+            p += 5; // skip KLLF_
+            if (strcmp(Token, p) == 0)
+            {
+                printf("Attributes %s found at %d\n",Token,i);
+                *AttributeData = i;
+            }
+        }
+    }
+    /* We are done */
+    return KeyWord;
 }
 
 ULONG
@@ -702,15 +853,98 @@
 }
 
 ULONG
-DoDEADKEY(PVOID DeadKeyData)
+DoDEADKEY(IN PDEADKEY *DeadKeyData)
 {
-    printf("DEADKEY support is not yet implemented. Please bug Arch to fix it\n");
-    return SkipLines();
+    ULONG KeyWord = 0;
+    CHAR Token[32];
+    ULONG CharacterCode;
+    ULONG SourceCode;
+    ULONG TargetCode;
+    PDEADKEY DeadKey;
+    PDEADKEY LastDeadKey;
+
+    /* Go to the end of the list */
+    DeadKey = *DeadKeyData;
+    LastDeadKey = *DeadKeyData;
+    while (DeadKey != NULL)
+    {
+        LastDeadKey = DeadKey;
+        DeadKey = DeadKey->Next;
+    }
+
+    /* Scan for the value */
+    if (sscanf(gBuf, "DEADKEY %04X", &CharacterCode) < 1)
+    {
+        /* Couldn't find them */
+        printf("Unable to read deadkey code.\n");
+    }
+
+    /* Start scanning */
+    while (NextLine(gBuf, 256, gfpInput))
+    {
+        /* Search for token */
+        if (sscanf(gBuf, "%s", Token) != 1) continue;
+
+        /* Make sure it's not just a comment */
+        if (*Token == ';') continue;
+
+        /* Make sure it's not a keyword */
+        KeyWord = isKeyWord(Token);
+        if (KeyWord < KEYWORD_COUNT) break;
+
+        /* Now scan for the source code */
+        if (sscanf(Token, "%4x", &SourceCode) != 1)
+        {
+            /* Skip */
+            printf("An invalid dedkey source code was specified.\n");
+            continue;
+        }
+
+        /* Now scan for the target code */
+        if (sscanf(gBuf, "%*4x %4x[^\n]", &TargetCode) != 1)
+        {
+            /* Skip */
+            printf("An invalid dedkey target code was specified.\n");
+            continue;
+        }
+
+        /* Now allocate the dead key */
+        DeadKey = malloc(sizeof(DEADKEY));
+        if (!DeadKey)
+        {
+            /* Fail */
+            printf("Unable to allocate the DEADKEY struct (out of memory?).\n");
+            exit(1);
+        }
+
+        /* Fill out the structure */
+        DeadKey->Key = CharacterCode;
+        DeadKey->Source = SourceCode;
+        DeadKey->Target = TargetCode;
+        DeadKey->Next = NULL;
+
+        /* Debug only */
+        DPRINT1("DEADKEY: [%4x] [%4x]->[%4x]\n", DeadKey->Key, DeadKey->Source, DeadKey->Target);
+
+        /* Point to it and advance the pointer */
+        if (*DeadKeyData == NULL)
+        {
+            *DeadKeyData = DeadKey;
+        }
+        else
+        {
+            LastDeadKey->Next = DeadKey;
+        }
+        LastDeadKey = DeadKey;
+    }
+
+    /* We are done */
+    return KeyWord;
 }
 
 ULONG
 DoLAYOUT(IN PLAYOUT LayoutData,
-         IN PVOID LigatureData,
+         IN PLIGATURE LigatureData,
          IN PULONG ShiftStates,
          IN ULONG StateCount)
 {
@@ -727,7 +961,6 @@
     ULONG ScanCodeCount = -1;
     PLAYOUTENTRY Entry;
     UCHAR CharacterType, LigatureChar;
-
     /* Zero out the layout */
     memset(LayoutData, 0, sizeof(LAYOUT));
 
@@ -898,8 +1131,19 @@
                 /* Save it as such */
                 Entry->OtherCharData[i] = 1;
             }
+            else if (CharacterType == CHAR_LIGATURE_KEY)
+            {
+                /* Save it as such */
+                Entry->LigatureCharData[i] = 1;
+            }
         }
+        /* Remove unused states */
+        while ((Entry->CharData[Entry->StateCount-1] == -1))
+        {
+            Entry->StateCount--;
+        }
 
+
         /* Check for sanity checks */
         DPRINT1("]\n");
         if (SanityCheck)
@@ -919,7 +1163,7 @@
     }
 
     /* Process the scan code table */
-    Entry = &LayoutData->Entry[ScanCodeCount];
+    Entry = &LayoutData->Entry[ScanCodeCount+1];
     for (i = 0; i < 110; i++)
     {
         /* Get the scan code */
@@ -968,7 +1212,10 @@
     ULONG ShiftStates[8];
     PKEYNAME DescriptionData = NULL, LanguageData = NULL;
     PKEYNAME KeyNameData = NULL, KeyNameExtData = NULL, KeyNameDeadData = NULL;
-    PVOID AttributeData = NULL, LigatureData = NULL, DeadKeyData = NULL;
+    INT AttributeData = 0;
+    PLIGATURE LigatureData = NULL;
+    INT LigatureCount = 0;
+    PDEADKEY DeadKeyData = NULL;
 
     /* Parse keywords */
     gLineCount = 0;
@@ -1066,7 +1313,7 @@
 
                 DPRINT1("Found LAYOUT section\n");
                 KeyWord = DoLAYOUT(&g_Layout,
-                                   &LigatureData,
+                                   LigatureData,
                                    ShiftStates,
                                    StateCount);
                 break;
@@ -1082,7 +1329,7 @@
             case 10:
 
                 DPRINT1("Found LIGATURE section\n");
-                KeyWord = DoLIGATURE(&LigatureData);
+                KeyWord = DoLIGATURE(&LigatureData, &LigatureCount);
                 break;
 
             /* KEYNAME */
@@ -1141,6 +1388,7 @@
                     ShiftStates,
                     DescriptionData,
                     LanguageData,
+                    LigatureCount,
                     AttributeData,
                     DeadKeyData,
                     LigatureData,
Index: tools/kbdtool/test.klc
===================================================================
--- tools/kbdtool/test.klc	(revision 66876)
+++ tools/kbdtool/test.klc	(working copy)
@@ -1,4 +1,4 @@
-KBD	Layout01	"US - Custom"
+KBD	American	"United States"
 
 COPYRIGHT	"(c) 2009 Company"
 
@@ -15,62 +15,66 @@
 0	//Column 4
 1	//Column 5 : Shft
 2	//Column 6 :       Ctrl
-
+3	//Column 7 : Shft  Ctrl
 LAYOUT		;an extra '@' at the end is a dead key
 
-//SC	VK_		Cap	0	1	2
-//--	----		----	----	----	----
+//SC	VK_		Cap	0	1	2	3
+//--	----		----	----	----	----	----
 
-02	1		0	1	0021	-1		// DIGIT ONE, EXCLAMATION MARK, <none>
-03	2		0	2	0040	-1		// DIGIT TWO, COMMERCIAL AT, <none>
-04	3		0	3	0023	-1		// DIGIT THREE, NUMBER SIGN, <none>
-05	4		0	4	0024	-1		// DIGIT FOUR, DOLLAR SIGN, <none>
-06	5		0	5	0025	-1		// DIGIT FIVE, PERCENT SIGN, <none>
-07	6		0	6	005e	-1		// DIGIT SIX, CIRCUMFLEX ACCENT, <none>
-08	7		0	7	0026	-1		// DIGIT SEVEN, AMPERSAND, <none>
-09	8		0	8	002a	-1		// DIGIT EIGHT, ASTERISK, <none>
-0a	9		0	9	0028	-1		// DIGIT NINE, LEFT PARENTHESIS, <none>
-0b	0		0	0	0029	-1		// DIGIT ZERO, RIGHT PARENTHESIS, <none>
-0c	OEM_MINUS	0	002d	005f	-1		// HYPHEN-MINUS, LOW LINE, <none>
-0d	OEM_PLUS	0	003d	002b	-1		// EQUALS SIGN, PLUS SIGN, <none>
-10	Q		1	q	Q	-1		// LATIN SMALL LETTER Q, LATIN CAPITAL LETTER Q, <none>
-11	W		1	w	W	-1		// LATIN SMALL LETTER W, LATIN CAPITAL LETTER W, <none>
-12	E		1	e	E	-1		// LATIN SMALL LETTER E, LATIN CAPITAL LETTER E, <none>
-13	R		1	r	R	-1		// LATIN SMALL LETTER R, LATIN CAPITAL LETTER R, <none>
-14	T		1	t	T	-1		// LATIN SMALL LETTER T, LATIN CAPITAL LETTER T, <none>
-15	Y		1	y	Y	-1		// LATIN SMALL LETTER Y, LATIN CAPITAL LETTER Y, <none>
-16	U		1	u	U	-1		// LATIN SMALL LETTER U, LATIN CAPITAL LETTER U, <none>
-17	I		1	i	I	-1		// LATIN SMALL LETTER I, LATIN CAPITAL LETTER I, <none>
-18	O		1	o	O	-1		// LATIN SMALL LETTER O, LATIN CAPITAL LETTER O, <none>
-19	P		1	p	P	-1		// LATIN SMALL LETTER P, LATIN CAPITAL LETTER P, <none>
-1a	OEM_4		0	005b	007b	001b		// LEFT SQUARE BRACKET, LEFT CURLY BRACKET, ESCAPE
-1b	OEM_6		0	005d	007d	001d		// RIGHT SQUARE BRACKET, RIGHT CURLY BRACKET, INFORMATION SEPARATOR THREE
-1e	A		1	a	A	-1		// LATIN SMALL LETTER A, LATIN CAPITAL LETTER A, <none>
-1f	S		1	s	S	-1		// LATIN SMALL LETTER S, LATIN CAPITAL LETTER S, <none>
-20	D		1	d	D	-1		// LATIN SMALL LETTER D, LATIN CAPITAL LETTER D, <none>
-21	F		1	f	F	-1		// LATIN SMALL LETTER F, LATIN CAPITAL LETTER F, <none>
-22	G		1	g	G	-1		// LATIN SMALL LETTER G, LATIN CAPITAL LETTER G, <none>
-23	H		1	h	H	-1		// LATIN SMALL LETTER H, LATIN CAPITAL LETTER H, <none>
-24	J		1	j	J	-1		// LATIN SMALL LETTER J, LATIN CAPITAL LETTER J, <none>
-25	K		1	k	K	-1		// LATIN SMALL LETTER K, LATIN CAPITAL LETTER K, <none>
-26	L		1	l	L	-1		// LATIN SMALL LETTER L, LATIN CAPITAL LETTER L, <none>
-27	OEM_1		0	003b	003a	-1		// SEMICOLON, COLON, <none>
-28	OEM_7		0	0027	0022	-1		// APOSTROPHE, QUOTATION MARK, <none>
-29	OEM_3		0	0060	007e	-1		// GRAVE ACCENT, TILDE, <none>
-2b	OEM_5		0	005c	007c	001c		// REVERSE SOLIDUS, VERTICAL LINE, INFORMATION SEPARATOR FOUR
-2c	Z		1	z	Z	-1		// LATIN SMALL LETTER Z, LATIN CAPITAL LETTER Z, <none>
-2d	X		1	x	X	-1		// LATIN SMALL LETTER X, LATIN CAPITAL LETTER X, <none>
-2e	C		1	c	C	-1		// LATIN SMALL LETTER C, LATIN CAPITAL LETTER C, <none>
-2f	V		1	v	V	-1		// LATIN SMALL LETTER V, LATIN CAPITAL LETTER V, <none>
-30	B		1	b	B	-1		// LATIN SMALL LETTER B, LATIN CAPITAL LETTER B, <none>
-31	N		1	n	N	-1		// LATIN SMALL LETTER N, LATIN CAPITAL LETTER N, <none>
-32	M		1	m	M	-1		// LATIN SMALL LETTER M, LATIN CAPITAL LETTER M, <none>
-33	OEM_COMMA	0	002c	003c	-1		// COMMA, LESS-THAN SIGN, <none>
-34	OEM_PERIOD	0	002e	003e	-1		// FULL STOP, GREATER-THAN SIGN, <none>
-35	OEM_2		0	002f	003f	-1		// SOLIDUS, QUESTION MARK, <none>
-39	SPACE		0	0020	0020	0020		// SPACE, SPACE, SPACE
-56	OEM_102	0	005c	007c	001c		// REVERSE SOLIDUS, VERTICAL LINE, INFORMATION SEPARATOR FOUR
-53	DECIMAL	0	002e	002e	-1		// FULL STOP, FULL STOP, 
+01	ESCAPE		0	001b	001b	001b	-1	// 
+02	1		0	1	0021	-1	-1	// DIGIT ONE, EXCLAMATION MARK, <none>
+03	2		0	2	0040	-1	0000	// DIGIT TWO, COMMERCIAL AT, <none>
+04	3		0	3	0023	-1	-1	// DIGIT THREE, NUMBER SIGN, <none>
+05	4		0	4	0024	-1	-1	// DIGIT FOUR, DOLLAR SIGN, <none>
+06	5		0	5	0025	-1	-1	// DIGIT FIVE, PERCENT SIGN, <none>
+07	6		0	6	005e	-1	001e	// DIGIT SIX, CIRCUMFLEX ACCENT, <none>
+08	7		0	7	0026	-1	-1	// DIGIT SEVEN, AMPERSAND, <none>
+09	8		0	8	002a	-1	-1	// DIGIT EIGHT, ASTERISK, <none>
+0a	9		0	9	0028	-1	-1	// DIGIT NINE, LEFT PARENTHESIS, <none>
+0b	0		0	0	0029	-1	-1	// DIGIT ZERO, RIGHT PARENTHESIS, <none>
+0c	OEM_MINUS	0	002d	005f	-1	001F	// HYPHEN-MINUS, LOW LINE, <none>
+0d	OEM_PLUS	0	003d	002b	-1	-1	// EQUALS SIGN, PLUS SIGN, <none>
+0e	BACK		0	0008	0008	007F		//
+10	Q		1	q	Q	-1	-1	// LATIN SMALL LETTER Q, LATIN CAPITAL LETTER Q, <none>
+11	W		1	w	W	-1	-1	// LATIN SMALL LETTER W, LATIN CAPITAL LETTER W, <none>
+12	E		1	e	E	-1	-1	// LATIN SMALL LETTER E, LATIN CAPITAL LETTER E, <none>
+13	R		1	r	R	-1	-1	// LATIN SMALL LETTER R, LATIN CAPITAL LETTER R, <none>
+14	T		1	t	T	-1	-1	// LATIN SMALL LETTER T, LATIN CAPITAL LETTER T, <none>
+15	Y		1	y	Y	-1	-1	// LATIN SMALL LETTER Y, LATIN CAPITAL LETTER Y, <none>
+16	U		1	u	U	-1	-1	// LATIN SMALL LETTER U, LATIN CAPITAL LETTER U, <none>
+17	I		1	i	I	-1	-1	// LATIN SMALL LETTER I, LATIN CAPITAL LETTER I, <none>
+18	O		1	o	O	-1	-1	// LATIN SMALL LETTER O, LATIN CAPITAL LETTER O, <none>
+19	P		1	p	P	-1	-1	// LATIN SMALL LETTER P, LATIN CAPITAL LETTER P, <none>
+1a	OEM_4		0	005b	007b	001b	-1	// LEFT SQUARE BRACKET, LEFT CURLY BRACKET, ESCAPE
+1b	OEM_6		0	005d	007d	001d	-1	// RIGHT SQUARE BRACKET, RIGHT CURLY BRACKET, INFORMATION SEPARATOR THREE
+1c	RETURN		0	000d	000d	000a	-1	//
+1e	A		1	a	A	-1	-1	// LATIN SMALL LETTER A, LATIN CAPITAL LETTER A, <none>
+1f	S		1	s	S	-1	-1	// LATIN SMALL LETTER S, LATIN CAPITAL LETTER S, <none>
+20	D		1	d	D	-1	-1	// LATIN SMALL LETTER D, LATIN CAPITAL LETTER D, <none>
+21	F		1	f	F	-1	-1	// LATIN SMALL LETTER F, LATIN CAPITAL LETTER F, <none>
+22	G		1	g	G	-1	-1	// LATIN SMALL LETTER G, LATIN CAPITAL LETTER G, <none>
+23	H		1	h	H	-1	-1	// LATIN SMALL LETTER H, LATIN CAPITAL LETTER H, <none>
+24	J		1	j	J	-1	-1	// LATIN SMALL LETTER J, LATIN CAPITAL LETTER J, <none>
+25	K		1	k	K	-1	-1	// LATIN SMALL LETTER K, LATIN CAPITAL LETTER K, <none>
+26	L		1	l	L	-1	-1	// LATIN SMALL LETTER L, LATIN CAPITAL LETTER L, <none>
+27	OEM_1		0	003b	003a	-1	-1	// SEMICOLON, COLON, <none>
+28	OEM_7		0	0027	0022	-1	-1	// APOSTROPHE, QUOTATION MARK, <none>
+29	OEM_3		0	0060	007e	-1	-1	// GRAVE ACCENT, TILDE, <none>
+2b	OEM_5		0	005c	007c	001c	-1	// REVERSE SOLIDUS, VERTICAL LINE, INFORMATION SEPARATOR FOUR
+2c	Z		1	z	Z	-1	-1	// LATIN SMALL LETTER Z, LATIN CAPITAL LETTER Z, <none>
+2d	X		1	x	X	-1	-1	// LATIN SMALL LETTER X, LATIN CAPITAL LETTER X, <none>
+2e	C		1	c	C	-1	-1	// LATIN SMALL LETTER C, LATIN CAPITAL LETTER C, <none>
+2f	V		1	v	V	-1	-1	// LATIN SMALL LETTER V, LATIN CAPITAL LETTER V, <none>
+30	B		1	b	B	-1	-1	// LATIN SMALL LETTER B, LATIN CAPITAL LETTER B, <none>
+31	N		1	n	N	-1	-1	// LATIN SMALL LETTER N, LATIN CAPITAL LETTER N, <none>
+32	M		1	m	M	-1	-1	// LATIN SMALL LETTER M, LATIN CAPITAL LETTER M, <none>
+33	OEM_COMMA	0	002c	003c	-1	-1	// COMMA, LESS-THAN SIGN, <none>
+34	OEM_PERIOD	0	002e	003e	-1	-1	// FULL STOP, GREATER-THAN SIGN, <none>
+35	OEM_2		0	002f	003f	-1	-1	// SOLIDUS, QUESTION MARK, <none>
+39	SPACE		0	0020	0020	0020	-1	// SPACE, SPACE, SPACE
+46	CANCEL		0	0003	0003	0003	-1	//
+56	OEM_102	0	005c	007c	001c	-1	-1	// REVERSE SOLIDUS, VERTICAL LINE, INFORMATION SEPARATOR FOUR
+53	DECIMAL	0	002e	002e	-1	-1	-1	// FULL STOP, FULL STOP, 
 
 
 KEYNAME
