Thread: Keyboard

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    69

    Keyboard

    Can you tell me how i could get my program to recognise when the user presses any arrow key up,down,left,right?

  2. #2
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    you could use the bioskey(0); function in bios.h to see the interger value of the keys

    an eg program

    ----------
    #include<iostream.h>
    #include<conio.h>
    #include<bios.h>

    void main()
    {
    int key;
    clrscr();

    cout<<"Press any key...";
    key=bioskey(0);
    cout<<"\ninteger value : "<<key;

    getch();
    }
    --------

    like if you pressed enter it will give 7181 as output.

    use for loop to see for all keys.

    Hope this helps..

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    69

    Dev c++ doesn't seem to have

    bios.h any other way?

  4. #4
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    This should work on Dev C++ -

    Code:
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    
    int main()
    {
    
    	while(1)
    	{
    	
    		if(GetAsyncKeyState(VK_UP))
    			cout << "UP"<<endl;
    		if(GetAsyncKeyState(VK_DOWN))
    			cout << "DOWN"<<endl;
    
    		//etc
    	}
    	
    
       return 0;
    }

  5. #5
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    #include <iostream.h>
    #include <conio.h>
    //There may be others im not sure....

    int main()
    {
    while(1)
    {
    char key = getch();

    if (key == 27) //This is ascii code for ESC (what you use)
    break;

    }
    return 0;
    }



    Tell me if i helped
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  6. #6
    Registered User JTtheCPPgod's Avatar
    Join Date
    Dec 2001
    Posts
    44
    Originally posted by Sorensen
    This should work on Dev C++ -

    Code:
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    
    int main()
    {
    
    	while(1)
    	{
    	
    		if(GetAsyncKeyState(VK_UP))
    			cout << "UP"<<endl;
    		if(GetAsyncKeyState(VK_DOWN))
    			cout << "DOWN"<<endl;
    
    		//etc
    	}
    	
    
       return 0;
    }
    would that work in VC++?
    "No! I must have my delicious cupcakes, my sweet cakey treasures, piping hot from their 40 watt WOMB!!!"
    --Captain Murphy

  7. #7
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    just out of curiosity, why don't u try it and find out??

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting keyboard and mouse in linux
    By sameer.nalwade in forum C Programming
    Replies: 3
    Last Post: 11-22-2008, 04:24 AM
  2. Keyboard port using other that a keyboard
    By antoinelac in forum C++ Programming
    Replies: 4
    Last Post: 06-12-2008, 02:46 PM
  3. Send output to keyboard buffer
    By DReynolds in forum C Programming
    Replies: 2
    Last Post: 06-06-2007, 03:44 PM
  4. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  5. Game Design Topic #2 - Keyboard or Mouse?
    By TechWins in forum Game Programming
    Replies: 4
    Last Post: 10-08-2002, 03:34 PM