#include #include #include #include "../../headers_c/newpluginapi.h" #include "../../headers_c/m_utils.h" HANDLE hKbdDev[10] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE}; #define MAX_KBDHANDLES 10 BOOL isWindowsNT(void) { OSVERSIONINFOEX osvi; BOOL bOsVersionInfoEx; ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); if(!(bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *) &osvi))) { osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if(!GetVersionEx((OSVERSIONINFO *)&osvi)) osvi.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS; } return osvi.dwPlatformId==VER_PLATFORM_WIN32_NT; } BOOL OpenKeyboardDevice() { int i = 0; char aux1[MAX_PATH+1], aux2[MAX_PATH+1]; do { mir_snprintf(aux1, sizeof(aux1), "Kbd%d", i); mir_snprintf(aux2, sizeof(aux2), "\\Device\\KeyboardClass%d", i); DefineDosDevice(DDD_RAW_TARGET_PATH, aux1, aux2); mir_snprintf(aux1, sizeof(aux1), "\\\\.\\Kbd%d", i); hKbdDev[i] = CreateFile(aux1, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); } while (hKbdDev[i] != INVALID_HANDLE_VALUE && ++i < MAX_KBDHANDLES); return hKbdDev[0] != INVALID_HANDLE_VALUE; } void CloseKeyboardDevice() { int i; for (i = 0; i < MAX_KBDHANDLES && hKbdDev[i] != INVALID_HANDLE_VALUE; i++) CloseHandle(hKbdDev[i]); } int main(void) { char buffer[MAX_PATH+1]; if (!isWindowsNT()) { printf("This application is meant for NT based systems\n"); return 0; } if (QueryDosDevice("Kbd0", buffer, sizeof(buffer))) { printf("Device already created\n"); return 0; } if (!OpenKeyboardDevice()) { printf("Device could not be created\n"); return 1; } CloseKeyboardDevice(); printf("Device succesfully created\n"); return 0; }