Sign in to follow this  
Tispe

Keyboard parsing

Recommended Posts

Hello

At the moment I am using the following code (DX/c++) to parse keystrokes

[code]
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
if(KEY_DOWN(VK_F))
//handle
[/code]

This code resulted in multiple "F"s spamming my screen because the key is held down multiple frames. So I resorted to make a BOOL to detect if it has already been parsed. If the key is released the BOOL is toggled back. So I have a very cumbersome code where each key has a BOOL and is checked with an IF statement.

My parser is limited by framerate etc. Most keyboard parsers also have a function where if you press a key down for more then 1 second it will add more letters, this won't work with my current code. If I were to implement it the way it is now I must add atleast 10 lines of code for each key.

Any suggestions? How does windows capture input in textboxes, can this be ported to DirectX?

Share this post


Link to post
Share on other sites
[url="http://msdn.microsoft.com/en-us/library/ms646276%28v=vs.85%29.aspx"]http://msdn.microsoft.com/en-us/library/ms646276%28v=vs.85%29.aspx[/url]

Share this post


Link to post
Share on other sites
[quote name='Tispe' timestamp='1306776245' post='4817578']
Is this how "big titles" catch user input?
[/quote]

Why [i]wouldn't[/i] they use functionality that is already implemented, works fine, and has no bugs?

Share this post


Link to post
Share on other sites
[quote name='JTippetts' timestamp='1306779481' post='4817596']
[quote name='Tispe' timestamp='1306776245' post='4817578']
Is this how "big titles" catch user input?
[/quote]

Why [i]wouldn't[/i] they use functionality that is already implemented, works fine, and has no bugs?
[/quote]

is'nt DirectInput / Xinput better ?

Share this post


Link to post
Share on other sites
Ok then. Just another quick one before the thread drops into the abyss.

Would you PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) once per frame or empty it completly before moving on?

[code]
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
//handle
[/code]

Or can this cause hiccups?

Share this post


Link to post
Share on other sites
[quote name='ryan20fun' timestamp='1306783652' post='4817620']
[quote name='JTippetts' timestamp='1306779481' post='4817596']
[quote name='Tispe' timestamp='1306776245' post='4817578']
Is this how "big titles" catch user input?
[/quote]

Why [i]wouldn't[/i] they use functionality that is already implemented, works fine, and has no bugs?
[/quote]

is'nt DirectInput / Xinput better ?
[/quote]

Not really. DirectInput has basically been deprecated since DX 8. Microsoft recommends XInput for 360 controllers, but standard Windows messages for keyboard and mouse. (Source: [url="http://en.wikipedia.org/wiki/XInput"]http://en.wikipedia.org/wiki/XInput[/url] ) There really is no reason to use other than Windows messages for character input on Windows. Some APIs, though, will throw a wrapper around the Windows messages so you don't have to actually deal with them, but underneath they're probably processing WM_CHAR and friends.

Share this post


Link to post
Share on other sites
[quote name='Tispe' timestamp='1306783829' post='4817624']
Ok then. Just another quick one before the thread drops into the abyss.

Would you PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) once per frame or empty it completly before moving on?

[code]
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
//handle
[/code]

Or can this cause hiccups?
[/quote]
You actually HAVE to empty the message pump completely or you end up with "lagging" window effects (e.g. when dragging the window around).

Share this post


Link to post
Share on other sites
[quote name='Tispe' timestamp='1306761939' post='4817491']
My parser is limited by framerate etc. Most keyboard parsers also have a function where if you press a key down for more then 1 second it will add more letters, this won't work with my current code. If I were to implement it the way it is now I must add atleast 10 lines of code for each key.
[/quote]

Do you have some kind of time stamp available (a tick count for example). Then just save time stamps instead of bools. Then you can easily find out how long a key has been pressed by checking against the current tick count.

- Michael.


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this