Index: tools/kbdtool/data.c
===================================================================
--- tools/kbdtool/data.c	(revision 66665)
+++ tools/kbdtool/data.c	(working copy)
@@ -13,44 +13,149 @@
 /* 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"},
 };
 /* Table of modifiers */
 VKNAME Modifiers[] =
Index: tools/kbdtool/kbdtool.h
===================================================================
--- tools/kbdtool/kbdtool.h	(revision 66665)
+++ tools/kbdtool/kbdtool.h	(working copy)
@@ -23,6 +23,8 @@
 #define CHAR_INVALID_KEY  3
 #define CHAR_LIGATURE_KEY 4
 
+#define MAX_VKKEY_NAMES 141
+
 typedef struct tagKEYNAME
 {
     ULONG Code;
@@ -74,6 +76,7 @@
 
 extern BOOLEAN Verbose, UnicodeFile, SanityCheck, FallbackDriver;
 extern PCHAR gpszFileName;
+extern CHAR BaseFileName[256];
 extern FILE* gfpInput;
 extern VKNAME VKName[];
 extern VKNAME Modifiers[];
Index: tools/kbdtool/main.c
===================================================================
--- tools/kbdtool/main.c	(revision 66665)
+++ tools/kbdtool/main.c	(working copy)
@@ -19,6 +19,8 @@
 /* Input file */
 PCHAR gpszFileName;
 FILE* gfpInput;
+/* Base file: no path or extension */
+CHAR BaseFileName[256];
 
 /* Command-line parameters */
 BOOLEAN UnicodeFile, Verbose, NoLogo, FallbackDriver, SanityCheck, SourceOnly;
@@ -25,7 +27,25 @@
 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)
 {
@@ -166,6 +186,9 @@
 
     /* Save the file name */
     gpszFileName = argv[i];
+    
+    /* Set the base file name */
+    SetBaseFileName(gpszFileName);
 
     /* Open either as binary or text */
     OpenFlags = "rb";
Index: tools/kbdtool/output.c
===================================================================
--- tools/kbdtool/output.c	(revision 66665)
+++ tools/kbdtool/output.c	(working copy)
@@ -74,12 +74,12 @@
         else if (!AddZero)
         {
             /* Char value, in hex */
-            sprintf(gCharName, "0x%04x", Char);
+            sprintf(gCharName, "0x%x", Char);
         }
         else
         {
             /* Char value, C-style */
-            sprintf(gCharName, "\\x%04x", Char);
+            sprintf(gCharName, "\\x%x", Char);
         }
     }
 
@@ -166,7 +166,7 @@
         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 */
@@ -187,11 +187,38 @@
     else
     {
         /* Terminate the table */
-        fprintf(FileHandle, "    0   ,    NULL\n");
+        fprintf(FileHandle, "    { 0, NULL },\n");
     }
 }
 
 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 +242,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,
@@ -327,9 +356,9 @@
     PKEYNAME NextDescription, NextLanguage;
 
     /* Build the keyboard name and internal name */
-    strcpy(OutputFile, gKBDName);
-    strcat(OutputFile, ".RC");
-    strcpy(InternalName, gKBDName);
+    strcpy(OutputFile, BaseFileName);
+    strcat(OutputFile, ".rc");
+    strcpy(InternalName, BaseFileName);
     for (p = InternalName; *p; p++) *p = tolower(*p);
 
     /* Open it */
@@ -360,156 +389,15 @@
 
     /* Write the resource file header */
     fprintf(FileHandle,
-            "#include \"winver.h\"\r\n"
-            "1 VERSIONINFO\r\n"
-            " FILEVERSION       1,0,%d,%d\r\n"
-            " PRODUCTVERSION    1,0,%d,%d\r\n"
-            " FILEFLAGSMASK 0x3fL\r\n"
-            " FILEFLAGS 0x0L\r\n"
-            "FILEOS 0x40004L\r\n"
-            " FILETYPE VFT_DLL\r\n"
-            " FILESUBTYPE VFT2_DRV_KEYBOARD\r\n"
-            "BEGIN\r\n"
-            "    BLOCK \"StringFileInfo\"\r\n"
-            "    BEGIN\r\n"
-            "        BLOCK \"000004B0\"\r\n"
-            "        BEGIN\r\n"
-            "            VALUE \"CompanyName\",     \"%s\\0\"\r\n"
-            "            VALUE \"FileDescription\", \"%s Keyboard Layout\\0\"\r\n"
-            "            VALUE \"FileVersion\",     \"1, 0, %d, %d\\0\"\r\n",
-            gVersion,
-            gSubVersion,
-            gVersion,
-            gSubVersion,
-            gCompany,
+            "#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,
-            gVersion,
-            gSubVersion);
-
-    /* Continue writing it */
-    fprintf(FileHandle,
-            "            VALUE \"InternalName\",    \"%s (%d.%d)\\0\"\r\n"
-            "            VALUE \"ProductName\",\"%s\\0\"\r\n"
-            "            VALUE \"Release Information\",\"%s\\0\"\r\n"
-            "            VALUE \"LegalCopyright\",  \"%s\\0\"\r\n"
-            "            VALUE \"OriginalFilename\",\"%s\\0\"\r\n"
-            "            VALUE \"ProductVersion\",  \"1, 0, %d, %d\\0\"\r\n"
-            "        END\r\n"
-            "    END\r\n"
-            "    BLOCK \"VarFileInfo\"\r\n"
-            "    BEGIN\r\n"
-            "        VALUE \"Translation\", 0x0000, 0x04B0\r\n"
-            "    END\r\n"
-            "END\r\n",
             InternalName,
-            gVersion,
-            gSubVersion,
-            "Created by ReactOS KbdTool",
-            "Created by ReactOS KbdTool",
-            gCopyright,
-            InternalName,
-            gVersion,
-            gSubVersion);
-
-    /* Now check if we have a locale name */
-    Length = strlen(gLocaleName);
-    if (Length)
-    {
-        /* Write the stringtable header */
-        fprintf(FileHandle,
-                "\r\nSTRINGTABLE DISCARDABLE\r\nLANGUAGE %d, %d\r\n",
-                9,
-                1);
-        fprintf(FileHandle, "BEGIN\r\n");
-
-        /* Language or locale? */
-        if (strchr(gLocaleName, '\"'))
-        {
-            /* Write the language name */
-            fprintf(FileHandle, "    %d    %s\r\n", gStringIdForLanguageNames, gLocaleName);
-        }
-        else
-        {
-            /* Write the locale name */
-            fprintf(FileHandle, "    %d    \"%s\"\r\n", gStringIdForLocaleName, gLocaleName);
-        }
-
-        /* Terminate the entry */
-        fprintf(FileHandle, "END\r\n\r\n");
-    }
-
-    /* Check for description information */
-    while (DescriptionData)
-    {
-        /* Remember the next pointer */
-        NextDescription = DescriptionData->Next;
-
-        /* Write the header */
-        fprintf(FileHandle,
-                "\r\nSTRINGTABLE DISCARDABLE\r\nLANGUAGE %d, %d\r\n",
-                DescriptionData->Code & 0x3FF,
-                DescriptionData->Code >> 10);
-        fprintf(FileHandle, "BEGIN\r\n");
-
-        /* Quoted string or not? */
-        if (strchr(DescriptionData->Name, '\"'))
-        {
-            /* Write the description name */
-            fprintf(FileHandle, "    %d    %s\r\n", gStringIdForDescriptions, DescriptionData->Name);
-        }
-        else
-        {
-            /* Write the description name */
-            fprintf(FileHandle, "    %d    \"%s\"\r\n", gStringIdForDescriptions, DescriptionData->Name);
-        }
-
-        /* Terminate the entry */
-        fprintf(FileHandle, "END\r\n\r\n");
-
-        /* Free the allocation */
-        free(DescriptionData->Name);
-        free(DescriptionData);
-
-        /* Move to the next entry */
-        DescriptionData = NextDescription;
-    }
-
-    /* Check for language information */
-    while (LanguageData)
-    {
-        /* Remember the next pointer */
-        NextLanguage = LanguageData->Next;
-
-        /* Write the header */
-        fprintf(FileHandle,
-                "\r\nSTRINGTABLE DISCARDABLE\r\nLANGUAGE %d, %d\r\n",
-                LanguageData->Code & 0x3FF,
-                LanguageData->Code >> 10);
-        fprintf(FileHandle, "BEGIN\r\n");
-
-        /* Quoted string or not? */
-        if (strchr(LanguageData->Name, '\"'))
-        {
-            /* Write the language name */
-            fprintf(FileHandle, "    %d    %s\r\n", gStringIdForLanguageNames, LanguageData->Name);
-        }
-        else
-        {
-            /* Write the language name */
-            fprintf(FileHandle, "    %d    \"%s\"\r\n", gStringIdForLanguageNames, LanguageData->Name);
-        }
-
-        /* Terminate the entry */
-        fprintf(FileHandle, "END\r\n\r\n");
-
-        /* Free the allocation */
-        free(LanguageData->Name);
-        free(LanguageData);
-
-        /* Move to the next entry */
-        LanguageData = NextLanguage;
-    }
-
+            InternalName);
+    
     /* We're done! */
     fclose(FileHandle);
     return TRUE;
@@ -569,8 +457,8 @@
     PCHAR p;
 
     /* 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 +471,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 +496,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 +516,100 @@
     {
         /* 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");
-
-    /* Table continue */
+            "ROSDATA USHORT scancode_to_vk[] =\n"
+            "{\n"
+            "/*  00(Error) 01 */\n"
+            "    VK_EMPTY, VK_ESCAPE,\n\n"
+            "/* First Row*/\n"
+            "/*  02   03   04   05   06  07   08   09   0A   0B   0C (-)        0D (+)       0E    */\n"
+            "    '1', '2', '3', '4', '5','6', '7', '8', '9', '0', VK_OEM_MINUS, VK_OEM_PLUS, VK_BACK,\n\n");
     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");
-
-    /* Table continue */
+            "/*  Second Row */\n"
+            "/*  0F      10   11   12   13   14   15   16   17   18   19   1A ([)    1B (]) */\n"
+            "    VK_TAB, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', VK_OEM_4, VK_OEM_6,\n\n");
     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 */
+            "/*  1C         1D          */\n"
+            "    VK_RETURN, VK_LCONTROL,\n\n"
+            "/*  Third Row */\n"
+            "/*  1E   1F   20   21   22   23   24   25   26   27 (:)    28 (')    29 (~)*/\n"
+            "    'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', VK_OEM_1, VK_OEM_7, VK_OEM_3,\n\n");
     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");
-
+            "/*  Fourth row */\n"
+            "/*  2A         2B (\\)    2C   2D   2E   2F   30   31   32   33 (,)        32 (.)         35 (?)    36      */\n"
+            "    VK_LSHIFT, VK_OEM_5, 'Z', 'X', 'C', 'V', 'B', 'N', 'M', VK_OEM_COMMA, VK_OEM_PERIOD, VK_OEM_2, VK_RSHIFT,\n\n");
+    fprintf(FileHandle,
+            "/*  Bottom Row */\n"
+            "/*  37 (Keypad*) 38(L_ALT) 39        3A CapsLock */\n"
+            "    VK_MULTIPLY, VK_LMENU, VK_SPACE, VK_CAPITAL,\n\n");
+    fprintf(FileHandle,
+            "/*  Top Row */\n"
+            "/*  3B     3C     3D     3E     3F     40     41     42     43     44     */\n"
+            "    VK_F1, VK_F2, VK_F3, VK_F4, VK_F5, VK_F6, VK_F7, VK_F8, VK_F9, VK_F10,\n"
+            "/*  Locks */\n"
+            "/*  45                  46 */\n"
+            "    VK_NUMLOCK | KMEXT, VK_SCROLL | KBDMULTIVK,\n\n");
+    fprintf(FileHandle,
+            "/*  Number Pad */\n"
+            "/*  47 (KeyPad 7)    48(KeyPad 8)   49 (KeyPad 9)     4A (KeyPad -)  */\n"
+            "    VK_HOME | KNUMS, VK_UP | KNUMS, VK_PRIOR | KNUMS, VK_SUBTRACT,\n"
+            "/*  4B (KeyPad 4)    4C (KeyPad 5)     4D (KeyPad 6)     4E (KeyPad +)  */\n"
+            "    VK_LEFT | KNUMS, VK_CLEAR | KNUMS, VK_RIGHT | KNUMS, VK_ADD,\n"
+            "/*  4F (KeyPad 1)   50(KeyPad 2)     51 (KeyPad 3) */\n"
+            "    VK_END | KNUMS, VK_DOWN | KNUMS, VK_NEXT | KNUMS,\n"
+            "/*  52 (KeyPad 0)      53(KeyPad .) */\n"
+            "    VK_INSERT | KNUMS, VK_DELETE | KNUMS,\n\n"
+            "/*  54 (Print Screen)  */\n"
+            "    VK_SNAPSHOT,\n\n");
+    
+    fprintf(FileHandle,
+            "/*  Oddities, and the remaining standard F-Keys */\n"
+            "/*  55 (OEM?) 56 (OEM?)   57      58   */\n"
+            "    VK_EMPTY, VK_OEM_102, VK_F11, VK_F12,\n"
+            "/*  Keyboard Vendor Specific */\n"
+            "/*  59        5A        5B        5C        5D        5E        5F        60        61        62     */\n"
+            "    VK_CLEAR, VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY,\n"
+            "/*  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"
+            "    VK_HELP, VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18, VK_F19, VK_F20, VK_F21, VK_F22, VK_F23,\n");
+    
+    fprintf(FileHandle,
+            "/*  More Keyboard Vendor Specific */\n"
+            "/*  6F        70        71        72        73        74        75        76   */\n"
+            "    VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_F24,\n"
+            "/*  77        78        79        7A        7B        7C        7D        7E        7F     */\n"
+            "    VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY, VK_EMPTY,\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");
+            "    0\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 +625,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 +634,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 +653,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 +663,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 +680,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 +689,7 @@
     {
         /* Print out entry */
         fprintf(FileHandle,
-                "    { %-12s,   %-12s },\n",
+                "    { %-12s, %-12s },\n",
                 getVKName(Entry->VirtualKey, 1),
                 Entry->Name);
 
@@ -801,7 +703,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"
@@ -820,8 +722,8 @@
 
     /* 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"
@@ -890,15 +792,15 @@
 
 
     /* 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++)
@@ -905,7 +807,7 @@
     {
         /* 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);
     }
@@ -948,20 +850,20 @@
 
         /* 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|",
+        for (k = 2; k < i; k++) fprintf(FileHandle,  " %-9.9s|",
                                         StateLabel[ShiftStates[k]]);
 
         /* 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");
@@ -974,10 +876,9 @@
 
             /* 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';
 
@@ -1002,15 +903,16 @@
 
                 /* Print out the WCH_ name */
                 fprintf(FileHandle,
-                        ",%-9s",
+                        " %-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");
 
             /* Do we have any data at all? */
             if (*LineBuffer != '\0')
@@ -1033,65 +935,67 @@
         {
             /* 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");
     }
 
     /* 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 */
-    for (i = 3; i <= StateCount; i++)
+    fprintf(FileHandle,"ROSDATA VK_TO_WCHAR_TABLE vk_to_wchar_master_table[] =\n{\n");
+
+    /* Array of translation tables */
+    fprintf(FileHandle,
+            "    vk_master(1, keypad_numbers),\n");
+            
+    /* Loop states higher than 2 */
+    for (i = 2; i <= StateCount; i++)
     {
         /* Print out the extra tables */
         fprintf(FileHandle,
-                "    {  (PVK_TO_WCHARS1)aVkToWch%d, %d, sizeof(aVkToWch%d[0]) },\n",
+                "    vk_master(%d, key_to_chars_%dmod),\n",
                 i,
-                i,
                 i);
     }
 
-    /* Array of translation tables */
+    /* Terminate The 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"
+            "    { 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 +1007,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 +1020,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);
@@ -1149,47 +1053,35 @@
         exit(1);
     }
 
-    /* Main keyboard table descriptor type */
-    fprintf(FileHandle, "static ");
-
-    /* FIXME? */
-
     /* 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 +1091,7 @@
     /* Descriptor extended key name section */
     if (KeyNameExtData)
     {
-        fprintf(FileHandle, "    aKeyNamesExt,\n");
+        fprintf(FileHandle, "    (VSC_LPWSTR *) extended_key_names,\n");
     }
     else
     {
@@ -1209,33 +1101,29 @@
     /* 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",   "0");  /* FIXME */
 
     /* Descriptor ligature data comment */
-    fprintf(FileHandle, "    /*\n     * Ligatures\n     */\n    %d,\n", 0); /* FIXME */
+    fprintf(FileHandle, "    /* Ligatures */\n  %d,\n", 0); /* FIXME */
 
     /* Descriptor ligature data section */
     if (!LigatureData)
@@ -1245,8 +1133,8 @@
     }
     else
     {
-        fprintf(FileHandle, "    sizeof(aLigature[0]),\n");
-        fprintf(FileHandle, "    (PLIGATURE1)aLigature\n");
+        fprintf(FileHandle, "    sizeof(Ligature[0]),\n");
+        fprintf(FileHandle, "    (PLIGATURE1) Ligature\n");
     }
 
     /* Descriptor finish */
@@ -1254,10 +1142,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);
@@ -1286,8 +1174,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;
     }
@@ -1307,12 +1196,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 66665)
+++ 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)
@@ -136,10 +136,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 */
@@ -727,7 +727,6 @@
     ULONG ScanCodeCount = -1;
     PLAYOUTENTRY Entry;
     UCHAR CharacterType, LigatureChar;
-
     /* Zero out the layout */
     memset(LayoutData, 0, sizeof(LAYOUT));
 
@@ -899,6 +898,12 @@
                 Entry->OtherCharData[i] = 1;
             }
         }
+        /* Remove unused states */
+        while ((Entry->CharData[Entry->StateCount-1] == -1))
+        {
+            Entry->StateCount--;
+        }
+        
 
         /* Check for sanity checks */
         DPRINT1("]\n");
@@ -919,7 +924,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 */
Index: tools/kbdtool/test.klc
===================================================================
--- tools/kbdtool/test.klc	(revision 66665)
+++ 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
