key is down for linux?

I used GetAsyncKeyState(char) function in windows, which returns a nonzero value if char key is down and 0 if it is not.

Unfortunately it is in windows.h so does not work on linux.

Anyone knows a similar function to it? It does not need to catch shift, f1 etc virtual keys. I just want to move my character to forward if ‘w’ is pressed =)

I use SDL or GLFW.

are these similar to glut? i am already using glut, it has a keyboard function but it is very basic. can i use them with glut?

XQueryKeymap perhaps does what you want. I’m working on the same problem right now but haven’t tried anything yet.

OK it’s a little late to answer but for reference (and Google hits!) I will report that XQueryKeymap does indeed do the trick but it’s a bit more complicated than Windows.
First you need the keycode for the keys you will use.
I used something like:


int spaceKey = XKeysymToKeycode(display, XK_space);

then to detect if key is down:


char keys[32];

XQueryKeymap(win.getDisplay(), keys);

if(keys[spaceKey/8]&(0x1<<(spaceKey%8)))
{

      //do something useful
}

The bit operations are required because array ‘keys’ encodes key code states in its individual bits.
For more info look in Xlib documentation(just google for it)
Hope that helps to get you started!

You won’t get localized input this way. For example the éèáà and other symbols that occur in several European countries. Let alone Asiatic symbols. For that you’ll need some quite complex X code (I’ve created such code a couple of weeks ago). Example documentation can be found here:

http://www.sbin.org/doc/Xlib/
(chapter 11)

How is localized text handled in the win32 api? Does windows handle everything for you depending on the selected keyboard/language?