input routine
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vkcode) & 0x8000) ? 1:0)
#define KEYUP(vk_code) ((GetAsyncKeyState(vkcode) & 0x8000) ? 0:1)
Now just use a simple if statement like this
if (KEYDOWN(VK_A) ) { //stuff here }
or you could use direct input which you can read about in the direct X SDK help file, where you'll find tutorials.
[This message has been edited by evaclear (edited November 22, 1999).]
I've since implemented direct input in my program, but it crashes every time I try to get immediate input from the keyboard. Its all set up seemingly correctly, as described in the tutorial, but when I insert a GetDeviceState in my main routine, the program crashes, with an access violation. Any ideas?
- Splat
I'm using quite an early version of VCC - version 4.1. Is this likely to be a problem?
If i remember correctly immediate keyboard data is quite easy to set up(alot easier than buffered) here is what i used for directinput
LPDIRECTINPUT g_pDI = NULL;
LPDIRECTINPUTDEVICE Keyboard = NULL;
BYTE diks[256];
HRESULT InitDirectInput(HWND hWnd ){
DirectInputCreate((HINSTANCE)GetWindowLong( hWnd, GWL_HINSTANCE ),DIRECTINPUT_VERSION, &g_pDI, NULL );
g_pDI->CreateDevice( GUID_SysKeyboard, &Keyboard, NULL );
Keyboard->SetDataFormat( &c_dfDIKeyboard );
Keyboard->SetCooperativeLevel(hWnd,DISCL_EXCLUSIVE | DISCL_FOREGROUND );
Keyboard->Acquire();
return S_OK;}
int KEY(int key){
return diks[key] & 0x80;}
Then in my input loop i just do
Keyboard->GetDeviceState( sizeof(diks), &diks );
if (KEY(DIK_ESCAPE)) PostMessage(hwnd, WM_DESTROY,0,0);
and so on no problems.
Hope this helps nothing else it rules out a problem with vcc 4.1
The problem is that I'm used to writing input routines for DOS, and not for windows, using getch(), which halts the program until a key is recieved, then returns the key. Simple as it seems, I can't seem to replicate this getch function in windows, because, coding for windows, I can only seem to retreive keystroke messages once per program cycle, and only in the winproc procedure.
Can anybody help with this?
____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux