Git Product home page Git Product logo

n_gamepad's Introduction

n Gamepad

A Flutter plugin to listen to game controller inputs.

Features

  • Allows listening to controller inputs from gamepad accessories on Android phones
  • Provides a framework to implement multi-device functionality, as demonstrated in this video

Getting started

Add the following lines of code to your FlutterActivity in order to override Android's standard input settings for gamepads:

class MainActivity : FlutterActivity() {
    private lateinit var view: View

    override fun onStart() {
        super.onStart()

        view = window.findViewById<ViewGroup>(FLUTTER_VIEW_ID).getChildAt(0)
    }

    override fun dispatchKeyEvent(event: KeyEvent?): Boolean {
        return view.dispatchKeyEvent(event)
    }
}

This configuration step is necessary for the proper functioning of the plugin on the Android platform.

Usage

Access the Gamepad.instance and assign handlers to a specific Button, the dpad, joysticks, and triggers. To reset individual input handlers, call the same method without specifying any functions.

// Sets onPress and onRelease handler for the A button
Gamepad.instance.assignButtonListener(Button.a, onPress: (event) {}, onRelease: (event) {});
// Resets onPress and sets onRelease handler for the B button
Gamepad.instance.assignButtonListener(Button.b, onRelease: (event) {});
// Sets onUse handler for the right joystick
Gamepad.instance.assignJoystickListener(Hand.right, onUse: (event) {});
// Resets onPress and onRelease handler of B button
Gamepad.instance.assignButtonListener(Button.b);
// Resets handlers for all input controls
Gamepad.instance.resetControls();

Additional information

For comprehensive documentation on the network capabilities, please refer to the nx Gamepad repository.

n_gamepad's People

Contributors

devenju avatar

Stargazers

Max Weber avatar Maksim Lin avatar

Watchers

 avatar

Forkers

jddl

n_gamepad's Issues

How to read unsupportted gamepad events?

Hello,

This is not a bug report. I just need help, and I think you may have knowledge for solving this problem.

I am developing an Android TV (game like) app with flutter. This app will use gamepad interactions to control the app. I tested with your flutter plugin, but failed to see the gamepad in 2.4 GHz wireless USB dongle connection.

For testing purposes, I just bought a gamepad (Pusat Clutch) which has 2 connection method:

  1. bluetooth (android is fully supported by the vendor)
  2. 2.4 GHz wireless with USB dongle (android is not supported by the vendor)

When I connect it to an android phone with bluetooth connection, everything works like a charm. I can detect it as Pusat gamepad on Android with java or flutter code. I can read keyEvents, motionEvents. When I test it with Game Controller Test app, it detects it as Pusat gamepad, and works excellent. No problem at all.

Game Controller Test app: https://play.google.com/store/apps/details?id=uk.co.powgames.gamecondiag

But when I connect it to an Android TV with 2.4 GHz wireless with USB dongle, and open Game Controller Test app, it detects this gamepad as Nintendo Switch gamepad. Test is ok, all buttons are working fine. But when I try to read keyEvents and motionEvents with java code or flutter code or with your plugin, I don't get any events.

How can I read keyEvents and motionEvents from 2.4 GHz wireless USB dongle connected gamepad like Game Controller Test app did with java (or with kotlin) or with your plugin in Android?

I use following java code to test that if I get any event from the gamepad. This code works for bluetooth connection, but does not work for 2.4 GHz with USB dongle connection.

Thanks for help

 @Override
        public boolean onGenericMotionEvent(MotionEvent event) {
            TextView textView = (TextView) findViewById(R.id.text);
            textView.setText("onGenericMotionEvent");
            return super.onGenericMotionEvent(event);
        }

        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            TextView textView = (TextView) findViewById(R.id.text);
            textView.setText("onKeyDown");
            return super.onKeyDown(keyCode, event);
        }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.