Archived

This topic is now archived and is closed to further replies.

input routine

This topic is 6599 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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).]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites