Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4581716
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:58:07+00:00 2026-05-21T20:58:07+00:00

I have an Android NDK game (NDK 4.) Almost all of the code is

  • 0

I have an Android NDK game (NDK 4.) Almost all of the code is in C++ (it’s a port) so in the Java all I have is an Activity and a GLSurfaceView with an override for onTouchEvents. I’m trying to figure out how to receive key press events so that I can forward them on to the native code to be handled.

I tried having the View implement OnKeyListener but onKey() is never called. Also tried overriding the onKeyDown() and onKeyUp() in the View with no success. Am I missing something?

Update

The View as I’m currently using it:

public class FooView extends GLSurfaceView implements SurfaceHolder.Callback, OnKeyListener
{
    private GameRenderer _renderer;
    private GameListener _listener;

    public FooView(Context context)
    {
        super(context);
        this._renderer = new GameRenderer();
        setRenderer(this._renderer);
        this._listener = new GameListener(context);
        BaseLib.setListener(this._listener);
    }

    @Override
    public boolean onTouchEvent(final MotionEvent event)
    {
        // touch code...
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        Log.d("testing", "onKeyDown event from Java");
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event)
    {
        Log.d("testing", "onKeyUp event from Java");
        return super.onKeyUp(keyCode, event);
    }

    @Override
    public boolean onKey(View view, int keyCode, KeyEvent event)
    {
        Log.d("testing", "onKey event from Java");
        return true;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T20:58:08+00:00Added an answer on May 21, 2026 at 8:58 pm

    Try this:

      @Override
      public boolean dispatchKeyEvent(KeyEvent event)
      {
              //
              // SEND event.getAction() to your NDK code
              //
              if(<NDK CODE PROCESSED IT>) return true;
    
              // default behavior for everything else
              return super.dispatchKeyEvent(event);
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a game in android with java not ndk.I want to
I have a C++ Android application that I'm trying to debug with ndk-gdb. The
I'm trying to make an NDK-based game work on Android ICS. It worked fine
I have android.permission.READ_OWNER_DATA but I can't find any reliable code that would explain how
I'm writing a game using android ndk. I'm using picking to select objects in
Ahoy, I'm working on an OpenGL ES based game for Android using the NDK.
I have installed Android NDK and want to make eclipse highlight c-source. How ?
the Android ndk is hard to use for the old autoconf based code, so
i have try to create new ndk project in eclipse i have done all
I have an Android NDK project. Windows 7, Cygwin, NDK r6b. The Android.mk references

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.