pcsx2 icon indicating copy to clipboard operation
pcsx2 copied to clipboard

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

Open SlyCooperReloadCoded opened this issue 2 years ago • 26 comments

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

  • Unbind hotkeys that use Esc, Ctrl, Alt, Function row, etc
  • Launch USB keyboard-compatible game with USB set to HID Keyboard
  • Try to use these keys during gameplay, they won't register

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

SlyCooperReloadCoded avatar Dec 18 '22 05:12 SlyCooperReloadCoded

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.

Formedras avatar Dec 22 '22 04:12 Formedras

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.

SlyCooperReloadCoded avatar Dec 24 '22 05:12 SlyCooperReloadCoded

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

refractionpcsx2 avatar Dec 24 '22 05:12 refractionpcsx2

Okay actually wait, those keys work now: image

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

SlyCooperReloadCoded avatar Dec 24 '22 05:12 SlyCooperReloadCoded

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.

agent13 avatar Dec 28 '22 23:12 agent13

can this be recheck on latest nightly

Mrlinkwii avatar Jun 26 '23 21:06 Mrlinkwii

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.

SlyCooperReloadCoded avatar Jun 27 '23 01:06 SlyCooperReloadCoded

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 :/

F0bes avatar Jul 06 '23 01:07 F0bes

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.

SlyCooperReloadCoded avatar Jul 06 '23 03:07 SlyCooperReloadCoded

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: @.***>

F0bes avatar Jul 06 '23 04:07 F0bes

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...

AmyRoxwell avatar Aug 07 '23 20:08 AmyRoxwell

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

SlyCooperReloadCoded avatar Aug 07 '23 21:08 SlyCooperReloadCoded

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 avatar Aug 07 '23 21:08 AmyRoxwell

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.

AmyRoxwell avatar Jul 02 '24 17:07 AmyRoxwell

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?)

Formedras avatar Jul 03 '24 01:07 Formedras

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 avatar Jul 03 '24 03:07 SlyCooperReloadCoded

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.

SlyCooperReloadCoded avatar Jul 05 '24 03:07 SlyCooperReloadCoded