Printable/modifier key filter

Started by mot, July 25, 2006, 11:42:17

Previous topic - Next topic

mot

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...

Fool Running

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:
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

mot

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.

Fool Running

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
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

oNyx

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.