• C

obtaining multiple keys at once

I am programming a simple VR tank simulation and I have run into a rather large bottleneck. Standard key-grabbing functions can only access one key at a time. This makes driving the tank forward and turning impossible. How can I access more than one key at once? I know getch() and cin only grab the current key. Is there anyway to access all currently depressed keys from the key buffer? I am attempting to have my application portable so I wanted to avoid assembly and any MFC calls if possible. None the less if necessary I would gladly use MFC as a solution.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jean_pierreAuthor Commented:
Edited text of question.
As you stated you'd be glad to use a MFC solution, I assume your platform is windows.

You can simply use the 'GetKeyState()' API, which does exactly what you want:

(quote from the docs)
"GetKeyState (Win32)

SHORT GetKeyState(nVirtKey)

int nVirtKey;      /* virtual-key code      */

The GetKeyState function retrieves the status of the specified virtual key. The status specifies whether the
key is up, down, or toggled (on, off--alternating each time the key is pressed).

Parameter      Description

nVirtKey      Specifies a virtual key. If the desired virtual key is a letter or digit (A through Z, a through z, or
0 through 9), nVirtKey must be set to the ASCII value of that character. For other keys, it must
be a virtual-key code.
      If a non-English keyboard layout is used, virtual keys with values in the range ASCII A
through Z and 0 through 9 are used to specify most of the character keys. For example, for
the German keyboard layout, the virtual key of value ASCII O (0x4F) refers to the 'o' key,
whereas VK_OEM_1 refers to the 'o with umlaut' key. "

Feel free to ask if you'd like to have an example!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jean_pierreAuthor Commented:
I was really hoping for a non-platform specific response (the application runs on IRIX SGIs) but this will definitely do the trick on the windows boxes. Is it possible to see an example of its usage? Where can I find the API and its documentation?

Redefine Your Security with AI & Machine Learning

The implications of AI and machine learning in cyber security are massive and constantly growing, creating both efficiencies and new challenges across the board. Check out our on-demand webinar to learn more about how AI can help your organization!

Sorry for the delay, but it's Europe here and - so to say - in the middle of the night ;-)

The API docs can be found in the MS SDK documentation, but I'll post a link to the MSDN article if you need it...
jean_pierreAuthor Commented:
that would be great thanks. I have also been told that the function getch()ekey could possibly achieve the same result, but unfortunately I have not been able to find any info on that either. So at this point there isn't really any standard c or c++ method of multi-key grabbing?

thanks again
Sorry for the delay, had to visit customers yesterday :-(

Here's the MSDN documentation:


>>So at this point there isn't really
>>any standard c or c++ method of multi-
>>key grabbing?

No, this is highly platform specific...

BTW: Using 'getche()' would mean 'polling', and this is a no-no nowadays.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.