Main Menu

Alt key

Started by Gram01, March 13, 2014, 02:42:45 PM

Previous topic - Next topic

Gram01

How to correctly distinguish the pressing Alt?
when I call the following code at the output.
I get no code pressing Alt I get zero

KeyMapper keyMapper = new KeyMapper();
KeyState ks;
while( ( ks = keyMapper.poll() ) != KeyState.NONE )
{         
           System.out.println(KeyEvent.getKeyText(ks.getKeyCode())+" "+ks.getChar());                                                     


if I press alt then the output I get
Unknown keyCode: 0x0
if I press Shift then the output I get
Shift

EgonOlsen


Gram01

works on the left alt, now I get 2 of the code, by pressing alt-one of them is correct, on the right 2 also shows the code but both are wrong, the same problem exists when pressing the print screen.
if I press left alt then the output I get:
Alt
Unknown keyCode: 0x0
if i press right alt then the output I get:
Unknown keyCode: 0x0
Unknown keyCode: 0x0

I guess it's codes of pressing and releasing the alt button, when pressed, for example on d button I get:
D d
D

EgonOlsen

I'm using the LWJGL constants for the keys. Unfortunately LWJGL doesn't know the ALT-keys (for whatever reasons). They only know LMENU and RMENU, which (at least according to my findings) should map to ALT too. That's what i'm using in this version, but it doesn't seem to work reliable. Do you really have to use the ALT-keys? I'm not sure what i should do know...

BTW: Which OS are you using?

Gram01

I'm using Windows 7. Thought there is a solution that allows using KeyMapper identify pressing any key on the keyboard (the internal key name is not important, the main thing is the uniqueness), which I could not find in the documentation. Apparently not, will have to use JOGL.

EgonOlsen

There are constants defined by LWJGL which the KeyMapper maps to AWT KeyEvents. The problem is that if i don't know which keys reflect the ALT key (because i can't find constants for ALT in LWJGL) or if that somehow doesn't work, i can't map them...
I can post the code for the KeyMapper if that would help. Anyway, i don't get the JOGL idea. You can use the AWTGLRenderer of LWJGL instead which lets you work with AWT key event directly. No need to switch to JOGL.