diff --git a/reactos/tools/kbdtool/kbdtool.h b/reactos/tools/kbdtool/kbdtool.h index de6a6127f47..5b2dd30c2eb 100644 --- a/reactos/tools/kbdtool/kbdtool.h +++ b/reactos/tools/kbdtool/kbdtool.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #define KEYWORD_COUNT 17 @@ -65,11 +66,22 @@ typedef struct tagLAYOUT LAYOUTENTRY Entry[110]; } LAYOUT, *PLAYOUT; +PCHAR +getVKName( + IN ULONG VirtualKey, + IN BOOLEAN Prefix +); + extern BOOLEAN Verbose, UnicodeFile, SanityCheck, FallbackDriver; extern PCHAR gpszFileName; extern FILE* gfpInput; extern VKNAME VKName[]; extern SCVK ScVk[]; extern LAYOUT g_Layout; +extern CHAR gVKeyName[32]; +extern CHAR gKBDName[10]; +extern CHAR gCopyright[256]; +extern CHAR gDescription[256]; +extern ULONG gVersion, gSubVersion; /* EOF */ diff --git a/reactos/tools/kbdtool/output.c b/reactos/tools/kbdtool/output.c index 845ce59a66e..c6856f69fd6 100644 --- a/reactos/tools/kbdtool/output.c +++ b/reactos/tools/kbdtool/output.c @@ -12,13 +12,133 @@ /* GLOBALS ********************************************************************/ +time_t Clock; +struct tm *Now; + /* FUNCTIONS ******************************************************************/ BOOLEAN kbd_h(IN PLAYOUT Layout) { - /* FIXME: Stub */ - return FALSE; + CHAR OutputFile[13]; + FILE *FileHandle; + ULONG i; + CHAR UndefChar; + USHORT SubCode; + + /* Build the keyboard name */ + strcpy(OutputFile, gKBDName); + strcat(OutputFile, ".H"); + + /* Open it */ + FileHandle = fopen(OutputFile, "wt"); + if (!FileHandle) + { + /* Fail */ + printf(" %12s : can't open for write.\n", OutputFile); + return FALSE; + } + + /* Print the module header */ + fprintf(FileHandle, + "/****************************** Module Header ******************************\\\n" + "* Module Name: %s\n*\n* keyboard layout header\n" + "*\n" + "* Copyright (c) 2009, ReactOS Foundation\n" + "*\n" + "* Various defines for use by keyboard input code.\n*\n* History:\n" + "*\n" + "* created by KBDTOOL v%d.%02d %s*\n" + "\\***************************************************************************/\n\n", + OutputFile, + gVersion, + gSubVersion, + asctime(Now)); + + /* Print out the includes and defines */ + fprintf(FileHandle, + "/*\n" + " * kbd type should be controlled by cl command-line argument\n" + " *\\n" + "#define KBD_TYPE 4\n\n" + "/*\n" + "* Include the basis of all keyboard table values\n" + "*/\n" + "#include \"kbd.h\"\n"); + + /* Now print out the virtual key conversion table */ + fprintf(FileHandle, + "/***************************************************************************\\\n" + "* The table below defines the virtual keys for various keyboard types where\n" + "* the keyboard differ from the US keyboard.\n" + "*\n" + "* _EQ() : all keyboard types have the same virtual key for this scancode\n" + "* _NE() : different virtual keys for this scancode, depending on kbd type\n" + "*\n" + "* +------+ +----------+----------+----------+----------+----------+----------+\n" + "* | Scan | | kbd | kbd | kbd | kbd | kbd | kbd |\n" + "* | code | | type 1 | type 2 | type 3 | type 4 | type 5 | type 6 |\n" + "\\****+-------+_+----------+----------+----------+----------+----------+----------+*/\n\n"); + + /* Loop all keys */ + for (i = 0; i < 110; i++) + { + /* Check if we processed this key */ + if (Layout->Entry[i].Processed) + { + /* Check if it redefined a virtual key */ + if (Layout->Entry[i].VirtualKey != Layout->Entry[i].OriginalVirtualKey) + { + /* Do we have a subcode? */ + SubCode = Layout->Entry[i].ScanCode & 0xFF00; + if (SubCode) + { + /* Which kind is it? */ + if (SubCode == 0xE000) + { + /* Extended 0 */ + UndefChar = 'X'; + } + else + { + /* Illegal */ + if (SubCode != 0xE100) + { + /* Unrecognized */ + printf("Weird scancode value %04x: expected xx, E0xx, or E1xx\n", SubCode); + exit(1); + } + + /* Extended 1 */ + UndefChar = 'Y'; + } + } + else + { + /* Normal key */ + UndefChar = 'T'; + } + + /* Print out the virtual key redefinition */ + fprintf(FileHandle, + "#undef %c%02X\n#define %c%02X _EQ(%43s%23s\n", + UndefChar, + Layout->Entry[i].ScanCode, + UndefChar, + Layout->Entry[i].ScanCode, + getVKName(Layout->Entry[i].VirtualKey, 0), + ")"); + } + } + } + + /* Cleanup and close */ + fprintf(FileHandle,"\n"); + fclose(FileHandle); + + /* We made it */ + return TRUE; + } BOOLEAN @@ -64,7 +184,11 @@ DoOutput(IN ULONG StateCount, IN PKEYNAME KeyNameDeadData) { ULONG FailureCode = 0; - + + /* Take the time */ + time(&Clock); + Now = localtime(&Clock); + /* Check if this just a fallback driver*/ if (!FallbackDriver) { diff --git a/reactos/tools/kbdtool/parser.c b/reactos/tools/kbdtool/parser.c index ead5f63f9a0..4bf04772c90 100644 --- a/reactos/tools/kbdtool/parser.c +++ b/reactos/tools/kbdtool/parser.c @@ -19,6 +19,7 @@ CHAR gCopyright[256]; CHAR gDescription[256]; CHAR gCompany[256]; CHAR gLocaleName[256]; +CHAR gVKeyName[32]; ULONG gID = 0; ULONG gKbdLayoutVersion; LAYOUT g_Layout; @@ -60,6 +61,53 @@ isKeyWord(PCHAR p) return i; } +PCHAR +getVKName(IN ULONG VirtualKey, + IN BOOLEAN Prefix) +{ + ULONG i; + + /* Loop for standard virtual key */ + if (((VirtualKey >= 'A') && (VirtualKey <= 'Z')) || + ((VirtualKey >= '0') && (VirtualKey <= '9'))) + { + /* Fill out the name */ + gVKeyName[0] = '\''; + gVKeyName[1] = VirtualKey; + gVKeyName[2] = '\''; + gVKeyName[3] = '\0'; + return gVKeyName; + } + + /* Check if a prefix is required */ + if (Prefix) + { + /* Add it */ + strcpy(gVKeyName, "VK_"); + } + else + { + /* Otherwise, don't add anything */ + strcpy(gVKeyName, ""); + } + + /* Loop all virtual keys */ + for (i = 0; i < 36; i++) + { + /* Check if this key matches */ + if (VKName[i].VirtualKey == VirtualKey) + { + /* Copy the key's name into the buffer */ + strcat(gVKeyName, VKName[i].Name); + return gVKeyName; + } + } + + /* If we got here, then we failed, so print out an error name */ + strcpy(gVKeyName, "#ERROR#"); + return gVKeyName; +} + ULONG getVKNum(IN PCHAR p) {