Guest User

Untitled

a guest
Mar 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.94 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <cstring>
  3. #include <iostream>
  4. #include <stdio.h>
  5. #include <conio.h>
  6. #include <windows.h>
  7. #include <winuser.h>
  8.  
  9.  
  10. #define STR_SIZE 256
  11. #define BUFSIZE 65535
  12. #define SHIFTED 0x8000
  13.  
  14.  
  15. int main() {
  16.  
  17. setlocale(LC_ALL, "rus");
  18. HANDLE hIn, hOut;
  19. DWORD size = STR_SIZE;
  20. char result[STR_SIZE];
  21.  
  22. FreeConsole();
  23. AllocConsole();
  24. SetConsoleOutputCP(1251);
  25.  
  26. hIn = GetStdHandle(STD_INPUT_HANDLE);
  27. hOut = GetStdHandle(STD_OUTPUT_HANDLE);
  28.  
  29. GetDC(NULL); // дескриптор стола
  30. POINT p; // структура для координат
  31. COORD cord; // структура COORD, которая указывает позицию курсора
  32.  
  33. cord.X = 0; // координата X структуры COORD
  34. cord.Y = 0; // координата Y структуры COORD
  35.  
  36. //------------------------------------------------------------------
  37.  
  38.  
  39. HWND hwndMain;
  40. HACCEL haccl;
  41. UINT uMsg;
  42. UINT wParam;
  43. LONG lParam;
  44. HWND hwnd;
  45. MSG msg;
  46.  
  47. switch (wParam)
  48. {
  49. case 0x10:
  50.  
  51. /*SHIFT key.*/
  52. printf("SHIFT pressed", wParam);
  53.  
  54. break;
  55.  
  56. case 0x11:
  57.  
  58. /*CTRL key.*/
  59. printf("CTRL pressed", wParam);
  60.  
  61. break;
  62. case 0x12:
  63.  
  64. /*ALT key. */
  65. printf("ALT pressed", wParam);
  66.  
  67. break;
  68. default:
  69.  
  70. printf("OTHER pressed", wParam);
  71. /* Обработка воспроизводимых символов. */
  72.  
  73. break;
  74. }
  75.  
  76. while (GetMessage(&msg, (HWND)NULL, 0, 0))
  77. {
  78. if (TranslateAccelerator(hwndMain, haccl, &msg) == 0)
  79. {
  80. TranslateMessage(&msg);
  81. DispatchMessage(&msg);
  82. }
  83. }
  84. //-----------------------------------------------------------------------------
  85.  
  86. while (1) {
  87. wsprintf(result, "Позиция курсора: ");
  88. WriteConsole(hOut, result, strlen(result), nullptr, nullptr);
  89. GetCursorPos(&p);
  90. wsprintf(result, "x = %4ld, y = %4ldrn", p.x, p.y);
  91. WriteConsole(hOut, result, strlen(result), nullptr, nullptr);
  92. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), cord);
  93. }
  94. return 0;
  95. }
  96.  
  97. #include "stdafx.h"
  98. #include <stdlib.h>
  99. #include <locale.h>
  100. #include <stdio.h>
  101. #include <windows.h>
  102. #include <tchar.h>
  103.  
  104. VOID ErrorExit(LPCSTR);
  105. VOID KeyEventProc(KEY_EVENT_RECORD);
  106. VOID MouseEventProc(MOUSE_EVENT_RECORD);
  107.  
  108. #define STR_SIZE 256
  109. #define BUFSIZE 65535
  110. #define SHIFTED 0x8000
  111.  
  112. HANDLE hStdin;
  113. HANDLE hOut;
  114. DWORD fdwSaveOldMode;
  115.  
  116. DWORD scan = 0; //скан-код последней клавиши
  117. wchar_t code = 0; //код символа последней клавиши
  118. bool alt, ctrl, shift; //состояние управляющих клавиш
  119.  
  120. void PrintData() {
  121. DWORD size = STR_SIZE;
  122. char result[STR_SIZE];
  123.  
  124. POINT p; // структура для координат
  125. COORD cord; // структура COORD, которая указывает позицию курсора
  126.  
  127. cord.X = 0; // координата X структуры COORD
  128. cord.Y = 0; // координата Y структуры COORD
  129.  
  130. SetConsoleCursorPosition(hOut, cord);
  131. wsprintf(result, "Позиция курсора: ");
  132. WriteConsole(hOut, result, strlen(result), nullptr, nullptr);
  133. GetCursorPos(&p);
  134. wsprintf(result, "x = %4ld, y = %4ldrn", p.x, p.y);
  135. WriteConsole(hOut, result, strlen(result), nullptr, nullptr);
  136.  
  137. if (scan != 0) {
  138. wsprintf(result, "Последняя нажатая клавишаnScan code: %4urn", (UINT)scan);
  139. WriteConsole(hOut, result, strlen(result), nullptr, nullptr);
  140.  
  141. wsprintf(result, "Character code: %4urn", (UINT)code);
  142. WriteConsole(hOut, result, strlen(result), nullptr, nullptr);
  143.  
  144.  
  145. if (ctrl) wsprintf(result, "CTRL:(+) "); else wsprintf(result, "CTRL:(-) ");
  146. WriteConsole(hOut, result, strlen(result), nullptr, nullptr);
  147.  
  148. if (shift) wsprintf(result, "SHIFT:(+) "); else wsprintf(result, "SHIFT:(-) ");
  149. WriteConsole(hOut, result, strlen(result), nullptr, nullptr);
  150.  
  151. if (alt) wsprintf(result, "ALT:(+) "); else wsprintf(result, "ALT:(-) ");
  152. WriteConsole(hOut, result, strlen(result), nullptr, nullptr);
  153. }
  154. }
  155.  
  156. int main()
  157. {
  158. SetConsoleCP(1251);
  159. SetConsoleOutputCP(1251);
  160. DWORD cNumRead, fdwMode, i;
  161. INPUT_RECORD irInBuf[128];
  162.  
  163. // Get the standard input handle.
  164.  
  165. hStdin = GetStdHandle(STD_INPUT_HANDLE);
  166. hOut = GetStdHandle(STD_OUTPUT_HANDLE);
  167.  
  168. // Save the current input mode, to be restored on exit.
  169.  
  170. if (!GetConsoleMode(hStdin, &fdwSaveOldMode))
  171. ErrorExit("GetConsoleMode");
  172.  
  173. // Enable the window and mouse input events.
  174.  
  175. fdwMode = ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT;
  176. if (!SetConsoleMode(hStdin, fdwMode))
  177. ErrorExit("SetConsoleMode");
  178.  
  179. // Loop to read and handle input events.
  180.  
  181. while (1)
  182. {
  183. // Wait for the events.
  184.  
  185. if (!ReadConsoleInput(
  186. hStdin, // input buffer handle
  187. irInBuf, // buffer to read into
  188. 128, // size of read buffer
  189. &cNumRead)) // number of records read
  190. ErrorExit("ReadConsoleInput");
  191.  
  192. // Dispatch the events to the appropriate handler.
  193.  
  194. for (i = 0; i < cNumRead; i++)
  195. {
  196. switch (irInBuf[i].EventType)
  197. {
  198. case KEY_EVENT: // keyboard input
  199. KeyEventProc(irInBuf[i].Event.KeyEvent);
  200. break;
  201.  
  202. case MOUSE_EVENT: // mouse input
  203. MouseEventProc(irInBuf[i].Event.MouseEvent);
  204. break;
  205.  
  206. case WINDOW_BUFFER_SIZE_EVENT:
  207. case FOCUS_EVENT:
  208. case MENU_EVENT:
  209. break;
  210. }
  211. }
  212. }
  213.  
  214. // Restore input mode on exit.
  215.  
  216. SetConsoleMode(hStdin, fdwSaveOldMode);
  217.  
  218. return 0;
  219. }
  220.  
  221.  
  222. VOID KeyEventProc(KEY_EVENT_RECORD ker)
  223. {
  224.  
  225. if (ker.bKeyDown) {
  226. scan = ker.wVirtualScanCode;
  227. code = ker.uChar.UnicodeChar;
  228.  
  229. if ((ker.dwControlKeyState & SHIFT_PRESSED) > 0) shift = true; else shift = false;
  230.  
  231. if ((ker.dwControlKeyState & LEFT_ALT_PRESSED) > 0 ||
  232. (ker.dwControlKeyState & RIGHT_ALT_PRESSED) > 0) alt = true;
  233. else alt = false;
  234.  
  235. if ((ker.dwControlKeyState & LEFT_CTRL_PRESSED) > 0 ||
  236. (ker.dwControlKeyState & RIGHT_CTRL_PRESSED) > 0) ctrl = true;
  237. else ctrl = false;
  238.  
  239. PrintData();
  240. }
  241.  
  242. }
  243.  
  244. VOID MouseEventProc(MOUSE_EVENT_RECORD mer)
  245. {
  246. if (mer.dwEventFlags == MOUSE_MOVED) {
  247. PrintData();
  248. }
  249. }
  250.  
  251. VOID ErrorExit(LPCSTR lpszMessage)
  252. {
  253. fprintf(stderr, "%sn", lpszMessage);
  254.  
  255. // Restore input mode on exit.
  256. SetConsoleMode(hStdin, fdwSaveOldMode);
  257.  
  258. ExitProcess(0);
  259. }
  260.  
  261. #include <stdlib.h>
  262. #include <locale.h>
  263. #include <stdio.h>
  264. #include <windows.h>
  265. #include <tchar.h>
  266.  
  267. VOID ErrorExit(LPSTR);
  268. VOID KeyEventProc(KEY_EVENT_RECORD);
  269. VOID MouseEventProc(MOUSE_EVENT_RECORD);
  270.  
  271. #define STR_SIZE 256
  272. #define BUFSIZE 65535
  273. #define SHIFTED 0x8000
  274.  
  275. HANDLE hStdin;
  276. HANDLE hOut;
  277. DWORD fdwSaveOldMode;
  278.  
  279. DWORD scan=0; //скан-код последней клавиши
  280. wchar_t code=0; //код символа последней клавиши
  281. bool alt,ctrl,shift; //состояние управляющих клавиш
  282.  
  283. void PrintData(){
  284.  
  285. DWORD size = STR_SIZE;
  286. TCHAR result[STR_SIZE];
  287.  
  288. POINT p; // структура для координат
  289. COORD cord; // структура COORD, которая указывает позицию курсора
  290.  
  291. cord.X = 0; // координата X структуры COORD
  292. cord.Y = 0; // координата Y структуры COORD
  293.  
  294. SetConsoleCursorPosition(hOut, cord);
  295. wsprintf(result, L"Позиция курсора: ");
  296. WriteConsole(hOut, result, wcslen(result), nullptr, nullptr);
  297. GetCursorPos(&p);
  298. wsprintf(result, L"x = %4ld, y = %4ldrn", p.x, p.y);
  299. WriteConsole(hOut, result, wcslen(result), nullptr, nullptr);
  300.  
  301. if(scan!=0){
  302. wsprintf(result, L"Последняя нажатая клавишаnScan code: %4u, Character code: %4urn", (UINT)scan,(UINT)code);
  303. WriteConsole(hOut, result, wcslen(result), nullptr, nullptr);
  304.  
  305. if(ctrl) wsprintf(result,L"CTRL:(+) "); else wsprintf(result,L"CTRL:(-) ");
  306. WriteConsole(hOut, result, wcslen(result), nullptr, nullptr);
  307.  
  308. if(shift) wsprintf(result,L"SHIFT:(+) "); else wsprintf(result,L"SHIFT:(-) ");
  309. WriteConsole(hOut, result, wcslen(result), nullptr, nullptr);
  310.  
  311. if(alt) wsprintf(result,L"ALT:(+) "); else wsprintf(result,L"ALT:(-) ");
  312. WriteConsole(hOut, result, wcslen(result), nullptr, nullptr);
  313. }
  314.  
  315. }
  316.  
  317.  
  318. int main()
  319. {
  320. setlocale(LC_ALL, "Russian");
  321. DWORD cNumRead, fdwMode, i;
  322. INPUT_RECORD irInBuf[128];
  323.  
  324. // Get the standard input handle.
  325.  
  326. hStdin = GetStdHandle(STD_INPUT_HANDLE);
  327. hOut = GetStdHandle(STD_OUTPUT_HANDLE);
  328.  
  329. // Save the current input mode, to be restored on exit.
  330.  
  331. if (! GetConsoleMode(hStdin, &fdwSaveOldMode) )
  332. ErrorExit("GetConsoleMode");
  333.  
  334. // Enable the window and mouse input events.
  335.  
  336. fdwMode = ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT;
  337. if (! SetConsoleMode(hStdin, fdwMode) )
  338. ErrorExit("SetConsoleMode");
  339.  
  340. // Loop to read and handle input events.
  341.  
  342. while (1)
  343. {
  344. // Wait for the events.
  345.  
  346. if (! ReadConsoleInput(
  347. hStdin, // input buffer handle
  348. irInBuf, // buffer to read into
  349. 128, // size of read buffer
  350. &cNumRead) ) // number of records read
  351. ErrorExit("ReadConsoleInput");
  352.  
  353. // Dispatch the events to the appropriate handler.
  354.  
  355. for (i = 0; i < cNumRead; i++)
  356. {
  357. switch(irInBuf[i].EventType)
  358. {
  359. case KEY_EVENT: // keyboard input
  360. KeyEventProc(irInBuf[i].Event.KeyEvent);
  361. break;
  362.  
  363. case MOUSE_EVENT: // mouse input
  364. MouseEventProc(irInBuf[i].Event.MouseEvent);
  365. break;
  366.  
  367. case WINDOW_BUFFER_SIZE_EVENT:
  368. case FOCUS_EVENT:
  369. case MENU_EVENT:
  370. break;
  371. }
  372. }
  373. }
  374.  
  375. // Restore input mode on exit.
  376.  
  377. SetConsoleMode(hStdin, fdwSaveOldMode);
  378.  
  379. return 0;
  380. }
  381.  
  382.  
  383. VOID KeyEventProc(KEY_EVENT_RECORD ker)
  384. {
  385.  
  386. if(ker.bKeyDown){
  387. scan=ker.wVirtualScanCode;
  388. code=ker.uChar.UnicodeChar;
  389.  
  390. if((ker.dwControlKeyState & SHIFT_PRESSED) > 0) shift=true; else shift=false;
  391.  
  392. if((ker.dwControlKeyState & LEFT_ALT_PRESSED) > 0 ||
  393. (ker.dwControlKeyState & RIGHT_ALT_PRESSED) > 0) alt=true;
  394. else alt=false;
  395.  
  396. if((ker.dwControlKeyState & LEFT_CTRL_PRESSED) > 0 ||
  397. (ker.dwControlKeyState & RIGHT_CTRL_PRESSED) > 0) ctrl=true;
  398. else ctrl=false;
  399.  
  400. PrintData();
  401. }
  402.  
  403. }
  404.  
  405. VOID MouseEventProc(MOUSE_EVENT_RECORD mer)
  406. {
  407. if(mer.dwEventFlags == MOUSE_MOVED){
  408. PrintData();
  409. }
  410. }
  411.  
  412. VOID ErrorExit (LPSTR lpszMessage)
  413. {
  414. fprintf(stderr, "%sn", lpszMessage);
  415.  
  416. // Restore input mode on exit.
  417. SetConsoleMode(hStdin, fdwSaveOldMode);
  418.  
  419. ExitProcess(0);
  420. }
Add Comment
Please, Sign In to add comment