Advertisement

Best Method of reading input from keyboard

Started by March 22, 2005 07:39 AM
5 comments, last by Lutz 19 years, 11 months ago
well the subject says it all. But i need something i can port to Linux , im using ogl which allows me to port my game(s) to linux thats why i dont want to use directinput because then im limited to windows the current input handeling is the simple one found in tutorial 8 with Keys[256]; the problem is i want multiple players on one keyboard, say 5 on a keyboard and each can press 2 buttons at any current time. thats 16 buttons + 1(fire) so i need something that can handle 17 buttons at the same time. keys[256] gets stuck and stuff
----------------------------

http://djoubert.co.uk
Curses might be ok.

ace
Advertisement
curses?
----------------------------

http://djoubert.co.uk
Your best bet would be to use SDL, from www.libsdl.org, which can handle all of the input for you, including keyboard, mouse, and joystick. But SDL is more than just input handling, it's cross-platform (Windows, Linux, Mac, BeOS, *BSD), network handling, window creation, OpenGL wrapper, and CD ROM handling. SDL is simple, not overly complicated, and there are tons of people using it.
"Donkey, if it were me, you'd be dead."I cna ytpe 300 wrods pre mniute.
Both SDL and GLUT should work in Linux. Both have similar functions for capturing keyboard input.

A suggested technique is to keep an array of booleans for your keys. Each frame set them all to false. Then, when a key is down, set the corresponding element to true. The button will stay down when depressed and not flicker on and off.

Good luck!

EDIT: Just read the end of your post. How does it get stuck?
Without order nothing can exist - without chaos nothing can evolve.
I won't comment about the chaotic image of having 5 people on 1 keyboard [grin], but what you will need to do is use a buffered style of input in order to make sure everything is correctly processed. I have a post here that sort of touches on the use of tracking input keys using STL. However, that may not work on Linux, so you may need to either use STLPort or something like that for functionalty. Regardless of what input lbirary you use, you need to implement your own buffered input. DirecInput is the only library that does it autmatically for you - to which you juse need to process it.
Advertisement
Quote:
Original post by Drew_Benton
I won't comment about the chaotic image of having 5 people on 1 keyboard [grin]


I once wrote a bomberman clone with SDL. It could handle four people at the same time using one keyboard. (After about 15 minutes, our hands fell off, but LOTS OF FUN!!). Each player had 7 keys (up/down/left/right/bomb/throw/extra), so that's 28 keys in total.

It worked fine most of the time/ However, sometimes it got stuck (more precisely, it didn't react to all keys that were pressed). But I assume that was because of the keyboard hardware, not SDL. I'd guess you can't prevent this. But 17 keys might be OK...

This topic is closed to new replies.

Advertisement