Can keyboard accept more than one key press at a time? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Can keyboard accept more than one key press at a time?

I would like to know if I can press two keys at the same time and two different actions is performed simultaneously . An example of this would be a fighter plane with arrow Up key as firing and the left and right key as movement to left and right respectively . Instead of using Kbhit() that only accept one user input the time .

Codes should be in Visual C++ 6.0.



Thanks








Comments

  • You should try to search for a:

    Keyboard ISR(Interrupt Service Routine),

    or make one =)



    It will update an array with all the

    keys on the keyboard, and you could set

    a specific entry to let's say "1" if that

    specific key is pressed, and "0" if it's not

    pressed.



    Good luck.




  • : You should try to search for a:

    : Keyboard ISR(Interrupt Service Routine),

    : or make one =)

    :

    : It will update an array with all the

    : keys on the keyboard, and you could set

    : a specific entry to let's say "1" if that

    : specific key is pressed, and "0" if it's not

    : pressed.

    :

    : Good luck.

    :

    : May I know where can I find a keyboard ISR(Interrupt Service Routine) or how to make one . Thanks






  • I think there are whole tutorials covering

    that topic, but well a gameprogramming site

    should have some info for you.



    I would definitly search for some tutorials.

    Try to find PCGPE

    (PC-Game-Programmers-Encyclopedia)

    I that's what it's short for...




  • this is what I do:

    in C++ win 32



    macro: keep macro on 1 line

    #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)



    then in other places use in if statement

    if(KEY_DOWN(VK_ESCAPE))

    {

    }

    or

    if(KEY_DOWN('A'))

    {

    }

    all chars will work inside of single quotes

    and the virtual keys are defined as VK_ESCAPE for escape key and so on

    hope it helps




  • You should consider using the DirectX SDK if you are an MSVC programmer. Look at DirectInput. DirectX is available free from Microsoft if you are developing a game. See:



    http://www.microsoft.com/directx



    You must create the DirectInput Object using a COM call, which sounds pretty frightening, but cut and paste sample code is supplied with the SDK in the help files.

    It supports joysticks and mice as well as multiple, asynchronous keypresses. You can query as simple as

    if(di->isKeyDown(DIK_ESCAPE) && di->isKeyDown(DIK_LSHIFT))

    {

    cout<"Shift-escape";<br>
    }




Sign In or Register to comment.