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. |
Administrator
|
I was working off this example, from http://jogamp.org/jogl/doc/NEWT-Overview.html:
How to pass user input back to the rendering loop ? The following example shows you how to use a fifo to pipe events from the EDT (listener) to the rendering loop. TestParenting02NEWT.java [v2.0-rc3] KeyAction.java [v2.0-rc3] I have a rendering loop that I want to pass input to and using the EventFifo like in the example seemed like the easiest method. About as much as I know about KeyListeners is that they execute a specified function upon receiving an event. I just want to capture the event information and put it directly in my render loop so I can use it to animate. Any suggestions are welcome |
Administrator
|
On 12/09/2013 12:07 AM, Jake [via jogamp] wrote:
> I was working off this example, from > http://jogamp.org/jogl/doc/NEWT-Overview.html: > > How to pass user input back to the rendering loop ? > > The following example shows you how to use a fifo to pipe events from the EDT > (listener) to the rendering loop. > TestParenting02NEWT.java [v2.0-rc3] > KeyAction.java [v2.0-rc3] > > > I have a rendering loop that I want to pass input to and using the EventFifo > like in the example seemed like the easiest method. > > About as much as I know about KeyListeners is that they execute a specified > function upon receiving an event. I just want to capture the event information > and put it directly in my render loop so I can use it to animate. > > Any suggestions are welcome > signature.asc (911 bytes) Download Attachment |
Administrator
|
In reply to this post by Jake
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. > 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 signature.asc (911 bytes) Download Attachment |
Free forum by Nabble | Edit this page |