Advanced Keyboard Input

This is a discussion on Advanced Keyboard Input within the Game Programming forums, part of the General Programming Boards category; Hello I'm making a game and I have a problem. For example I want that when I press the arrow ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    7

    Talking Advanced Keyboard Input

    Hello
    I'm making a game and I have a problem.
    For example I want that when I press the arrow keys on the keyboard the ball will move across the screen with a slow speed and when I hold the spacebar while moving the ball with the arrow keys, the ball will move faster...

    How do I know whether the spacebar is hold (pressed down) while pressing other keys like the arrow keys...

    Please help me and thank you!

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    Try looking at the kbhit() function, this will tell you when a key has been pressed without you having to ask, if you know what i mean. its found in conio.h
    Code:
    while(1)
    {
        speed = SLOW; /* set your ball speed to slow */
    
        if(kbhit()) /* has a key been pressed */
            if(getch() == SPACEBAR)
                speed = FAST; /* set yor ball speed to fast */
    
        /* move your ball here */
    }
    Just an idea, change it with your specific code, it might work
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    Registered User Coder's Avatar
    Join Date
    Aug 2001
    Location
    Cairo, Egypt
    Posts
    128
    If you're using a DOS compiler (i.e Not MSVC++ or BCB) you can use int9 keyboard handler which allows you to detect multiple keys being pressed down in a style like this
    Code:
    if(IsPressed(keys[VK_SPACEBAR])
    {
        // Do something
    }
    if(IsPressed(keys[VK_UP])
    {
        // Do something
    }
    I believe www.shdon.com (or www.shd.cjb.net) has source code explaining the usage of the handler.
    Muhammad Haggag

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    7

    Unhappy Bummer.....

    1st of all thank you for trying to help me, but
    C_Coder: you didn't understand my question.
    Coder: I couldn't find the soruce...

    I hope that someone will help me...

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    7

    Thank you very very much!

    Thank you stonned and I wish you a stonned holiday!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help using inline assembly for keyboard input
    By sleventeen in forum C Programming
    Replies: 7
    Last Post: 05-10-2009, 01:31 AM
  2. Keyboard Input
    By CaliJoe in forum C++ Programming
    Replies: 3
    Last Post: 05-08-2009, 09:51 AM
  3. Keyboard input in a Dialog
    By ksarkar in forum C++ Programming
    Replies: 1
    Last Post: 05-20-2005, 05:39 AM
  4. Intercepting keyboard input
    By EvBladeRunnervE in forum Windows Programming
    Replies: 3
    Last Post: 01-08-2004, 08:03 AM
  5. Need help with Console Keyboard Input
    By pawelx2 in forum Game Programming
    Replies: 5
    Last Post: 05-30-2002, 11:03 PM

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