C++ OpenGL / Glut 按钮和键

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15435715/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 19:21:13  来源:igfitidea点击:

OpenGL / Glut Buttons and Keys

c++inputkeyboardglut

提问by Reanimation

I'm self studying using the Pearson, Computer Graphics with OpenGL's book.

我正在使用这Pearson, Computer Graphics with OpenGL本书自学。

I'm currently trying to make a simple square move, but before I get ahead of myself I need to be sure I understand what keys are built into Glut.

我目前正在尝试做一个简单的正方形移动,但在我超越自己之前,我需要确保我了解 Glut 中内置了哪些键。

I'm aware of the following keys:

我知道以下键:

  • 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
  • GLUT_KEY_F1, GLUT_KEY_F2, ..., GLUT_KEY_F12- F1 到 F12 键
  • GLUT_KEY_PAGE_UP, GLUT_KEY_PAGE_DOWN- Page Up 和 Page Down 键
  • GLUT_KEY_HOME, GLUT_KEY_END- 主页和结束键
  • GLUT_KEY_LEFT, GLUT_KEY_RIGHT, GLUT_KEY_UP, GLUT_KEY_DOWN- 方向键
  • GLUT_KEY_INSERT- 插入键

I either found them in my book or here on Stackoverflow in another post.

我要么在我的书中找到它们,要么在 Stackoverflow 上的另一篇文章中找到它们。

But are there any more? eg, for all keys on a keyboard and mouse?

但是还有吗?例如,对于键盘和鼠标上的所有键?

Thanks.

谢谢。

采纳答案by mr5

glutdivides key in keyboard by glutSpecialFuncw/c takes special keys such as F1,F2..., NUMPADS, etc. while glutKeyboardFunctakes all keys that can be represented by a character like the alphabets, numbers, ESC (27 in 'ASCII'), ENTER (32 in 'ASCII'), etc.

glut将键盘中的键除以glutSpecialFuncw/c 采用特殊键,如 F1、F2...、NUMPADS 等,同时glutKeyboardFunc采用所有可以由字符表示的键,如字母、数字、ESC('ASCII' 中的 27), ENTER('ASCII' 中的 32)等。

in summary, glutKeyboardFunctake charparameters that can be represented without using any '\' (backslash, like '\t', '\n') before any character the rest are handled by glutSpecialFunc

总之,glutKeyboardFunc采取char的是可以在不使用任何来表示参数“\”(反斜杠,像“\ t”的“\ n”)的任何字符之前的其余部分是由处理glutSpecialFunc

回答by Ahmad Abo Bakr

the keyboard have two sets of buttons: those that can be represented using ASCII code and those that could not. the ones that can be represented in ASCII returns 1 byte when pressed, the ones that couldn't return two bytes the first of which is NULL

键盘有两组按钮:可以使用 ASCII 代码表示的按钮和不能使用的按钮。可以用 ASCII 表示的那些按下时返回 1 个字节,不能返回两个字节的那些,其中第一个是NULL

glut abstract this by giving you two set of functions to handle keyboard events: one to handle normal ASCII standard buttons glutKeyboardFunc, the other to handle special two byte buttons glutSpecialFunc

glut 通过为您提供两组处理键盘事件的函数来抽象它:一组处理普通的 ASCII 标准按钮glutKeyboardFunc,另一组处理特殊的两字节按钮 glutSpecialFunc

the special function have constants for common keyboard special buttons :

特殊功能具有常见键盘特殊按钮的常量:

GLUT_KEY_F1:0x0001, GLUT_KEY_F2:0x0002, GLUT_KEY_F3:0x0003, GLUT_KEY_F4:0x0004, GLUT_KEY_F5:0x0005, GLUT_KEY_F6:0x0006, GLUT_KEY_F7:0x0007, GLUT_KEY_F8:0x0008, GLUT_KEY_F9:0x0009, GLUT_KEY_F10:0x000A, GLUT_KEY_F11:0x000B, GLUT_KEY_F12:0x000C, GLUT_KEY_LEFT:0x0064, GLUT_KEY_UP:0x0065, GLUT_KEY_RIGHT:0x0066, GLUT_KEY_DOWN:0x0067, GLUT_KEY_PAGE_UP:0x0068, GLUT_KEY_PAGE_DOWN:0x0069, GLUT_KEY_HOME:0x006A, GLUT_KEY_END:0x006B, GLUT_KEY_INSERT:0x006C, GLUT_KEY_REPEAT_OFF:0x0000, GLUT_KEY_REPEAT_ON:0x0001, GLUT_KEY_REPEAT_DEFAULT:0x0002.

GLUT_KEY_F1:0×0001, GLUT_KEY_F2:0×0002, GLUT_KEY_F3:为0x0003, GLUT_KEY_F4:0x0004, GLUT_KEY_F5:0×0005, GLUT_KEY_F6:0x0006, GLUT_KEY_F7:0x0007, GLUT_KEY_F8:0×0008, GLUT_KEY_F9:为0x0009, GLUT_KEY_F10:0x000A, GLUT_KEY_F11:0x000B, GLUT_KEY_F12:0x000C, GLUT_KEY_LEFT:0x0064, GLUT_KEY_UP:0x0065, GLUT_KEY_RIGHT:0x0066, GLUT_KEY_DOWN:0x0067, GLUT_KEY_PAGE_UP:0x0068 , GLUT_KEY_PAGE_DOWN:0x0069, GLUT_KEY_HOME:0x006A, GLUT_KEY_END:0x006B, GLUT_KEY_INSERT:0x006C, GLUT_KEY_REPEAT_OFF:0x0000, GLUT_KEY_REPEAT_ON:0x0001, GLUT_KEY_REPEAT_DEFAULT:0x0002。

mouse clicks can be handled with the glutMouseFuncand the constants associated with the mouse buttons are: GLUT_LEFT_BUTTON:0x0000, GLUT_MIDDLE_BUTTON:0x0001, GLUT_RIGHT_BUTTON:0x0002

鼠标点击可以用glutMouseFunc和与鼠标按钮关联的常量是: GLUT_LEFT_BUTTON:0x0000, GLUT_MIDDLE_BUTTON:0x0001, GLUT_RIGHT_BUTTON:0x0002

glut can also handle joysticks with the glutJoystickFuncwhich has the following constants: GLUT_HAS_JOYSTICK:0x0264, GLUT_OWNS_JOYSTICK:0x0265, GLUT_JOYSTICK_BUTTONS:0x0266, GLUT_JOYSTICK_AXES:0x0267, GLUT_JOYSTICK_POLL_RATE:0x0268, GLUT_JOYSTICK_BUTTON_A:0x0001, GLUT_JOYSTICK_BUTTON_B:0x0002, GLUT_JOYSTICK_BUTTON_C:0x0004, GLUT_JOYSTICK_BUTTON_D:0x0008.

glut 还可以处理glutJoystickFunc具有以下常量的操纵杆: GLUT_HAS_JOYSTICK:0x0264, GLUT_OWNS_JOYSTICK:0x0265, GLUT_JOYSTICK_BUTTONS:0x0266, GLUT_JOYSTICK_AXES:0x0267, GLUT_JOYSTICK_POLL_RATE:0x0268, GLUT_JOYSTICK_BUTTON_A:0x0001, GLUT_JOYSTICK_BUTTON_B:0x0002, GLUT_JOYSTICK_BUTTON_C:0x0004, GLUT_JOYSTICK_BUTTON_D:0x0008

if you are using a gaming mouse or a keyboard/joystick with more buttons you can test for what each button returns by outputting the button pressed to the console then directly use this value in your code to know if one of those button is pressed

如果您使用的是带有更多按钮的游戏鼠标或键盘/操纵杆,您可以通过将按下的按钮输出到控制台来测试每个按钮返回的内容,然后直接在您的代码中使用此值来了解是否按下了其中一个按钮