Time for action – handling keyboard, D-Pad, and trackball events natively
Let's extend our new Input system with more event types:
- Open
jni/InputHandler.hpp
and add the keyboard and trackball event handlers:#ifndef _PACKT_INPUTHANDLER_HPP_ #define _PACKT_INPUTHANDLER_HPP_ #include <android/input.h> class InputHandler { public: virtual ~InputHandler() {}; virtual bool onTouchEvent(AInputEvent* pEvent) = 0; virtual bool onKeyboardEvent(AInputEvent* pEvent) = 0; virtual bool onTrackballEvent(AInputEvent* pEvent) = 0; }; #endif
- Update the method
processInputEvent()
inside the existing filejni/EventLoop.cpp
to redirect the keyboard and trackball events toInputHandler
.Trackballs and touch events are assimilated to motion events and can be discriminated ...
Get Android NDK Beginner's Guide - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.