Multiple key handler
Hi I am having problems with my game. I program in DJGPP C++ for DOS and want to make a multiple keyboard handler so that more than one key can be pressed like a combination of control and alt and still pick up ordinary keys. I know that this can be done in assembley but how ?? I hate DJGPP''s assembly syntax so much that it makes it so hard to do anything. Can anyone help
Thanks in advance.
---------------------------------------------You Only Live Once - Don't be afriad to take chances.
Does the entire keyboard don''t have more key than you need?
My key board as more the 70 key!
Just the letters (26 key) should cover lot of command!
con the numbers (from 0 to 9)
Commun key in game (CTRL, ALT, Space bar, Up rigth leff down)
F1 to F12
And there is the mouse!
If a game need more key....it will required a so long learning curve than no one will play it!
Don''t make key combination this is really anoying (this is one reason than i don''t like consol)
My key board as more the 70 key!
Just the letters (26 key) should cover lot of command!
con the numbers (from 0 to 9)
Commun key in game (CTRL, ALT, Space bar, Up rigth leff down)
F1 to F12
And there is the mouse!
If a game need more key....it will required a so long learning curve than no one will play it!
Don''t make key combination this is really anoying (this is one reason than i don''t like consol)
Maybe key combinations are an integral part of his design. Maybe his game is designed with contorl pads in mind. Not so many keys there eh . Anyway, if u where using dinput I could help you, but as it is I can''t sorry.
Dare To Think Outside The Box
_____________________________
|____________________________|
http://www.inversestudios.com
Dare To Think Outside The Box
_____________________________
|____________________________|
http://www.inversestudios.com
Write more poetry.http://www.Me-Zine.org
No what I mean is that is I am moving my character on the screen and I want too fire then I am really pressing two keys. say if the fire button is control and the direction button is an arrow key. I want my program to recognise both. The way I am doing it now is that it only recognises one at a time meaning if I wanna shoot I have to take my hand off a key and press control to fire and I know games don''t work like this.
---------------------------------------------You Only Live Once - Don't be afriad to take chances.
Key combinations are not a bad thing. Talk to any efficient windows user and they will tell you they use things like [ALT]-F-X(or [ALT]-F4) to exit a program, [ALT]-[TAB] to change programs, etc., etc. Once memorized, if placed right key combinations can make you faster. Any speedy windows user will attest to this.
Kressilac
Kressilac
Derek Licciardi (Kressilac)Elysian Productions Inc.
I don''t think that the number of keys are of importance here you guys.
What he wants to know, is how to determine if two keys are pressed at the same time.
Say that you are playing a game with an overhead view (tile map). You can go up, down, left, right and diagonal. In order for you to go up and to the right, you would have to check if the up key & the right key were pressed at the same time. On top of that, you would want to be able to press the fire button at the same time, so there is another key that you want to check for.
I don''t know how to do it in your compiler, but I can in Dinput. I think I have some source laying about for a dos mode keyboard handler don''t in assembly. If you want me to have a look for it then send me an e-mail.
What he wants to know, is how to determine if two keys are pressed at the same time.
Say that you are playing a game with an overhead view (tile map). You can go up, down, left, right and diagonal. In order for you to go up and to the right, you would have to check if the up key & the right key were pressed at the same time. On top of that, you would want to be able to press the fire button at the same time, so there is another key that you want to check for.
I don''t know how to do it in your compiler, but I can in Dinput. I think I have some source laying about for a dos mode keyboard handler don''t in assembly. If you want me to have a look for it then send me an e-mail.
Hi there. Are you by chance using the Allegro library? I remember that you can handle keystates (up or down) instead of reading just when the player presses a key in Allegro. You can do it in DJGPP itself im sure, but I don't remember how
If you want to use Allegro (which is IMHO best if you are using DJGPP), you can use the following code:
(assuming you have the rest of allegro setup)
void game_init() {
// this is where you do all your initialization,
// however you have it
allegro_init();
install_keyboard();
}
void handle_input() {
// there is a char array, key[128], that holds the key states
// it will be 0 if it is not pressed, and non-0 if it is
// the actual value will also tell you which keys are
// pressed with it (ctrl, alt, etc)
// allegro also defines KEY_* constants to make it easier
// px, py - player position
if (key[KEY_UP]) { py--; }
if (key[KEY_DOWN]) { py++; }
if (key[KEY_LEFT]) { px--; }
// ...etc...
}
this will handle multiple keys (you press up and right? you go diagonally up-right with the simple code above automatically; press left+right at the same time and they cancel each other out)
this is what you wanted, no?
could add the line:
if (key[KEY_CONTROL]) { shoot = TRUE; } else { shoot = FALSE; }
and you can shoot and move at the same time.
Hope you get it working the way you want.
- Daniel Major
Edited by - MajorD on 2/4/00 12:56:47 PM
If you want to use Allegro (which is IMHO best if you are using DJGPP), you can use the following code:
(assuming you have the rest of allegro setup)
void game_init() {
// this is where you do all your initialization,
// however you have it
allegro_init();
install_keyboard();
}
void handle_input() {
// there is a char array, key[128], that holds the key states
// it will be 0 if it is not pressed, and non-0 if it is
// the actual value will also tell you which keys are
// pressed with it (ctrl, alt, etc)
// allegro also defines KEY_* constants to make it easier
// px, py - player position
if (key[KEY_UP]) { py--; }
if (key[KEY_DOWN]) { py++; }
if (key[KEY_LEFT]) { px--; }
// ...etc...
}
this will handle multiple keys (you press up and right? you go diagonally up-right with the simple code above automatically; press left+right at the same time and they cancel each other out)
this is what you wanted, no?
could add the line:
if (key[KEY_CONTROL]) { shoot = TRUE; } else { shoot = FALSE; }
and you can shoot and move at the same time.
Hope you get it working the way you want.
- Daniel Major
Edited by - MajorD on 2/4/00 12:56:47 PM
You can write a keyboard interrupt handler for your program. I believe you can use setvect and getvect with DJGPP to assign the handler. You might want to check out the old DOS version of Black Art of 3d Game Programming for details on how to write the handler. Or really any of LaMothe''s old DOS books should have details on it. But it shouldn''t invlove much (if any) assembly.
Why reinvent the wheel tho? By the sounds of things (the numerous posts and Dark Star being a self-proclaimed newbie) he would be well off to get Allegro. It''s what I used when I did DJGPP games, and it has decent performance with an relatively easy interface. You could write an interrupt handler, but thats what install_keyboard() does for you.
If you didn''t download it when you got DJGPP, you can get it here:
ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2tk/allegro/alleg312.zip
I highly recommend it.
- Daniel Major
If you didn''t download it when you got DJGPP, you can get it here:
ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2tk/allegro/alleg312.zip
I highly recommend it.
- Daniel Major
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement