Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 20th, 2010 | Syntax: C | Size: 2.01 KB | Hits: 103 | Expires: Never
Copy text to clipboard
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <windows.h>
  6.  
  7. /*
  8.         Using Virtual-Key constant instead of the old _KB_ constant.
  9.         For studying purpose only.
  10.         In a "read world" application simply define the constants
  11. */
  12.  
  13. int myGetch ();
  14. void vk_constant();
  15.  
  16. void main() {
  17.         while(1) vk_constant();
  18. }
  19.  
  20. void vk_constant() {
  21.         /*
  22.                 Documentation about GetAsyncKeyState function can be found at:
  23.                 http://msdn.microsoft.com/en-us/library/ms646293(VS.85).aspx
  24.         */
  25.         int ch = myGetch();
  26.         if (GetAsyncKeyState(VK_F1)) { puts("You pressed F1"); }
  27.         else if (GetAsyncKeyState(VK_F2)) { puts("You pressed F2"); }
  28.         else if (GetAsyncKeyState(VK_F3)) { puts("You pressed F3"); }
  29.         else if (GetAsyncKeyState(VK_F4)) { puts("You pressed F4"); }
  30.         else if (GetAsyncKeyState(VK_F5)) { puts("You pressed F5"); }
  31.         else if (GetAsyncKeyState(VK_F6)) { puts("You pressed F6"); }
  32.         else if (GetAsyncKeyState(VK_F7)) { puts("You pressed F7"); }
  33.         else if (GetAsyncKeyState(VK_F8)) { puts("You pressed F8"); }
  34.         else if (GetAsyncKeyState(VK_F9)) { puts("You pressed F9"); }
  35.         else if (GetAsyncKeyState(VK_F10)) { puts("You pressed F10"); }
  36.         else if (GetAsyncKeyState(VK_F11)) { puts("You pressed F11"); }
  37.         else if (GetAsyncKeyState(VK_F12)) { puts("You pressed F12"); }
  38.         else if (GetAsyncKeyState(VK_NEXT)) { puts("You pressed Page Down"); }
  39.         else if (GetAsyncKeyState(VK_PRIOR)) { puts("You pressed Page Up"); }
  40.         else if (GetAsyncKeyState(VK_HOME)) { puts("You pressed Home"); }
  41.         else if (GetAsyncKeyState(VK_END)) { puts("You pressed End"); }
  42.         else if (GetAsyncKeyState(VK_UP)) { puts("You pressed Up Arrow"); }
  43.         else if (GetAsyncKeyState(VK_DOWN)) { puts("You pressed Down Arrow"); }
  44.         /*
  45.                 .
  46.                 .
  47.                 .
  48.                 Full Virtual-Key define list can be found at:
  49.                 http://msdn.microsoft.com/en-us/library/ms646280(VS.85).aspx
  50.         */
  51.         else { exit(0); }
  52. }
  53.  
  54. int myGetch(void) {
  55.     /* _getch is used instead of getch (VS Compiler issues). */
  56.         int ch = _getch();
  57.         return (ch == 0 || ch == 0xE0)? _getch():ch;
  58. }