Author Topic: Alt key  (Read 1079 times)

Offline Gram01

  • byte
  • *
  • Posts: 3
    • View Profile
Alt key
« on: March 13, 2014, 02:42:45 pm »
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
Code: [Select]
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Alt key
« Reply #1 on: March 13, 2014, 08:31:17 pm »

Offline Gram01

  • byte
  • *
  • Posts: 3
    • View Profile
Re: Alt key
« Reply #2 on: March 14, 2014, 05:24:18 am »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Alt key
« Reply #3 on: March 14, 2014, 07:41:16 am »
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?

Offline Gram01

  • byte
  • *
  • Posts: 3
    • View Profile
Re: Alt key
« Reply #4 on: March 14, 2014, 10:17:29 am »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Alt key
« Reply #5 on: March 14, 2014, 12:13:48 pm »
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.