🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

input routine

Started by
6 comments, last by benjamin bunny 24 years, 7 months ago
I'm not sure if I understand what you are trying to do, but couldn't you just use DirectInput, and read the keyboard in an infinite loop, and re-read it until there is input?
Advertisement
You could either define a macro for Key up & down like this:

#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).]

Joseph FernaldSoftware EngineerRed Storm Entertainment.------------------------The opinions expressed are that of the person postingand not that of Red Storm Entertainment.
thanks for the advice.

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?

You sure you set the data format and allocated enough space for the keyboard state array? You need 256 bytes, and you need to tell GetDeviceState() in the first parameter that you have 256 bytes.

- Splat

Yeah, I set the data format, and it returned DI_OK, and the kb buffer is 256 bytes, exactly as described in the keyboard input tutorial.

I'm using quite an early version of VCC - version 4.1. Is this likely to be a problem?

I doubt it i use vcc 4.1 myself with dx7.0 and have never experinced 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

I've been coding a 3D engine for the last 6 months, and everything was going fine, until yesterday, when I tried to write a simple input routine to retreive a string from the keyboard, and everything went pear shaped.

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

That seems to have worked. Thanks for the help.

This topic is closed to new replies.

Advertisement