Sign in to follow this  
wicked357

Needing linux substitution code.

Recommended Posts

I need to know any kind of linux substitution code for the following bits of code, both these sources require the windows.h header file to be included.
void gotoxy(int x, int y)
{
   COORD coord;
   coord.x = x;
   coord.y = y;
   SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

And a linux substitution for handling this keyboard macro
#define keyDown(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define keyUp(vk_code)   ((GetAsyncKeyState(vk_codE) & 0x8000) ? 0 : 1)

**EDIT: Oh yeah, I would prefer to not use an already existing library that handles this stuff for me!

Share this post


Link to post
Share on other sites
Quote:
Original post by wicked357
I need to know any kind of linux substitution code for the following bits of code, both these sources require the windows.h header file to be included.

*** Source Snippet Removed ***

And a linux substitution for handling this keyboard macro

*** Source Snippet Removed ***

**EDIT: Oh yeah, I would prefer to not use an already existing library that handles this stuff for me!


You're in for a world of pain if you choose not to use libcurses to handle the first question.

You can use kbhit / getch for the second problem.

Edit: Just realized that won't work for multiple simultaneous keypresses. OpenGL provides this functionality already I believe, are you using it by any chance?

Share this post


Link to post
Share on other sites
Quote:
Original post by wicked357
I need to know any kind of linux substitution code for the following bits of code, both these sources require the windows.h header file to be included.

*** Source Snippet Removed ***

If your application is running in a console that handles ANSI escapes (most likely), you can use something like:
void gotoxy(int x, int y) {
printf("\x1b[%d;%dH", x, y);
}


However, you might be better served by using a library like ncurses, which would handle this, and a whole lot more :)

Quote:
And a linux substitution for handling this keyboard macro

*** Source Snippet Removed ***

Generally, you get asynchronous keyboard input via libraries like SDL, the X libraries, or OpenGL's GLUT. There are some non-standard functions provided by some compiler vendors for this, but you are probably better off avoiding them.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this