#define _CRT_SECURE_NO_WARNINGS
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
/*
Using Virtual-Key constant instead of the old _KB_ constant.
For studying purpose only.
In a "read world" application simply define the constants
*/
int myGetch ();
void vk_constant();
void main() {
while(1) vk_constant();
}
void vk_constant() {
/*
Documentation about GetAsyncKeyState function can be found at:
http://msdn.microsoft.com/en-us/library/ms646293(VS.85).aspx
*/
int ch = myGetch();
if (GetAsyncKeyState(VK_F1)) { puts("You pressed F1"); }
else if (GetAsyncKeyState(VK_F2)) { puts("You pressed F2"); }
else if (GetAsyncKeyState(VK_F3)) { puts("You pressed F3"); }
else if (GetAsyncKeyState(VK_F4)) { puts("You pressed F4"); }
else if (GetAsyncKeyState(VK_F5)) { puts("You pressed F5"); }
else if (GetAsyncKeyState(VK_F6)) { puts("You pressed F6"); }
else if (GetAsyncKeyState(VK_F7)) { puts("You pressed F7"); }
else if (GetAsyncKeyState(VK_F8)) { puts("You pressed F8"); }
else if (GetAsyncKeyState(VK_F9)) { puts("You pressed F9"); }
else if (GetAsyncKeyState(VK_F10)) { puts("You pressed F10"); }
else if (GetAsyncKeyState(VK_F11)) { puts("You pressed F11"); }
else if (GetAsyncKeyState(VK_F12)) { puts("You pressed F12"); }
else if (GetAsyncKeyState(VK_NEXT)) { puts("You pressed Page Down"); }
else if (GetAsyncKeyState(VK_PRIOR)) { puts("You pressed Page Up"); }
else if (GetAsyncKeyState(VK_HOME)) { puts("You pressed Home"); }
else if (GetAsyncKeyState(VK_END)) { puts("You pressed End"); }
else if (GetAsyncKeyState(VK_UP)) { puts("You pressed Up Arrow"); }
else if (GetAsyncKeyState(VK_DOWN)) { puts("You pressed Down Arrow"); }
/*
.
.
.
Full Virtual-Key define list can be found at:
http://msdn.microsoft.com/en-us/library/ms646280(VS.85).aspx
*/
else { exit(0); }
}
int myGetch(void) {
/* _getch is used instead of getch (VS Compiler issues). */
int ch = _getch();
return (ch == 0 || ch == 0xE0)? _getch():ch;
}