Key input

This is a discussion on Key input within the Windows Programming forums, part of the Platform Specific Boards category; Hello I need for my little game key input. Unfortunately I dont need only arrows but even letters. Is there ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    162

    Key input

    Hello

    I need for my little game key input. Unfortunately I dont need only arrows but even letters. Is there any way how to do so using only WinAPI or do I need to use DirectX?

  2. #2
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Simply handle the WM_CHAR or WM_KEYUP/WM_KEYDOWN messages for your window.

  3. #3
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    for games its generalyl preferred to use the WM_KEYUP and WM_KEYDOWN messages to update a keystate structure. WM_CHAR is subject to auto-repeat for keys that are held down. One thing to note however is that if the application loses focus while a key is down adn then the player releases the key while th app doesnt have focus, then the app will not recieve the WM_KEYUP message and will think that the key is still down. You should occasionally perform a sanity check using GetAsyncKeyState() for keys that are held down for lengthy periods. Dependign ont eh game, you coudl of course just skip that step, as it may not be an issue.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    162
    Quote Originally Posted by abachler View Post
    for games its generalyl preferred to use the WM_KEYUP and WM_KEYDOWN messages to update a keystate structure. WM_CHAR is subject to auto-repeat for keys that are held down. One thing to note however is that if the application loses focus while a key is down adn then the player releases the key while th app doesnt have focus, then the app will not recieve the WM_KEYUP message and will think that the key is still down. You should occasionally perform a sanity check using GetAsyncKeyState() for keys that are held down for lengthy periods. Dependign ont eh game, you coudl of course just skip that step, as it may not be an issue.
    I use GetAsyncKeyState() but only for arrows and stuff. It never works with letters in my case. I will try the WM_KEYDOWN it probably wont be an issue with the WM_KEYUP.

    Thank you

  5. #5
    Registered User
    Join Date
    Apr 2007
    Posts
    162
    So now I use GetAsyncKeyState() for any input again thx for the advice. Just additional question I found at MSDN list of virtual keys but they dont work in my app the values are different. Is it because my app is set to Multibyte so that the character set has different mapping values?

    If yes where can I see map of Multibyte character set?

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    162
    Oh I didnt realize before what I was looking for is a table of ascii code.

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Oh wow... Well if you ever need it, check out the VK_* codes on MSDN.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function to check memory left from malloc and free?
    By Lechx in forum C Programming
    Replies: 4
    Last Post: 04-24-2006, 06:45 AM
  2. Trouble with a lab
    By michael- in forum C Programming
    Replies: 18
    Last Post: 12-06-2005, 11:28 PM
  3. key input definition
    By hkmixxa in forum C++ Programming
    Replies: 3
    Last Post: 08-09-2004, 06:39 PM
  4. Key input?
    By Kavity in forum Linux Programming
    Replies: 0
    Last Post: 12-20-2002, 11:01 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 11:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21