8000 zdxsv: USB keyboard sends the physical key (Japanese keyboard layout) by inada-s-ai[bot] · Pull Request #552 · inada-s/pcsx2 · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
3 changes: 2 additions & 1 deletion ZDXSV.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ UPnP 対応ルーターなら、同じページの「UPnP Now」ボタンで転
処理時間の内訳 (エミュレーション、ロールバック、セーブ/ロード、通信待ち、スリープ) をグラフで、
GS スレッド・VU スレッド・GPU の 1 フレームあたりの時間を数値で表示します。

PC のキーボードはゲームの USB キーボードとしても使え、チャットを入力できます。
PC のキーボードはゲームの USB キーボードとしても使え、チャットを入力できます
(Windows では日本語キーボードの配列のまま入力できます)。
PCSX2 のホットキー (F1〜F9、Space、Tab、Escape など) は割り当てていません。
必要なものは 設定 → コントローラー → ホットキー で設定してください。

Expand Down
3 changes: 2 additions & 1 deletion ZDXSV.md
8000
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ Settings → zdxsv → "Frame time overlay" shows, during online battles and
replays, where each frame's time goes (emulation, rollback, save/load, network
wait, sleep) as a graph, and the GS thread, VU thread and GPU time per frame.

The PC keyboard is also the game's USB keyboard, for chat. PCSX2's own hotkeys
The PC keyboard is also the game's USB keyboard, for chat (a Japanese keyboard types as one
on Windows). PCSX2's own hotkeys
(F1-F9, Space, Tab, Escape, ...) are not bound; set any you want under
Settings → Controllers → Hotkeys.

Expand Down
3 changes: 2 additions & 1 deletion docs/zdxsv/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ skips does not run on that path.
| Qt host start and exit (`CrashReportHooks.h`), log output (`Log::SetTapOutputLevel` in `common/Console`) | `pcsx2-qt/Zdxsv/CrashReports` | crash reports, the last log lines they carry |
| Qt host start (`AuthHooks.h`) | `Zdxsv/AuthSignIn` | sign-in test trigger (`ZDXSV_AUTH_SIGNIN_TEST`) |
| Default settings and settings load (`DefaultsHooks.h`: `VMManager::SetDefaultSettings`, Big Picture controller reset, Qt host start) | `InputDefaults` | no upstream hotkeys, USB keyboard on port 1 |
| Host key events (`KeyboardHooks.h`: `DisplaySurface` key event dispatch in `pcsx2-qt/DisplayWidget`, `HIDKbdDevice::SetBindingValue` in `USB/usb-hid`) | `HostKeyboard` | the USB keyboard sends the physical key (scan code, Windows) |

### Network paths

Expand Down Expand Up @@ -174,7 +175,7 @@ Keys (`net=1`, `lobby=1`, `port=`, `delay=`, ...) are parts of `ZDXSV_GGPO`.
## Game window

- **Mouse wheel volume**: the wheel over the game screen changes the volume in 5% steps, OSD with the new volume; not while a menu takes the mouse or the wheel is bound to an input; `ZdxsvWheelVolume`.
- **Keyboard and hotkeys**: the host keyboard is a USB keyboard on USB port 1 (in-game chat; Settings > Controllers > USB Port 1, None turns it off); no upstream PCSX2 hotkeys are bound by default, the zdxsv replay ones stay (bind any under Settings > Hotkeys). Settings files from before get both once on start (`[Zdxsv] InputDefaultsVersion`).
- **Keyboard and hotkeys**: the host keyboard is a USB keyboard on USB port 1 (in-game chat; Settings > Controllers > USB Port 1, None turns it off); on Windows it sends the physical key, so a Japanese keyboard types its own symbols (@ : ^ and the shifted ones) as a Japanese keyboard; no upstream PCSX2 hotkeys are bound by default, the zdxsv replay ones stay (bind any under Settings > Hotkeys). Settings files from before get both once on start (`[Zdxsv] InputDefaultsVersion`).

## ARM64 builds ([arm64.md](arm64.md))

Expand Down
5 changes: 4 additions & 1 deletion pcsx2-qt/DisplayWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "QtHost.h"
#include "QtUtils.h"
#include "Zdxsv/QtHooks.h"
#include "pcsx2/Zdxsv/KeyboardHooks.h"

#include "pcsx2/ImGui/FullscreenUI.h"
#include "pcsx2/ImGui/ImGuiManager.h"
Expand Down Expand Up @@ -270,8 +271,10 @@ void DisplaySurface::handleKeyInputEvent(QEvent* event)
m_keys_pressed_with_modifiers.push_back(key);
}

Host::RunOnCPUThread([key, pressed]() {
Host::RunOnCPUThread([key, pressed, scancode = key_event->nativeScanCode()]() {
Zdxsv::HostKeySetScancode(scancode);
InputManager::InvokeEvents(InputManager::MakeHostKeyboardKey(key), static_cast<float>(pressed));
Zdxsv::HostKeySetScancode(0);
});

return;
Expand Down
2 changes: 2 additions & 0 deletions pcsx2/CMakeLists.txt
8000
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ set(pcsx2Sources
Zdxsv/SyncSettings.cpp
Zdxsv/GamePatches.cpp
Zdxsv/InputDefaults.cpp
Zdxsv/HostKeyboard.cpp
Zdxsv/OnlineLimits.cpp
Zdxsv/IntHooks.cpp
Zdxsv/RecHooks.cpp
Expand Down Expand Up @@ -271,6 +272,7 @@ set(pcsx2Headers
Zdxsv/CpuHooks.h
Zdxsv/InputHooks.h
Zdxsv/DefaultsHooks.h
Zdxsv/KeyboardHooks.h
Zdxsv/SaveStateHooks.h
Zdxsv/PatchHooks.h
Zdxsv/PineHooks.h
Expand Down
11 changes: 10 additions & 1 deletion pcsx2/USB/usb-hid/usb-hid.cpp
8BD0
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "USB/qemu-usb/USBinternal.h"
#include "USB/qemu-usb/desc.h"
#include "USB/usb-hid/usb-hid.h"
#include "Zdxsv/KeyboardHooks.h"

#include "IconsPromptFont.h"
#include "common/Console.h"
Expand Down Expand Up @@ -807,11 +808,19 @@ namespace usb_hid
{
UsbHIDState* s = USB_CONTAINER_OF(dev, UsbHIDState, dev);

KeyValue kv;
if (const int number = Zdxsv::HostKeyNumber(); number != 0)
{
kv.type = KEY_VALUE_KIND_NUMBER;
kv.u.number = number;
s->QueueKeyboardState(kv, (value >= 0.5f));
return;
}

const auto it = s->keycode_mapping.find(bind);
if (it == s->keycode_mapping.end())
return;

KeyValue kv;
kv.type = KEY_VALUE_KIND_QCODE;
kv.u.qcode = it->second;
s->QueueKeyboardState(kv, (value >= 0.5f));
Expand Down
47 changes: 47 additions & 0 deletions pcsx2/Zdxsv/HostKeyboard.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-FileCopyrightText: 2026 zdxsv contributors
// SPDX-License-Identifier: GPL-3.0+

// The USB keyboard sends the physical key, not the character the host layout gives it: the game reads
// a Japanese layout, so a key named by its character (@ : ^ on a Japanese keyboard) would be lost or moved.

#include "Zdxsv/KeyboardHooks.h"

namespace Zdxsv
{
namespace
{
struct HostKeyState
{
u32 native_scancode = 0;
};

HostKeyState s_host_key;

// Windows: bits 0-7 scan code, 0x100 the extended (E0) flag. Pause has no single code; NumLock carries the flag.
constexpr u32 WIN_EXTENDED = 0x100;
constexpr u32 WIN_PAUSE = 0x45;
constexpr u32 WIN_NUMLOCK = 0x145;
} // namespace

void HostKeySetScancode(u32 native_scancode)
{
s_host_key.native_scancode = native_scancode;
}

int HostKeyNumber()
{
#ifdef _WIN32
const u32 sc = s_host_key.native_scancode;
if (sc == 0 || sc == WIN_PAUSE || sc > 0x1ff)
return 0;
if (sc == WIN_NUMLOCK)
return 0x45;
const u32 code = sc & 0x7f;
if (code == 0 || (sc & 0x80))
return 0;
return static_cast<int>((sc & WIN_EXTENDED) ? (code | 0x80) : code);
#else
return 0;
#endif
}
} // namespace Zdxsv
17 changes: 17 additions & 0 deletions pcsx2/Zdxsv/KeyboardHooks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2026 zdxsv contributors
// SPDX-License-Identifier: GPL-3.0+

#pragma once

// zdxsv hooks of the host keyboard path (Qt display widget, USB HID keyboard). Only declarations (AGENTS.md, Seams With Upstream Code).

#include "common/Pcsx2Defs.h"

namespace Zdxsv
{
// CPU thread, around InputManager::InvokeEvents of a host key: the event's native scan code, 0 after it.
void HostKeySetScancode(u32 native_scancode);

// In HIDKbdDevice::SetBindingValue: the PS/2 set 1 number of the physical key being dispatched, 0 when unknown.
int HostKeyNumber();
} // namespace Zdxsv
1 change: 1 addition & 0 deletions pcsx2/Zdxsv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ options: `docs/zdxsv/`.
| `replay.proto` | Replay file schema (`BattleLogFile` + PCSX2 fields); documentation, not compiled |
| `GamePatches.cpp` | The Z game's patches (widescreen), built in in place of pnach files; a missing patches.zip is no warning (seam: `PatchHooks.h`) |
| `InputDefaults.cpp` | Default input settings: no upstream hotkeys, USB keyboard on port 1; one-time migration of older settings files (seam: `DefaultsHooks.h`) |
| `HostKeyboard.cpp` | The physical key (Windows scan code) of the host key event being dispatched, for the USB keyboard (seam: `KeyboardHooks.h`) |
| `OnlineLimits.cpp`, `OnlineLimits.h` | PCSX2 features limited while online (lobby or net battle): the switch, forced settings, PINE refusal, macro buttons, refused operations, breakpoints cleared (seams: `PineHooks.h`, `InputHooks.h`, `UiHooks.h`) |
| `SyncSettings.cpp`, `SyncSettings.h` | Sync-relevant settings forced while the Z game runs (speedhacks during battles only), their fingerprint for the lobby (UI: `ZdxsvSettingsWidget::markSyncForced`) |
| `LobbyConnection.cpp` | A TCP connection to the lobby (no-DEV9 host socket): platform info message, GGPO lobby setup, lobby filter |
Expand Down
2 changes: 2 additions & 0 deletions pcsx2/pcsx2.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@
<ClCompile Include="Zdxsv\SyncSettings.cpp" />
<ClCompile Include="Zdxsv\GamePatches.cpp" />
<ClCompile Include="Zdxsv\InputDefaults.cpp" />
<ClCompile Include="Zdxsv\HostKeyboard.cpp" />
<ClCompile Include="Zdxsv\OnlineLimits.cpp" />
<ClCompile Include="Zdxsv\IntHooks.cpp" />
<ClCompile Include="Zdxsv\RecHooks.cpp" />
Expand Down Expand Up @@ -960,6 +961,7 @@
<ClInclude Include="Zdxsv\CpuHooks.h" />
<ClInclude Include="Zdxsv\InputHooks.h" />
<ClInclude Include="Zdxsv\DefaultsHooks.h" />
<ClInclude Include="Zdxsv\KeyboardHooks.h" />
<ClInclude Include="Zdxsv\SaveStateHooks.h" />
<ClInclude Include="Zdxsv\MediaHooks.h" />
<ClInclude Include="Zdxsv\AuthHooks.h" />
Expand Down
1 change: 1 addition & 0 deletions tests/zdxsv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Scripts are in `tests/zdxsv/` except `run.py` (repository root) and
| Online without DEV9 | `m4z.py` `EMU=1 CLIENTS="1 3" GGPO=7101 GGPO_CLIENTS="1 3"` (DEV9 adapter off): `join tcp x0`, `platform info sent x2`, `BattleResult x2`, `p1/p3 ggpo session`, `ggpo battle ends x1: every recording past every peer's end msg`; without `GGPO`: `no DEV9: connect to <ip>:8210 refused`, `FAIL no battle`. Login: `nodev9.py` (fast login): the lobby ID selection shows, emulog `no DEV9` and `fast login: session` with the lobby on the server, no DNAS POST, no connect refused, TCP to the server only on the lobby and login API ports; fast login off (`ZDXSV_FAST_LOGIN=0`): `no DEV9: connect to <ip>:443 refused`, no DNAS POST | `nodev9.py` with `NODEV9=0 MAXS=90`: no ID selection, the network device pick shows the device as unavailable |
| A build from source connects to a local zdxsv | no test: by hand, `run.py rom` with no server settings against zdxsv `ZDXSV_AUTH_DEV=1 scripts/run-local.sh` reaches the dev sign-in page, signs in and logs in (emulog `names resolve to 127.0.0.1`, `fast login: by token`) | none |
| Default input settings: no upstream hotkeys, USB keyboard on port 1, one-time migration | no test: by hand, start the build with `-datapath <dir>` holding an older `PCSX2.ini` (upstream default hotkeys, `[USB1] Type = None`); after start the upstream hotkeys are gone, the `Zdxsv*` ones stay, `[USB1] Type = hidkbd`, `[Zdxsv] InputDefaultsVersion = 1`; a file already at version 1 is left alone. In-game chat, by hand: `SHOW=1 ROUTE=top,C,login,w300000 ROUTE_END=1 MAXS=520 boottime.py` (or `ZDXSV_FAST_BOOT=default ROUTE=w300000`, ○ presses to 戦場選択), enter a lobby, `pcsx2ctl.ps1 -AnyKey -Seq "A,H,J,K,Return,w1500,Return"`: the chat box shows `あhjk`, lobby.log has 0x6701 and the 0x6702 echo `82 a0 82 88 82 8a 82 8b` | `[USB1] Type = None`: no chat box, no 0x6701 (map cursor: only the pad d-pad moves it, hold arrows about 1 s per step) |
| USB keyboard sends the physical key (Windows) | no test: by hand, Windows with a Japanese keyboard layout, USB port 1 = `hidkbd`, in a lobby room type `@`, `:`, `^`, `A` then Enter twice: the chat line is `@:^あ` | the same build with `HostKeyNumber` returning 0: the line is `あ` (the three symbols dropped) |
| Fast login | `ROUTE=top LIMIT=200 boottime.py` (server with `/lbs/login`): user_id screen with no ログイン press, emulog `Zdxsv: fast login: session`, no DNAS POST in `dnas.log` | `ZDXSV_FAST_LOGIN=0 ROUTE=top LIMIT=200 MAXS=150 boottime.py` fails (stops at TOP) |
| Fast login at the game's reconnect | `m4z.py` `EMU=1 CLIENTS="1 3" GGPO=7101 GGPO_CLIENTS=1` (DEV9 adapter off; client 3 without GGPO cannot reach the battle server, the game gives up and opens its reconnect): `p3 battle unreachable without DEV9, back online after the game's reconnect` (a second `ZdxsvOnline: online` within 180 s), emulog `fast login: by token, from the game's login browser` | a build without it: one `ZdxsvOnline: online`, FAIL |
| Fast boot | `fastboot.py`: run 1 (no boot state) logs `Zdxsv: fast boot: saving` and reaches the user_id screen with no input, run 2 logs `Zdxsv: fast boot: loading` and reaches it within 5 s of the VM start (`LIMIT`); each prints its time from the launch and from the VM start; run 3 (`OTHER_CARD`, default the second of `CARDS`) logs `Zdxsv: fast boot: saving` (no load of run 1's state) and leaves one boot state; run 4 (unformatted card) logs `Zdxsv: fast boot: stopped, memory card error` within 15 s; passes with the local zdxsv stack and with `LOBBY=fake` (`boot_lobby.py`: lobby API login and the lobby up to the user_id list only) | `ZDXSV_FAST_BOOT=0 MAXS=60 boottime.py` fails (no user_id screen), also with `LOBBY=fake`; run 3 on a build that keys the boot state on the adapter path only fails (`loading`) |
Expand Down
0