int findvkey(const char* name, int* key)
{
/* symbol table record */
typedef struct tokentable {
char *token;
int vkey;
} tokentable;
/* global symbol table */
static tokentable tbl[] = {
"BAC", VK_BACK,
"BS" , VK_BACK,
"BKS", VK_BACK,
"BRE", VK_CANCEL,
"CAP", VK_CAPITAL,
"DEL", VK_DELETE,
"DOW", VK_DOWN,
"END", VK_END,
"ENT", VK_RETURN,
"ESC", VK_ESCAPE,
"HEL", VK_HELP,
"HOM", VK_HOME,
"INS", VK_INSERT,
"LEF", VK_LEFT,
"NUM", VK_NUMLOCK,
"PGD", VK_NEXT,
"PGU", VK_PRIOR,
"PRT", VK_SNAPSHOT,
"RIG", VK_RIGHT,
"SCR", VK_SCROLL,
"TAB", VK_TAB,
"UP", VK_UP,
"F1", VK_F1,
"F2", VK_F2,
"F3", VK_F3,
"F4", VK_F4,
"F5", VK_F5,
"F6", VK_F6,
"F7", VK_F7,
"F8", VK_F8,
"F9", VK_F9,
"F10", VK_F10,
"F11", VK_F11,
"F12", VK_F12,
"F13", VK_F13,
"F14", VK_F14,
"F15", VK_F15,
"F16", VK_F16,
"F17", VK_F17,
"F18", VK_F18,
"F19", VK_F19,
"F20", VK_F20,
"F21", VK_F21,
"F22", VK_F22,
"F23", VK_F23,
"F24", VK_F24,
"SPC", VK_SPACE,
"SPA", VK_SPACE,
"LWI", VK_LWIN,
"RWI", VK_RWIN,
"APP", VK_APPS,
};
int i;
for (i=0;i<sizeof(tbl)/sizeof(tokentable);i++) {
if (strcmp(tbl[i].token, name)==0) {
*key=tbl[i].vkey;
return 1;
}
}
return 0;
}
BOOL
IsKeyPressed(name)
char* name;
CODE:
int vkey;
int found;
int len = strlen(name);
if (len >= 3)
name[3]=NUL;
found = findvkey(name, &vkey);
if (found) {
OutputDebugString("Trying key\n");
RETVAL = GetAsyncKeyState(vkey);
} else if (strlen(name)==1 && (isdigit(*name) || isalpha(*name))) {
OutputDebugString("Trying alphanum\n");
RETVAL = GetAsyncKeyState(toupper(*name));
}else {
OutputDebugString("No key\n");
RETVAL = 0;
}
OUTPUT:
RETVAL