LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: mot on July 25, 2006, 11:42:17

Title: Printable/modifier key filter
Post by: mot on July 25, 2006, 11:42:17
Hi, is it possible to tell what keys coming from LWJGL input are printable
characters (not alt/ctrl/shift/pause/F1/F2 etc.)?
The next best thing to trying to get advice from here that I could think of
is a large switch statement with all Keyboard.KEY_ constants...
Title: hmmmmm...
Post by: Fool Running on July 27, 2006, 23:43:27
I'm not sure if there is an easy way of doing it, but I think you can just use ranges of values (like 'a' to 'z', 'A' to 'Z', etc.) to simplify it a little bit.

You might be able to do Keyboard.getEventCharacter() to see if it is printable (i.e. if it actually returns a char), but I'm not sure of that.

Someone else can chime in here :lol:
Title: Printable/modifier key filter
Post by: mot on July 28, 2006, 18:23:56
Thanks for your reply. I solved it with a big hammer, something like this:


public class KeyFilterPrintable implements KeyFilter {
private static String validCharacters =
"`1234567890!{}:|!?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

public boolean isValidKey( int key, char character ) {
return validCharacters.indexOf( character ) != -1;
}
}


And I pass the result of Keyboard.getEventCharacter() as the second parameter to isValidKey.
Title: hmmmmm...
Post by: Fool Running on July 29, 2006, 18:31:02
Well, definitly better than a big switch statement. :lol:

Gonna have to remember this when I need it later (if you don't mind me stealing you're ideas) :D
Title: Re: hmmmmm...
Post by: oNyx on August 01, 2006, 07:27:55
Quote from: "Fool Running"[...]

You might be able to do Keyboard.getEventCharacter() to see if it is printable (i.e. if it actually returns a char), but I'm not sure of that.

[...]

Yea, it should return Keyboard.CHAR_NONE in those non printable cases.