O'Reilly logo

Android NDK Beginner's Guide by Sylvain Ratabouil

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – handling keyboard, D-Pad, and trackball, natively

First, let's handle keyboard and trackball events.

  1. Open jni/InputHandler.hpp and add keyboard and trackball event handlers:
    #ifndef _PACKT_INPUTHANDLER_HPP_
    #define _PACKT_INPUTHANDLER_HPP_
    
    #include <android/input.h>
    
    namespace packt {
        class InputHandler {
        public:
            virtual ~InputHandler() {};
    
            virtual bool onTouchEvent(AInputEvent* pEvent) = 0;
            virtual bool onKeyboardEvent(AInputEvent* pEvent) = 0;
            virtual bool onTrackballEvent(AInputEvent* pEvent) = 0;
        };
    }
    #endif
  2. Update method processInputEvent() inside the existing file jni/EventLoop.cpp to redirect keyboard and trackball events to InputHandler.

    Trackballs and touch events are assimilated to motion events and can be discriminated ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required