PCSX2 / pcsx2

PCSX2 - The Playstation 2 Emulator
https://pcsx2.net
GNU General Public License v3.0
11.58k stars 1.6k forks source link

[BUG]: Non-character keys not picked up by USB keyboard emulation on Qt builds #7605

Open SlyCooperReloadCoded opened 1 year ago

SlyCooperReloadCoded commented 1 year ago

Describe the Bug

Non-character keys such as Esc, Ctrl, Alt, and F1 - F12 are not recognized by the new USB keyboard emulation for games that use them, but letters, symbols, and the numpad are. With the old 1.6.0 USB keyboard emulation, these worked fine.

Reproduction Steps

Expected Behavior

The affected keys should be picked up by any game that uses them. An easy test for this is any retail copy of Star Wars Starfighter which has debug functions that are available when a USB keyboard is plugged into the system, even on real hardware. Ctrl + P freezes and unfreezes the game, Ctrl + F4 opens debug displays, and Esc + / opens up a command console. None of these work with the new update but work fine on PCSX2 1.6.0. All of the keys on the Numpad and letter rows work fine, even the symbols, so Numpad / and Numpad - still adjust the game camera, for example.

PCSX2 Revision

v1.7.3728

Operating System

Windows 10 (64bit)

If Linux - Specify Distro

No response

Formedras commented 1 year ago

Another game to test with is Dirge of Cerberus: Final Fantasy VII. Spacebar is defaulted to Jump/Confirm there, and that key doesn't work either.

SlyCooperReloadCoded commented 1 year ago

A recent update to the USB Keyboard functionality seems to have fixed this. Esc, Ctrl, and Function row now work for Starfighter like I mentioned. Close if you like, unless it's a temporary fix for something else.

refractionpcsx2 commented 1 year ago

You sure? Cos somebody on our discord is saying they don't work on linux.

SlyCooperReloadCoded commented 1 year ago

Okay actually wait, those keys work now: image

However Shift + Number row doesn't work, so I can't input !@#$%^&*()

agent13 commented 1 year ago

In Monster Hunter games, Shift key won't work. Shift+ key combinatons won't working (Impossible make a "?" for example). ">" key won't working too.

Mrlinkwii commented 1 year ago

can this be recheck on latest nightly

SlyCooperReloadCoded commented 1 year ago

Yep, it's still an issue on latest 1.7. Lowercase letters work, holding shift to enter uppercase letters works, "lowercase" symbols like minus, equals, backslash work, but holding shift and pressing a symbol key to enter the "uppercase" version still doesn't work. I can type HELLO THERE = ME but I can't type HELLO THERE! $ITS ME

I really hope this gets solved. This issue and #7606 are the only two reasons I still keep an old 1.6.0 build around.

F0bes commented 1 year ago

I looked into it a little bit.

QKeyEvent::key() ignores the shift modifier for letters, **but not for other keys such as 1,2,3,[,], etc.


Here is what this means for the curious:

In the case that you wanted to write an exclamation (!) symbol, the current system expects the following events: SHIFT (0x01000020) PRESSED 1 (0x31) PRESSED

It is up to the guest (the emulated PS2) to determine that it is an exclamation mark that is being pressed by these two events.

However, we instead get these events: SHIFT (0x01000020) PRESSED ! (0x21) PRESSED


Qt, why. (edit: It looks like I can't really blame QT for this. The native key codes are completely different :face_exhaling: ) By the way, Megamouse from RPCS3 asked about this 5 years ago and got no answer

We could check the result of QKeyEvent::text() and map the result to keycodes like so: "!" -> 1(0x31) "@" -> 2(0x32)

But I think issues would arise from keyboard layouts where symbols are in different key locations :/

SlyCooperReloadCoded commented 1 year ago

No idea if it's possible, but considering the input menu is blank when you select HID Keyboard in the USB section, a drop-down menu with multiple keyboard layouts could be added so there would be no conflicts.

F0bes commented 1 year ago

It wouldn't be very nice from a UX perspective if we required a user to select that. Hoping that someone with more experience with the input system can chime in.

On Wed, Jul 5, 2023, 11:26 p.m. SlyCooperReloadCoded < @.***> wrote:

No idea if it's possible, but considering the input menu is blank when you select HID Keyboard in the USB section, a drop-down menu with multiple keyboard layouts could be added so there would be no conflicts.

— Reply to this email directly, view it on GitHub https://github.com/PCSX2/pcsx2/issues/7605#issuecomment-1622909814, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG7QDSGZMQFCA2WPOTRJ2CDXOYV6NANCNFSM6AAAAAATCKJVT4 . You are receiving this because you commented.Message ID: @.***>

AmyRoxwell commented 1 year ago

We could check the result of QKeyEvent::text() and map the result to keycodes like so: "!" -> 1(0x31) "@" -> 2(0x32)

But I think issues would arise from keyboard layouts where symbols are in different key locations :/

I wonder tho, have you actually tried to test and see if that could cause issues? Cuz in theory, it can cause problems, but what if it doesn't? It could finally fix this issue that has been on QT since forever, so maybe is worth giving it a try...

SlyCooperReloadCoded commented 1 year ago

Or rather, could PCSX2 detect keyboard layout from the OS?

AmyRoxwell commented 1 year ago

We could also try to just doing per game basis and force a keyboard loadout. (There are probably not many games that use the keyboard) For example, for Japanese games use the standard qwerty japanese loadout, so even if you have a standard US keyboard, the game will just register it as a Japanese keyboard (like how ps2 does it) and for US games, then the US loadout.

Obviously I don't know how complicated could this be to implement and I don't expect this to be easy, but it would be much better than this never being fixed, obviously some keyboards that aren't full size could have some issues typing some symbols, but having to take in account for every keyboard size will take forever (and the ps2 only accepts standard, full size keyboards anyways so...)

AmyRoxwell commented 3 months ago

Just in case someone wants to work on this on the future...

You need to implement the option to bind the alt and tab into a different key, a lot of online games use ALT+Function Key (F1, F4, etc) to do stuff and you may notice that also stuff like alt+f4 is a thing

Other way to do it would be to have it as a toggle-able, so if you press the key it acts like it pressed.

Formedras commented 3 months ago

Just in case someone wants to work on this on the future...

You need to implement the option to bind the alt and tab into a different key, a lot of online games use ALT+Function Key (F1, F4, etc) to do stuff and you may notice that also stuff like alt+f4 is a thing

Other way to do it would be to have it as a toggle-able, so if you press the key it acts like it pressed.

I think I'd like to see the keyboard Menu key (the one between Right Start and Right Ctrl) be used as a toggle between [having the emulated PS2 own the keyboard] and [normal function], at least as a default. (But also for upcoming laptops, maybe also Left Shift+Left Super+F23 since that's what the Copilot key is mapped to, and Copilot seems to be replacing Menu and/or Right Ctrl on laptops with that key?)

SlyCooperReloadCoded commented 3 months ago

I recently saw how RPCS3 handles this - they do appear hardcode every keyboard layout for every region, which is likely how they get symbol keys (and possibly left/right Ctrl/Alt, haven't checked if they differentiate but it probably does) to work regardless of OS-defined layout. I don't see any reason why that can't be implemented here unless I'm missing something obvious.

SlyCooperReloadCoded commented 2 months ago

There's been another regression. The Period key on the main part of the keyboard no longer registers, but the Period key on the numpad still works.

AmyRoxwell commented 1 week ago

@SlyCooperReloadCoded Maybe give #11829 a go?

SlyCooperReloadCoded commented 1 week ago

How do I build that? I looked for the artifacts page but I don't see it.

AmyRoxwell commented 1 week ago

How do I build that? I looked for the artifacts page but I don't see it.

https://github.com/PCSX2/pcsx2/actions/runs/10926258620?pr=11829 Scroll down, this is the windows one https://github.com/PCSX2/pcsx2/actions/runs/10926258617?pr=11829 This is the linux one

AmyRoxwell commented 1 week ago

11829 has almost fixed all the issues with the current keyboard implementation, but there is still some issues with the current implementation:

  1. There are games that use the Function keys (F1-F12) that have extra actions while holding Alt, you may notice that if you use alt + F4 you will close the emulator. (The game that uses this the most is Monster Hunter 2 dos, where you can emote faster by holding ALT + Function key.)

We need to find a way to make ALT toggle-able so you can access those extra functions without activating windows/linux keyboard default shortcuts.

  1. Currently, activating Caps Lock on all monster hunter games is impossible due to the emulator not detecting the "Shift + Caps Lock" combo (It may affect also "Outbreak File 1 and 2" and "Automodellista".)
SlyCooperReloadCoded commented 1 week ago

With the new merged PR, Tilde (`), its Shift version (~), Numpad Asterisk, and Numpad Plus don't do anything when pressed. Star Wars Starfighter games use those keys, and it uses the Numpad versions of keys for separate functions than the main keyboard versions.

The rest of the keys and symbols work now. So close!

AmyRoxwell commented 1 week ago

@SlyCooperReloadCoded did they work before the pr?

SlyCooperReloadCoded commented 1 week ago

The Shift version of Tidle definitely didn't. I don't think the others worked before, but this doesn't fix any of them. They might be able to be added just looking at how this PR works.

AmyRoxwell commented 6 days ago

PCSX2 throws this on the log while having hid enabled:

image