PabloMK7 / citra

A Nintendo 3DS Emulator
GNU General Public License v2.0
3.75k stars 634 forks source link

[android] Question: Handling of keyCode #184

Closed newhinton closed 4 months ago

newhinton commented 4 months ago

Issue

While working on the quicksave-feature, i encountered a strange bug.

I was using a stadia-controller for my testing. This controller features two "social media"-buttons (i think they were used for sharing screenshots). When using those buttons, they get both recognized as Button 0.

I then tried out the "home" button on my 8bitdo sn30 pro, which was also assigned as button 0.

Now my question: Is it sufficient to only use keyCode for recognizing different buttons?

I guess this is not that problematic, since there currently are not that many hotkeys, and many controller don't have two non-standard buttons.

One idea i had to work around this problem was to fall back to the scancode if the keycode was 0. I don't know if that has side effects with actual controllers. (At least my two dont have an actual 0-key)

What do you think, would you accept a PR that implements said fallback?

PabloMK7 commented 4 months ago

Is this behavior documented somewhere?

newhinton commented 4 months ago

Yes it is! (Kind of, at least)

At first i missread the documentation, and overlooked that key_0 is not value 0.

So if the press returns 0 from the input device, that actually means unknown key:

https://developer.android.com/reference/android/view/KeyEvent#KEYCODE_UNKNOWN

So by falling back to the scan code, we would most certainly be handling it better than before, though the docs state that the scan code is "unreliable"

Retrieve the hardware key id of this key event. These values are not reliable and vary from device to device.

Mostly this is here for debugging purposes.

I am not sure if this only changes between actual devices, so that button 703 is always 703, or if that changes between reconnects/restarts.

Though, i guess since it's a scan code, it should be stable per device. But i can't guarantee it.

PabloMK7 commented 4 months ago

As long as it persists between launches for the same controller, it should be fine. In any case if you are going to make a PR make sure to add a comment explaining this for the future.