Hi,
I want to get the Key State of the arrow keys in linux, because I'm trying to create something like a simple game.
I've been searching on Google for hours, but all code I found was for Windows ONLY.
For my program, I was going to use a loop like this:
//...
#define Xmax 40
#define Ymax 40
#define Xmin 0
#define Ymin 0
main()
{
int movement=0;
int PlayerPosition[Xmax][Ymax];
int PlayerX, PlayerY;
int RY,RX;
for(RX=0;RX<Xmax;RX++)
for(RY=0;RY<Ymax;RY++)
PlayerPosition[RX][RY]=0;
//...
while (movement=1)
{
if (GetKeyState(VK_ARROWDOWN))
{
if !( PlayerY=Ymin)
{
PlayerPosition [PlayerX][PlayerY]=0
PlayerPosition [PlayerX][PlayerY-1]=1
PlayerY=PlayerY-1;
}
}
//This goes on for the other three Arrow Keys
//...
}
Anybody know how to code this?
PeterK
P.S.: The code is just an example and probably doesn't follow the correct C++ Syntax.
What linux are we talking about here? Anyways, your best bet would probably be to get yourself some specialized library for games, like SFML, SDL or Allegro. Those provide pretty much everything you generally need for a game (graphics/sound, input routines, stuff like that).
Other than that you could also use a more general framework like wxWidgets or Qt.
PS: Arrays are evil, and the same goes for functions like GetKeyState. Input should be handled event based, not poll based.
My whole program is based on an array... Don't want to change it now ;-)
I was going to work with Qt, installed it, but I didn't use it for key input. Could you please post an example code?
Peter
P.S.: thx for helping :)
Wow, thanks for all that code, I'm going to try it out tomorrow afternoon, hope I find some time to do that^^
Honestly, I didn't expect THAT much... thanks!
Can I write that .ui file with notepad and just save it that way or do I need some sort of compiler?
You can just save it, but you will need the qt library (and the tools qmake and make) to compile this. If you want to make own GUI's it would probably best to get a tool like Qt Designer.
If you have all of those, put them all into a new directory and just do this from a terminal (with the directory you just created as the active one of course)