Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / Game Design & Programming / Problems reading keyboard Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
Bumper

November 01, 2004, 05:21 AM

I have problems reading the input of my new wireless keyboard.

I currently handle WM_KEYDOWN and WM_KEYUP event in the WndProc callback (of course, it works well with a non-wireless keyboard).

The problem is that when I key pressed a key to move my camera in a direction for example, it stop moving after 1-3 seconds. I have the same probleme under windows when I press a key.

Here I keep pressed 'g' -> "gggg" instead of "gggggggggggggggggggggggggg...." but sometime it work normally.

Keyboard signal and battery are both high. Moreover, I do not have the problem at all in the game "Ground Control II". I also try UT2004 and FarCry and I have sometime the problem but almost not, so it is not a big problem to play.

I think those games use another method to handle the keyboard inputs. Are you aware of that problem, and do you know a better method to handle keyboard inputs than WM_KEYDOWN and WM_KEYUP event? (my be DirectInput?)

Thanks in advance for helping.

 
StiNKy

November 01, 2004, 06:44 AM

Give DirectX's DirectInput a try. It's not too hard to implement.

 
Bumper

November 01, 2004, 07:08 AM

Arf, it was my keyboard which was not synchronized with the receiver.. I did not do the right manip.

Shame on me, I did not read the fucking manual :(

However, I did not understand how Groud Control 2 works perfectly when the keyboard not synchronized..

 
eNGIMa

November 01, 2004, 06:59 PM

Isn't SDL's input subsystem a wrapper for direct input under windows?

 
laundrypowder

November 01, 2004, 07:04 PM

When available, it uses DirectInput2, otherwise it falls back on Win32 API.

corey

 
lukep

November 01, 2004, 11:08 PM

Are you just checking for a WM_KEYDOWN event and then checking if the right key was pressed (ie 'w') then going cam++? Not a good idea... you might want to try using GetAsyncKeyState... or even better, use DirectInput :)

 
laundrypowder

November 01, 2004, 11:19 PM

If you want a simple method using the WM_ message, there is this method:

1) Detect WM_KEYDOWN messages and store key value. Send message/perform action associated.

2) While your game loop progresses, and you need to check for the key press again( while it is still pressed on the keyboard), provide a method to check for the key value in the array of values stored from WM_KEYDOWN message.

3) Detect WM_KEYUP message and remove value from array/list.

Make sure you only add the key value to the array/list once!

Beware, this will have some issues with right vs. left detection of Shift, Ctrl, Alt unless you write extra code to detect these repeat messages and grab the keyboard state with WIN32 API calls.

corey

 
Bumper

November 02, 2004, 03:06 AM

I just do "m_KeyDown[key] = true" and call my "OnKeyboard(key, true)" function when I receive WM_KEYDOWN and "m_KeyDown[key] = false" and call my "OnKeyboard(key, false)" when I receive WM_KEYUP.

For my camera I just read "m_KeyDown[left, up, right..] == true" in my Update function.

My problem is partially resolved, when the keyboard is re-synchronized it works well 99% of the time.. sometime there is a WM_KEYUP when the key is still pressed but I suppose it cannot be 100% perfect with a wireless keyboard?

I will try direct input anyway..

 
This thread contains 8 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.