how do you get arrow key input in DOS??

This is a discussion on how do you get arrow key input in DOS?? within the A Brief History of Cprogramming.com forums, part of the Community Boards category; i am just wondering how to get input from the arrow keys...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    44

    how do you get arrow key input in DOS??

    i am just wondering how to get input from the arrow keys

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    44

    more help

    ok i made a program that creates a window in dos please help me figure out what is wrong it compiles but when i execute and after i enter my numbers it says that it encounter problems and had to close
    Code:
    #include "stdafx.h"
    
    int createwindow(int x,int y);
    
    struct window{
    		int x,y;
    		
    	}test;
    
    int main(int argc, char* argv[])
    {
    
    	printf("enter the x dimension\n");
    	scanf("%d",&test.x);
    	printf("\nenter the y dimension\n");
    	scanf("%d");
    	createwindow(test.x,test.y);
    					
    	return 0;
    }
    
    int createwindow(int x,int y){
    	int help1,help2,help3;
    	for(help1=0;help1==x;help1++){
    		printf("-");
    		for(help2=0;help2==y;help2++){
    			printf("|");
    				for(help3=0;help3==(x-2);help3++){
    					printf(" ");
    					printf("|");
    				}
    		}
    	}
    	return 0;
    }

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    44

    optimized

    i optimized my program but this doesnt work either please smeone tell me what is wrong?
    Code:
    #include "stdafx.h"
    
    int createwindow(int x,int y);
    
    struct window{
    		int x,y;
    		
    	};
    
    int main(int argc, char* argv[])
    {
    	window test;
    	printf("enter the x dimension\n");
    	scanf("%d",&test.x);
    	printf("\nenter the y dimension\n");
    	scanf("%d");
    	createwindow(test.x,test.y);
    					
    	return 0;
    }
    
    int createwindow(int x,int y){
    	int help,help1;
    	for(help=0;help1==x;help++){
    		printf("-");
    	}
    	for(help=0;help==y;help++){
    		printf("|");
    		for(help1=0;help1==(x-2);help1++){
    			printf(" ");
    		}
    	}
    	for(help=0;help==x;help++){
    		printf("-");
    	}
    	return 0;
    }

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    44

    sorry

    ok sorry guys for wasting your time i found the problem but now i have another problem when i enter the numbers it says press enter to contnue i will show my new code
    Code:
    #include "stdafx.h"
    
    int createwindow(int x,int y);
    
    struct window{
    		int x,y;
    		
    	};
    
    int main(int argc, char* argv[])
    {
    	window test;
    	printf("enter the x dimension\n");
    	scanf("%d",&test.x);
    	printf("\nenter the y dimension\n");
    	scanf("%d",&test.y);
    	createwindow(test.x,test.y);
    					
    	return 0;
    }
    
    int createwindow(int x,int y){
    	int help,help1;
    	for(help=0;help1==x;help++){
    		printf("-");
    	}
    	for(help=0;help==y;help++){
    		printf("|");
    		for(help1=0;help1==(x-2);help1++){
    			printf(" ");
    		}
    	}
    	for(help=0;help==x;help++){
    		printf("-");
    	}
    	return 0;
    }

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>i am just wondering how to get input from the arrow keys
    http://faq.cprogramming.com/cgi-bin/...&id=1043284392

    >>for(help=0;help1==x;help++)
    and
    >>for(help=0;help==y;help++)
    and
    >>for(help1=0;help1==(x-2);help1++)
    and
    >>for(help=0;help==x;help++)
    The test condition is wrong. I'd guess you'd want something more like:
    >>for(help=0;help < x;help++)
    ... or maybe something similar?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Write an interrupt 09h interrupt handler.


    For C++ use (...) and for C use (void) in interrupt <somefunc>().
    Code:
    #define DOWN 1
    #define UP       0
    #define FALSE  0
    #define TRUE    1
    
    
    
    typedef unsigned char BYTE;
    
    BYTE keys[128];
    
    int HandlerInstalled;
    
    interrupt *OldHandler=0;
    
    void StartKeyboard(void);
    void EndKeyboard(void);
    
    
    interrupt NewKeyHandler(...)
    {
      BYTE ch=inportb(0x60);
      if (ch<128)
      {
          keys[ch]=DOWN
          lastkey=ch
      }
      else
      {
        if (ch==170)
        {
           keys[lastkey]=UP;
           lastkey=ch;
        }
         else
        {
           keys[ch-128]=UP;
           lastkey=ch-128;
        }
      }
      
       //Acknowledge EOI
       outportb(0x20,0x20);
    
    }
     
    void StartKeyboard(void)
    {
    
       //register our exit function
       //This will not catch CTRL-C or int 23h
       //But with handler installed - CTRL-C will do nothing
       //Upon normal termination of code - EndKeyboard will always be
       //called
       atexit(EndKeyboard);
    
       //Save old handler
       OldHandler=getvect(0x09);
    
       //Install new one
       setvect(0x09,NewKeyHandler);
    
       HandlerInstalled=TRUE;
    }
    
    void EndKeyboard(void)
    {
      if (HandlerInstalled) 
      {
         setvect(0x09,OldHandler);
         HandlerInstalled=FALSE;
      }
    }

    Then to test whether or not a key is down:

    if (keys[key_scan_code] dosomething();

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 09:00 AM
  2. Trouble with a lab
    By michael- in forum C Programming
    Replies: 18
    Last Post: 12-06-2005, 10:28 PM
  3. Allegro Specific key input...
    By o0obruceleeo0o in forum Game Programming
    Replies: 6
    Last Post: 07-01-2003, 12:41 PM
  4. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM

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