Thread: keystroke processing

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    keystroke processing

    How do I disable keystroke processing?
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  2. #2

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    I was reading the article below that said when using GetAsyncKeyState the application can still process input while it doesn't have the input focus. As I understood it, to solve this keystroke processing had to be turned off.

    http://msdn.microsoft.com/archive/de...dn_dos2win.asp
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  4. #4
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    Aha, I have read the part of the article you are speaking about. Basically, it explains two different ways to process keyboard input:

    1. the Good Citizen way, using WM_KEYDOWN and WM_KEYUP messages, which are not sent to an application that does not have input focus, so there are no problems when your application loses focus. The bad thing with this is that if your game is slow, someone could press a key and release it (assuming that WM_KEYDOWN and WM_KEYUP are updating a keyboard table that says what keys are down/up), and by the time the table is consulted, it may not 'catch' the fact that a key was down for a brief period of time. This is no good. A second method solves the problem:

    2. Use GetAsyncKeyState, which returns whether a key is currently down right now, and if it has been down since the last time you checked, even if it is up now. This way, you never lose the fact that a key was briefly pressed inbetween checks.

    Now, the problem is that GetAsyncKeyState is a call that you make (where as WM_KEYDOWN and WM_KEYUP are messages that you get from the system only when you have focus). This means if your program is making this call when it doesn't have focus, then it will still tell you what the current state of the keys are. So, if you ALT-TAB to a word processor, and hold an arrow key down to move the cursor, the character in your game in the background also moves.

    The solution? As the article states, and the source of your question: "Be sure to turn off keystroke processing when your game loses the input focus." Basically, this means if your application is not in focus, stop calling GetAsyncKeyState! (i.e. there's nothing to 'disable'.)

    (P.S. There is no way I could have arrived at a proper answer to your question without the link you posted in the second post - so, please be as specific as you can in further posts, just as your second post was.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reentrant Message Processing (WndProc)
    By phantomotap in forum Windows Programming
    Replies: 7
    Last Post: 04-28-2009, 10:44 AM
  2. What types of files can C++ file processing handle?
    By darsunt in forum C++ Programming
    Replies: 9
    Last Post: 10-28-2008, 11:33 AM
  3. Sub Array Processing
    By GCNDoug in forum C++ Programming
    Replies: 8
    Last Post: 11-28-2007, 04:41 PM
  4. Using a lot of processing time!
    By nickname_changed in forum C++ Programming
    Replies: 0
    Last Post: 09-25-2003, 03:44 AM
  5. file writing crashes
    By test in forum C Programming
    Replies: 25
    Last Post: 08-13-2002, 08:44 AM