English 中文(简体)
如何在 GLUT 中检测命令/ Alt/ conter/ fn 密钥
原标题:How to detect Command/alt/control/fn keys in GLUT

我探测到关键急迫性,对用fn(功能)、ctrl(控制)、alt(功能)和fn(功能)检测有某些问题。

我可以检测空间栏、 输入、 ESC、 字母、 数字和光标。 但我无法检测我之前告诉过的特殊密钥 。 当我按下这些密钥时, 这两种方法都不显示屏幕上的任何信息 。

检测普通密钥 的方法

void KeyboardFunc(unsigned char key, int x, int y)
{
    int numeros;

    Key[key] = true;

    cout << "-----------------" << endl;
    cout << "PULSE " << (int) key << endl;
    cout << "-----------------" << endl;

    if(key >= 48 && key < 58)
    {
        numeros = key; 
        key =  a ;  
    }

    switch ( key ) 
    {
        case    :   // Space bar
            cout << "Barra Espaciadora pulsada." << endl;
            break;
        case 13:    // #13 es Enter
            cout << "Enter pulsada." << endl;
            break;   
        case 27:    // "27" is the Escape key
            cout << "Tecla ESC pulsada." << endl;
            exit(1);
        case  a :   // Teclado numérico.
            cout << "Número pulsado: " << numeros - 48 << endl;
            key = numeros;    
    }
}

检测特殊密钥的方法:

void SpecialFunc(int key, int x, int y)
{
    Arrow[key] = true;

    cout << "-----------------" << endl;
    cout << "ESPECIAL PULSADO: " << (int) key << endl;
    cout << "-----------------" << endl;

    switch ( key ) 
    {
        case GLUT_KEY_UP:    // #73 es cursor arriba
            cout << "Cursor ARRIBA pulsada." << endl;
            break;
        case GLUT_KEY_DOWN:    // #81 es cursor abajo
            cout << "Cursor ABAJO pulsada." << endl;
            break;
        case GLUT_KEY_LEFT:    // #73 es cursor izquierda
            cout << "Cursor IZQUIERDA pulsada." << endl;
            break;
        case GLUT_KEY_RIGHT:    // #81 es cursor derecha
            cout << "Cursor DERECHA pulsada." << endl;
            break;    
        case 30:    // #30 es alt_a     
            cout << "Tecla ALT pulsada." << endl;
            break;    
    }
}
最佳回答

你可以转到SDL 找到凶器的来源

http://brutalches.sourceforge.net/" rel="no follow">http://brutalches.sourceforge.net/

并查看其中如何处理密钥 。 datenwolf 是正确的, 打开gl 与输入( 鼠、 键、 窗口焦点等) 无关 。 您也可以尝试 SFML, 它比 SDL 简单

http://rastergrid.com/blog/downloads/mountains-demo/" rel="nofollow" >http://rastergrid.com/blog/downloads/mountains-demo/

SDL比SFML更灵活,例如,KEY-PRESS不同于KEY-RELASE。

问题回答

OpenGL 不处理用户输入。 它是一个绘图 API, 仅包含将点、 线和三角带获取到光栅像素图缓冲 。

您现在使用的是“ em> GLUT < / em”, 这是用于小型 OpenGL演示的相当简单的框架 。 < em> GLUT 不属于 OpenGLL! 如果 GLUT 不再满足您的需求, 该是时候继续使用一个更有能力的框架, 或者从头开始所有窗口和输入处理 。

我知道这篇文章很旧 但我只是碰巧在寻找别的东西时 找到了它

无论如何, 答案,因为它可能帮助其他人 在将来。

GLUT实际上支持 ALT事件... 被逼迫。

GLUT_effactive_SHIFT — — 设定您是否按 SHIFT 键, 或Caps Lock 正在打开。 请注意, 如果两者都在, 那么则没有设置常数 。

GLUT_Adactive_CTRL - 按 CTRL 键时设定 。

GLUT_effactive_ALT — 如果您按 ALT 键, 请设定 。

你要做的就是:

void processNormalKeys(unsigned char key, int x, int y) {

if (key == 27)
    exit(0);
else if (key== r ) {
    int mod = glutGetModifiers();
    if (mod == GLUT_ACTIVE_ALT)
        //piece of code
    else if(//...)
        //piece of code
}}




相关问题
2 mysql instances in MAC

i recently switched to mac. first and foremost i installed xampp. then for django-python-mysql connectivity, i "somehow" ended up installing a seperate MySQL. now the seperate mysql installation is ...

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Controlling OSX windows

I m trying to control windows of a foreign OSX applications from my application. I d like to 1. move the windows on the screen 2. resize the windows on the screen 3. change the currently active window ...

Switching J2SE versions on Mac OS (SnowLeopard)

My current JDK on Mac OS (10.6) is set to 1.6 and I d like to switch to 1.5. A listing of /System/Library/Frameworks/JavaVM.framework/Versions/ shows: lrwxr-xr-x 1 root wheel 10 Nov 3 18:34 ...

Scrolling inside Vim in Mac s Terminal

I ve been googling around trying to figure out if it s possible to use my mouse wheel to scroll while inside Vim in Mac s Terminal, with no luck. It seems as if only X11 or iTerm support this. Before ...

export to MP3 from quicktime API

A question for Apple,QT programmers. Would like to know if it s possible to export a Movie object to MP3 using the QuickTime API. Preferably the ConvertMovieToFile function. I ve looked at ...

热门标签