View Full Version : key is down for linux?
03-11-2009, 12:11 PM
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 =)
03-11-2009, 01:12 PM
I use SDL or GLFW.
03-11-2009, 01:54 PM
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?
03-12-2009, 09:01 AM
XQueryKeymap perhaps does what you want. I'm working on the same problem right now but haven't tried anything yet.
09-15-2009, 06:54 AM
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:
//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!
09-15-2009, 07:05 AM
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:
How is localized text handled in the win32 api? Does windows handle everything for you depending on the selected keyboard/language?
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.