Needing linux substitution code.

Started by
1 comment, last by mattd 14 years, 2 months ago
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!
Advertisement
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?
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.

This topic is closed to new replies.

Advertisement