Keyboard?

This is a discussion on Keyboard? within the Game Programming forums, part of the General Programming Boards category; OK. I have a BIG problem... I want to know how to make my program do some different things at ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    100

    Keyboard?

    OK.

    I have a BIG problem...
    I want to know how to make my program do some different things at the same time. I've heared that it's called multitasking, but I don't know anything about it. There was some function for that purpose, but what was it and how can I use it? You could also tell me how to make program to wait until some key is pressed and do something what I want, without affecting on the some other task that it's doing. Or is it the same multitasking?

    Well... I wait forward for your ansewrs

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    106
    to follow up on that, can you use this, if you can, in DOS apps? Thats all i know how to do, lol...im such a loser, i cant grasp windows programming

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    100
    It makes two of us....

    I also have some SERIOUS problems with the Windows-monster.
    Sauron a few seconds before his defeat:
    "What? A 'division by 0' error?!?"

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    Windows programming is not harder (in many ways, it's easier) but it's just DIFFERENT. It takes a lot of knowing how to set stuff up.

    For multitasking in DOS, it may be easiest to have one loop that is constantly running, and simply call a lot of fuctions to do one "cycle" of each task. So, if you had a main loop for a game, and you wanted to check for input, move the sprites, and apply damage to various sprites if necessary, then draw the screen, you could just do something like this:
    Code:
    while (exit == false){
    	CheckForInput();
    	MoveSprites();
    	ApplyDamage();
    	DrawScreen();
    }

    Key input isn't hard, but you should NOT wait for it, unless you have a multithreaded game. Rather, your CheckForInput(); should immediately return if there is no input ready, so the rest of your game doesn't stall. You never want to stall the main loop, ever.

    Doing keystrokes in DOS is not the easiest thing, especially if the goal is a game where certain keys will be held down. Usually, it is recommended that you write your own keyboard interrupts for this purpose -- and I've long sinc stopped DOS programming so I no longer have any sample code to give you =/

    Check books on DOS game programming -- they'll give you lots of helpful advice.

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    106
    Good tip about stalling the main function, i just have no clue how i would do that...if ive got a case statement that requires the user to hit arrow keys to move around, how would i make it so if there isnt any input it skips it? kinda conufsing question/topic. thanks for your input tho, lol

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    Well, you'll probably need to create a new keyboard handler, and then, you move only if an arrow key is down, else you won't move.

    Many people have written keyboard handlers for DOS programs (I used to have one on the web at one point, too). This looks, at a glance, to be what you need:

    http://www-scf.usc.edu/~akotaobi/opkey.html

    Using this guy's keyboard handler, you'd just do things like:

    if (tbl[SCAN_UP]) {
    // Move up
    }

  7. #7
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    check out c-for-dummies.com - he has a section on DOS multitaksing.

  8. #8
    Registered User
    Join Date
    Aug 2001
    Posts
    106
    alright, thanks a lot guys. that should help.

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, 03: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, 09: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

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