Full Keyboard Input

I just realized something… Right now all the keyboard handling is comming from the perspective of checking if a particular key is down or not. That’s great if we have a limited set of keys that respond to specific actions…



I’m working on the EditBox control and realized that there is not good current way of handling just standard typing of text without registering for every key individually… and therefore looping through all the keys and checking if the key is down.



Anyhow, while I take a look at this for the next few hours I’d like to hear what others think for ideas of how to approach this problem.

When I had the problem in JME I solved it by gowing throw all of the keys and cheking if thay are down. Then returning the first one down. I worked almost all of the time. The only part it had troble with is when there was two keys down.( I think you could solve the problem.)

"guurk" wrote:
Anyhow, while I take a look at this for the next few hours I'd like to hear what others think for ideas of how to approach this problem.

Write your own InputHandler and loop through the keys - that's the way I did this.

    public void update(float time) {
        /* call base class method */
        super.update(time);
       
        for (int i = 0; i < 255; i++) {
            if (keyInput.isKeyDown(i)) {
                String codeName = keyInput.getKeyName(i);
                // do your own stuff here
            }
        }

Really wanted to stay away from looping… I notice that the underlying LWJGL Keyboard class can get the current key for the event. Just need to figure out how to get the event…

Ok… topic from LWJGL…



http://puppygames.net/forums/viewtopic.php?t=466&highlight=keyboard+event



You can also put the keyboard in buffered mode and then loop through only they keys that are down.



I’m going to add to the InputHandler a way to add a generic KeyboardAction that will recieve the event based key. So when any key is pressed, the registered KeyboardAction will be called with key that triggered the event as a parameter.

Checked in changes here… doesn’t affect current functionality.



Use like this:



      input.addBufferedKeyAction( new AbstractInputAction() {
            public void performAction(float time) {
                System.out.println( this.key);
            }
        });



The advantage?... you don't loop through ALL keys, just those that have changed state.