Posted by
Sven Gothel on
Dec 09, 2013; 1:01am
URL: https://forum.jogamp.org/NEWT-KeyEvent-Function-Key-Trouble-tp4030828p4030834.html
On 12/08/2013 09:10 PM, Jake [via jogamp] wrote:
> I'm trying to make a simple input control using NEWT so that pressing F9 sets
> my GLWindow to fullscreen and F12 destroys the window.
>
> Here is my code:
>
> while( null != ( event = (NEWTEvent) eventFifo.get() ) ) {
> Window source = (Window) event.getSource();
>
> if(event instanceof KeyEvent) {
>
> KeyEvent keyEvent = (KeyEvent) event;
>
> switch(keyEvent.getKeyCode()) {
>
> case KeyEvent.VK_F9:
> source.setFullscreen(!source.isFullscreen());
> break;
>
> case KeyEvent.VK_F12:
> shouldQuit = true;
> break;
> }
> }
> }
>
> The problem is the if clause returns false whenever I hit a function key but
> true if I type anything else(a-z). However I still receive the following
> output for function keys:
>
> KeyEvent[EVENT_KEY_PRESSED, code 0x69, sym 0x69, char ' ' (0x0), printable
> false, modifier false, action true, InputEvent[modifiers: [],
> NEWTEvent[source:jogamp.newt.driver.windows.WindowDriver, consumed false,
> when:1386532337539 d 0ms]]]
>
> KeyEvent[EVENT_KEY_RELEASED, code 0x69, sym 0x69, char ' ' (0x0), printable
> false, modifier false, action true, InputEvent[modifiers: [],
> NEWTEvent[source:jogamp.newt.driver.windows.WindowDriver, consumed false,
> when:1386532337753 d 0ms]]]
>
> I also tried outputting the value of event.getEventType() for a-z keys and
> function keys. a-z yields a result of 301 which is a KeyEvent but the function
> keys didn't output anything. This was done using
> System.out.println(event.getEventType())
>
> Any help would be appreciated and sorry if I'm just doing something dumb, I'm
> still rather new to this.
>
KeyEvent.VK_F9 == 0x69 - right.
Your dump shows it is a KeyEvent.
If you use the original test code 'KeyAction',
you will notice it only 'records' the printable keys, see below.
Hence you need your own 'KeyAction' impl. to record all desired keys.
+++
class KeyAction extends KeyAdapter {
NEWTEventFiFo eventFifo;
...
public void keyReleased(KeyEvent e) {
if( !e.isPrintableKey() || e.isAutoRepeat() ) {
return;
}
eventFifo.put(e);
}
}
+++
~Sven