#define _CRT_SECURE_NO_WARNINGS //#define _UNICODE //#define UNICODE #include #include #include #include #include #include #include #include #include #include #include void printGetKeyboardType(); void printGetAsyncKeyState(); void printGetKeyState(); void printGetKeyboardState(); void printGetCaretBlinkTime(); void printGetSystemMetrics(); void printShowCursor(); void printSetCaretBlinkTime(); int main(void) { // программа только для UNICODE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! const wchar_t str[] = L"help"; const wchar_t str1[] = L"exit"; const wchar_t str2[] = L"getKey"; const wchar_t str3[] = L"asyncKey"; const wchar_t str4[] = L"getK"; const wchar_t str5[] = L"getC"; const wchar_t str6[] = L"getS"; const wchar_t str7[] = L"showC"; const wchar_t str8[] = L"setC"; const wchar_t str9[] = L"type"; _setmode(_fileno(stdin), _O_U16TEXT); _setmode(_fileno(stdout), _O_U16TEXT); _setmode(_fileno(stderr), _O_U16TEXT); printGetKeyboardState(); wchar_t comand[50]; //setlocale(LC_ALL, ".UTF8"); _tprintf(_T("Здравствуйте, в связи с атакой террористов на мое воображение эта программа получила название \"Программа2\"\n")); while (1) { _tprintf(_T("Введите команду: ")); fgetws(comand,sizeof(comand), stdin); comand[wcslen(comand) - 1] = 0; if(!wcscmp(comand, str)) { _tprintf(_T("Тут должен быть список доступных команд, но его нет - как жаль(\n")); } else if (!wcscmp(comand, str2)) { printGetKeyState(); } else if (!wcscmp(comand, str3)) { printGetAsyncKeyState(); } else if (!wcscmp(comand, str5)) { printGetCaretBlinkTime(); } else if (!wcscmp(comand, str6)) { printGetSystemMetrics(); } else if (!wcscmp(comand, str7)) { printShowCursor(); } else if (!wcscmp(comand, str8)) { printSetCaretBlinkTime(); } else if (!wcscmp(comand, str9)) { printGetKeyboardType(); } else if (!wcscmp(comand, str1)) { _tprintf(_T("Произошел выход из программы!\n")); break; } else if (!wcscmp(comand, str4)) { printGetKeyboardState(); } else { _tprintf(_T("Неверная команда!\n")); } } return 0; } void printGetKeyboardType() { int type = GetKeyboardType(0); if (type == 0x4) { _tprintf(_T("Улучшенные клавиатуры со 101 или 102 клавишами (и совместимые) \n")); } else if (type == 0x7) { _tprintf(_T("Японская клавиатура\n")); } else if (type == 0x8) { _tprintf(_T("Корейская клавиатура\n")); } else { DWORD error = GetLastError(); _tprintf(_T("Неизвестный тип клавиатуры. Код ошибки: \n", error)); } } void printGetKeyState() { SHORT ks; while ((GetKeyState('S') & 0x8000) == 0) { } _tprintf(_T("Клавиша S нажата \n")); } void printGetAsyncKeyState() { while ((GetAsyncKeyState('R') & 0x8001) == 0) { } _tprintf(_T("Клавиша R нажата \n")); } void printGetKeyboardState() { _tprintf(_T("Нажми на SHIFT!\n")); BYTE keyboardState[256]; while (1) { GetKeyState(0); // чтобы все работало! GetKeyboardState(keyboardState); if (keyboardState[VK_LBUTTON] & 0x80) { // 0х80 это сравниваем старший бит в 16-й системе _tprintf(_T("Клавиша SHIFT нажата \n"), keyboardState); Sleep(100); // чтобы много не выводило при нажатии break; } } } void printGetCaretBlinkTime() { UINT blinkTime = GetCaretBlinkTime(); _tprintf(_T("Стандартный интервал времени мигания курсора: %ld\n"), blinkTime); } void printGetSystemMetrics() { int width = GetSystemMetrics(SM_CXSCREEN); int height = GetSystemMetrics(SM_CYSCREEN); _tprintf(_T("Разрешение экрана: %d на %d\n "), width, height); } void printShowCursor() { BOOL cursor = 0; int s; while ((GetAsyncKeyState(VK_ESCAPE) & 0x81) == 0) { if (cursor) { s = ShowCursor(TRUE); _tprintf(_T("Курсор видим %d"),s); } else { s = ShowCursor(FALSE); _tprintf(_T("Курсор не видим %d"),s); } cursor = !cursor; Sleep(1000); } } void printSetCaretBlinkTime() { UINT blinkTime = 2000; if (SetCaretBlinkTime(blinkTime)) { _tprintf(_T("Интервал времени мигания курсора изменен на: %dмс \n"), blinkTime); } else { _tprintf(_T("Не удалось изменить интервал мигания курсора \n")); } } void printClipCursor() { RECT clipRect = { 0, 0, 800, 600 }; //RECT fullClipRect = { 0, 0, 1920, 1200 }; if (ClipCursor(&clipRect)) { _tprintf(_T("Движение курсора ограничено %d по %d\n"), clipRect.right, clipRect.bottom); Sleep(5000); //_tprintf(_T("Движение курсора увеличено %d по %d\n"), fullClipRect.right, fullClipRect.bottom); ClipCursor(NULL); } else { _tprintf(_T("Какая-то лажа\n")); } }