Search in sources :

Example 1 with KeyEvent

use of com.jogamp.newt.event.KeyEvent in project narchy by automenta.

the class NEWTKBD method HandleEvents.

private void HandleEvents() {
    int key;
    Jake2InputEvent event;
    while ((event = InputListener.nextEvent()) != null) {
        Window eventWin = null;
        Object source = event.ev.getSource();
        if (source instanceof Window) {
            eventWin = (Window) source;
        }
        switch(event.type) {
            case Jake2InputEvent.KeyPress:
            case Jake2InputEvent.KeyRelease:
                Do_Key_Event(XLateKeyCode((KeyEvent) event.ev), event.type == Jake2InputEvent.KeyPress);
                break;
            case Jake2InputEvent.MotionNotify:
                // }
                if (IN.mouse_active) {
                    mx = (((MouseEvent) event.ev).getX() - win_w2) * 2;
                    my = (((MouseEvent) event.ev).getY() - win_h2) * 2;
                } else {
                    mx = 0;
                    my = 0;
                }
                break;
            case Jake2InputEvent.ButtonPress:
                key = mouseEventToKey((MouseEvent) event.ev);
                Do_Key_Event(key, true);
                break;
            case Jake2InputEvent.ButtonRelease:
                key = mouseEventToKey((MouseEvent) event.ev);
                Do_Key_Event(key, false);
                break;
            case Jake2InputEvent.WheelMoved:
                float dir = ((MouseEvent) event.ev).getRotation()[0];
                if (dir > 0) {
                    Do_Key_Event(Key.K_MWHEELDOWN, true);
                    Do_Key_Event(Key.K_MWHEELDOWN, false);
                } else {
                    Do_Key_Event(Key.K_MWHEELUP, true);
                    Do_Key_Event(Key.K_MWHEELUP, false);
                }
                break;
            case Jake2InputEvent.CreateNotify:
            case Jake2InputEvent.ConfigureNotify:
                handleCreateAndConfigureNotify(eventWin);
                break;
        }
    }
    if (mx != 0 || my != 0) {
        // move the mouse to the window center again
        c.warpPointer(c.getWidth() / 2, c.getHeight() / 2);
    }
}
Also used : Window(com.jogamp.newt.Window) KeyEvent(com.jogamp.newt.event.KeyEvent) MouseEvent(com.jogamp.newt.event.MouseEvent)

Aggregations

Window (com.jogamp.newt.Window)1 KeyEvent (com.jogamp.newt.event.KeyEvent)1 MouseEvent (com.jogamp.newt.event.MouseEvent)1