From cb4a46e7fbe62d788e66ed6121c717a2d22a4d7c Mon Sep 17 00:00:00 2001 From: watcherhd Date: Thu, 21 Apr 2011 14:14:52 +0000 Subject: svn.miranda.im is moving to a new home! git-svn-id: http://miranda-plugins.googlecode.com/svn/trunk@7 e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb --- kbdnotify/KnowYourRights/knowyourrights.c | 77 +++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 kbdnotify/KnowYourRights/knowyourrights.c (limited to 'kbdnotify/KnowYourRights/knowyourrights.c') diff --git a/kbdnotify/KnowYourRights/knowyourrights.c b/kbdnotify/KnowYourRights/knowyourrights.c new file mode 100644 index 0000000..8b83985 --- /dev/null +++ b/kbdnotify/KnowYourRights/knowyourrights.c @@ -0,0 +1,77 @@ +#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; +} -- cgit v1.2.3