-
Key press in windows
Is there really no other way of getting key press input than with WM_KEYDOWN and virtual keys? It's rather cumbersome to work with I think. Is there a third party solution around somewhere?
I've always been using IUP, when building GUIs and they have made it pretty simple. All printable keys are mapped to their corresponding ascii value, and it's very easy to check if the control- or some other key is pressed at the same time.
Code:
switch (kp) {
case K_A: // a
break;
case K_sA: // Shift + a = A
break;
case K_cF1: // Ctrl + F1
break;
case K_mF1: // Alt + F1
break;
}
EDIT: Programming in C...
-
You should probably build accelerator tables...
Using Keyboard Accelerators (Windows)
Basically you build an accelerator table in your resource editor. Then you add TranslateAccelerator() to your message dispatcher and use LoadAccelerator() to load the table for it. From there on every mapped keystroke is translated into a WM_COMMAND message... with a bit of cleverness you can make these the same values as your buttons and menus emit, making a keypress no different than clicking a button...
If you still insist on doing it the hard way ;) you can add TranslateMessage() to your message dispatcher and handle WM_CHAR messages... These carry the ASCII values...
-
I don't know if this will help, but maybe...
Code:
static int keyCache[128];
void KeysInit( void )
{
int i;
for ( i = 0; i < 128; i++ )
keyCache[i] = 0;
}
int is_key_down(char vk)
{
return !(GetAsyncKeyState(vk) & 0x8000) ? keyCache[vk] = 0 : 1;
}
int was_key_pressed(char vk)
{
if(is_key_down(vk))
{
if(!keyCache[vk])
return keyCache[vk] = 1;
return 0;
}
return keyCache[vk] = 0;
}