1

キーが押されたかどうかを取得するために LWJGL を使用しようとしています。エスケープ キーが押されると、アプリケーションは終了します。ただし、正常にDisplay.isCloseRequested()動作しますが、キーボード入力を読み取ることはできません。

LWJGL 2.6 と Java 1.6 を使用して RHEL を使用しています。

for(;;) {
    // check if we want to quit

    if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
        System.exit(0);  // can't get this to happen!
    }
    if(Display.isCloseRequested()) {
        System.exit(0);
    }

/* timer code omitted */

    render();
    Display.update();
}

編集:同じバージョンのlwjglとJREを使用して、まったく同じコードが私のWindowsボックスで完全に正常に動作します。

4

2 に答える 2

0

関数でキーボードが作成されているかどうかを確認できisCreatedますか?

それ以外は、私はプログラミングが得意ではないので、他の情報を提供することはできません.

これを試して

Keyboard.isCreated()
于 2011-04-20T12:18:06.317 に答える
0

私は役に立たないかもしれないし、役に立たないかもしれません/ここで死んだトピックを復活させます.

これは、Zdeva エンジンからの入力クラスです。

「エンジン」全体をダウンロードする必要はありません。

package LWJGL;

import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;

public class Input 
{
    public static boolean[] mouseButtons = {false, false, false};
    public static int[] mousePos = new int[Mouse.getButtonCount()];
    public static int[] keysBound = {Keyboard.KEY_A, Keyboard.KEY_B};

    /**
     * Initializes the input system. Loads keyconfig.
     * 
     */
    public static void init()
    {
        System.out.println("Initializing input system...");
        //Eventually will check for OS, and adjust keys accordingly.
        System.out.println("Input system initialized!");
    }

    /**
     * Updates all mouse info, keys bound, and performs actions.
     */
    public static void tick()
    {
        mouseButtons[0] = Mouse.isButtonDown(0);
        mouseButtons[1] = Mouse.isButtonDown(1);

        mousePos[0] = Mouse.getX();
        mousePos[1] = Mouse.getY();

        while(Keyboard.next())
        {
            if(Keyboard.getEventKeyState())
            {
                doAction(Keyboard.getEventKey(), false);
            }
        }

        for(int key : keysBound)
        {
            if(Keyboard.isKeyDown(key))
            {
                doAction(key, true);
            }
        }

        while(Mouse.next())
        {
            doAction(-1, false);
        }
        doAction(0, true);  
    }

    /**
     * Does the associated action for each key. Called automatically from tick.
     * @param key The key to check & perform associated action
     */
    public static void doAction(int key, boolean ifRepeat)
    {
        if(mouseButtons[0])
        {

        }
        if(mouseButtons[1])
        {

        }
        if(key == keysBound[0] & ifRepeat)
        {
            System.out.println("a");
        }
        if(key == keysBound[1] & !ifRepeat)
        {
            System.out.println("b");            
        }
    }
}
于 2013-11-12T02:43:42.050 に答える