问题
I want to check for Key-Events like pressing up / pressing down ...
But the function, which I created to be called, gets a "unsigned char". I am able to check for keys like W/A/S/D with key == 'w'
, but I don't know how to check for other keys.
Is there any list of available chars, like "\n"?
回答1:
You can find a list of character escape sequences here.
Note that some keys have to be handled using glutSpecialFunc()
/glutSpecialUpFunc()
, for whose handler the following applies:
The key argument may take one of the following defined constant values:
- GLUT_KEY_F1, GLUT_KEY_F2, ..., GLUT_KEY_F12 - F1 through F12 keys
- GLUT_KEY_PAGE_UP, GLUT_KEY_PAGE_DOWN - Page Up and Page Down keys
- GLUT_KEY_HOME, GLUT_KEY_END - Home and End keys
- GLUT_KEY_LEFT, GLUT_KEY_RIGHT, GLUT_KEY_UP, GLUT_KEY_DOWN - Arrow keys
- GLUT_KEY_INSERT - Insert key
回答2:
The natural char type in C++ uses ASCII characters. Here is a list: http://www.asciitable.com/
You can check for something like newline like this:
if (key == '\n')
回答3:
this is a nice list of enums for keys
http://msdn.microsoft.com/en-us/library/system.windows.forms.keys(v=vs.71).aspx
回答4:
You are asking for escape sequences.
Here is a complete list of C++ non-graphic characters and their escape sequences.
回答5:
If I understand correctly, there is no system independent way of getting the information you need. What you're looking for, I think, is called a scan code, and most systems will have a way of getting it“under Unix, it will be something in the X library if you are running in a window, and under Windows, it's likely to be in the Windowing library as well. What you'll get is the scan code plus some bits indicating the state of the various keys like shift, control and alt; and the windowing system will generate an event each time any key changes state.
If you're not running in a window (or in your own window), it may still be possilbe to get some sort of key state if you're reading directly from a terminal, although I'm not too familiar with the possiblities. (Remember that historically, the input interfaces were designed for reading over a serial line, and this sort of information simply wasn't available in the C++.)
来源:https://stackoverflow.com/questions/9266045/list-of-key-constants