moonlight-stream / moonlight-android

GameStream client for Android
GNU General Public License v3.0
3.23k stars 512 forks source link

Xiaomi Gamepad has wrong keymap #92

Closed woodleader closed 8 years ago

woodleader commented 8 years ago

The Xiaomi Gamepad does not work with Moonlight. The Android OS recognizes the right keymap, but Somehow Moonlight doesnt. The A button on the Controller gets swapped with the B button. Any other button does not seem to work although the analog sticks are working fine. If needed I can try to provide more information that would be needed to implement the right keymap.

buster39 commented 8 years ago

Would love to use that cheap and robust gamepad with moonlight too. If I can help with testing or anything other than coding, give me a call.

5H00T4 commented 8 years ago

Yup, same here. Happens on Fire TV and Android App (via tablet). Button mapping of the controller is fine in every other map.

Please consider looking at it, if you need additional data or logs etc. don't hesitate to ask. Moonlight was the main reason I bought the Xiaomi controller.

zven73 commented 8 years ago

+1

oswalya commented 8 years ago

Would also love if someone yould fix this :)

ZombieBear commented 8 years ago

I'm disappointed at how long this has gone without a fix. I can't even seem to find where the key mapping is handled in the code to try and solve this.

cgutman commented 8 years ago

I haven't dealt with this and other mapping issues because the next major version of Moonlight will support controller mapping.

Another thing, I'm using all standard Android button codes. The fact that the Xiaomi controller doesn't work is because they aren't sending the correct key codes that the Android input API expects. The only controller that Moonlight supports that sends incorrect keycodes is the PS4 controller, which was popular enough to warrant hacking around the issue (and long ago where controller mapping wasn't being considered).

The controller code is in ControllerHandler.java. If you want to take a stab at it, I would accept a PR that added support for the controller as long as it wasn't too messy.

5H00T4 commented 8 years ago

Cameron is right, it's really the Xiaomi Controllers fault. It works correctly in Android, but for some reason the mapping is completely bonkers outside of it. It also happens in Windows 7 and 10, and you have to use workarounds for games to work correctly. I am interested when the next major version with button mapping will come, any ETA?

brianumbrellaus commented 8 years ago

Here is my solution, root access required.

Connect gamepad via Bluetooth.

Download and install the Terminal Emulator, press more and check "Default to UTF-8", go back. Type "cat /proc/bus/input/devices", there should be a name call "小米蓝牙手柄“ or "XiaoMi Bluetooth Wireless GameController". Write down its Vendor CODE and Product CODE.

Download the file 1.txt Rename as "Vendor_YOUR VENDOR CODE_Product_YOUR PRODUCT CODE.kl" For example, my vendor code is 2717 and my Product code is 3144, so the file name is "Vendor_2717_Product_3144.kl"

Use root explorer or other root file manager to place the file to "/system/usr/keylayout/"

Download the file 2.txt Rename as "Vendor_YOUR VENDOR CODE_Product_YOUR PRODUCT CODE.kcm" and place it to "/system/usr/keychars/"

Reconnect gamepad.

Done.

ZombieBear commented 8 years ago

Any news on how long until the version with button mapping is out? I can't use this fix cause my nexus player isn't rooted

Akeid commented 8 years ago

It would be nice if you guys could push an update for the xiaomi controller. Brianumbrellaus's modifications seem to do the trick, however, the D-pad buttons do not work.

cgutman commented 8 years ago

Ok, I think it will just be easier to create a mapping since so many people are affected.

Please remove any new kl or kcm files added for the gamepad (undo Brianumbrellaus's modifications) or pair to a device without the modifications.

Run this app: https://play.google.com/store/apps/details?id=com.chiarly.gamepad&hl=en

Go through all of the buttons on the controller and write down the mapping for each. For example: A: 1 B: 5 X: 4 Y: 6 L1: 8 and so on...

Post the mapping here and I'll add it.

ZombieBear commented 8 years ago

A 96 B 97 X 99 Y 100 L1 102 R1 103 L2 104 R2 105 TL 106 TR 107 START 108 SELECT 109 Up HatY-1.0 Down HatY+1.0 Left HatX-1.0 Right HatX+1.0

cgutman commented 8 years ago

That's weird, because that seems to be the default mapping in Android (and correct). I have a theory of why it's not working though. Can you collect ADB logcat logs with this modified APK, upload them to pastebin.com, and drop a link here?

https://onedrive.live.com/redir?resid=C15BF9770619F56!162075&authkey=!AFpJyzCmUfSX1X8&ithint=file%2capk

ZombieBear commented 8 years ago

Hope this works had to use my phone cause I don't have a lo g enough cable to reach the Nexus player http://pastebin.com/aYsyqavv

cgutman commented 8 years ago

@ZombieBear Sorry, I made a mistake in my instructions. While the logging is running, you should start a stream from your PC and push some buttons on the Xiaomi controller.

ZombieBear commented 8 years ago

I did, launched binding of Isaac rebirth and tried every button

ZombieBear commented 8 years ago

Played through a few rooms, mapping was all over the place, b worked as a, a as X, X as y, y as left bumper

cgutman commented 8 years ago

@ZombieBear ok, maybe try immediately stopping the log after pressing 1 button.

If you get the data I'm looking for, you'll see the text "Creating controller context for device" appear in the log.

ZombieBear commented 8 years ago

Here we go, confirmed the line's there https://drive.google.com/open?id=0B1HJwgCS8FlGUXAtNFhsXzRxUFk

cgutman commented 8 years ago

OK, try this build. Please check that all buttons, sticks, and triggers are mapped correctly.

https://onedrive.live.com/redir?resid=C15BF9770619F56!162076&authkey=!ABt-oRg3QtrVDyU&ithint=file%2capk

ZombieBear commented 8 years ago

Everything but the back button!

ZombieBear commented 8 years ago

That being select

cgutman commented 8 years ago

@ZombieBear does it back out of streaming or just do nothing?

ZombieBear commented 8 years ago

nothing

cgutman commented 8 years ago

@ZombieBear ok, one more time. Give this build a try. If the back button works correctly, let me know. If not, please take another log and look for that same line. In either case, please confirm that the triggers are definitely working correctly too.

https://onedrive.live.com/redir?resid=C15BF9770619F56!162077&authkey=!ANYOJwdglkjjgMU&ithint=file%2capk

ZombieBear commented 8 years ago

Flawless! Thanks dude!

cgutman commented 8 years ago

@ZombieBear ok, you're sure that the triggers aren't swapped (L2 is R2)?

ZombieBear commented 8 years ago

Yeah they're good :D

cgutman commented 8 years ago

Fixed by https://github.com/moonlight-stream/moonlight-android/commit/25ccc3d0e165a522abbe14c7b57f68e710076780

cgutman commented 8 years ago

Fix released in v4.5.9. Thanks for your help.