diff --git a/README.md b/README.md index f55cad72e..b27b27034 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,8 @@ A **gamepad is recommended**: console games are made for one, and their menus an game's gamepad – buttons, sticks, triggers and rumble. It can be plugged in or out while the game runs. - **Keyboard and mouse** work too, as a gamepad: WASD the left stick, the mouse the right stick, mouse buttons the triggers, the wheel the bumpers, Enter / Space A, Escape / Backspace B, arrows the D-pad, - E / Q Y / X, Shift / Ctrl the stick clicks, Tab View, P Menu. `keyboard_mouse` and `mouse_sensitivity` in + E / Q Y / X, Shift / Ctrl the stick clicks, Tab View, P Menu, Page Up / Page Down the right stick up / down + (to scroll a menu's long text). `keyboard_mouse` and `mouse_sensitivity` in the game's `xcl.toml` turn it off or change the mouse speed. A gamepad and the keyboard / mouse can be used together. diff --git a/crates/xcl/src/hle/kbm.rs b/crates/xcl/src/hle/kbm.rs index 6d18b1cfb..7afebd574 100644 --- a/crates/xcl/src/hle/kbm.rs +++ b/crates/xcl/src/hle/kbm.rs @@ -14,6 +14,7 @@ //! | E / Q | Y / X | //! | Space, Enter / Escape, Backspace | A / B | //! | arrows / Tab / P | D-pad / View / Menu | +//! | Page Up / Page Down | right stick held up / down | //! //! The mouse is read with Raw Input on the XCL window (movement in mouse counts, not the //! cursor); its speed becomes a stick deflection – the stick turns the camera at a rate, @@ -42,6 +43,12 @@ pub fn stick_from_keys(up: bool, left: bool, down: bool, right: bool) -> (f32, f } } +/// Page Up / Page Down: the right stick held fully up / down (None: neither, or both). +pub fn stick_from_page_keys(page_up: bool, page_down: bool) -> Option<(f32, f32)> { + let (x, y) = stick_from_keys(page_up, false, page_down, false); + (y != 0.0).then_some((x, y)) +} + /// mouse counts a second that give full deflection at sensitivity 1 const FULL_SPEED: f32 = 4000.0; /// slower than this (counts a second) the stick rests (sensor noise, a hand on the mouse) @@ -428,6 +435,14 @@ pub fn apply(s: &mut GamepadState) { if key(0x02) { s.left_trigger = 1.0; } + // Page Up / Page Down: the right stick held up / down – a menu's long text (a title's terms + // of service) scrolls with the right stick, which the mouse deflects only while it moves + if let Some((px, py)) = stick_from_page_keys(key(0x21), key(0x22)) { + if px * px + py * py >= s.right_x * s.right_x + s.right_y * s.right_y { + s.right_x = px; + s.right_y = py; + } + } let mut g = MOUSE.lock().unwrap_or_else(|e| e.into_inner()); let m = g.get_or_insert_with(|| Mouse { last: Instant::now(), velocity: Velocity::default(), wheel: Wheel::default(), wheel_rest: 0 }); let now = Instant::now(); @@ -461,6 +476,15 @@ mod tests { assert_eq!(stick_from_keys(true, true, true, true), (0.0, 0.0)); } + #[test] + fn page_keys_hold_the_right_stick_up_or_down() { + assert_eq!(stick_from_page_keys(false, false), None); + assert_eq!(stick_from_page_keys(true, false), Some((0.0, 1.0))); + assert_eq!(stick_from_page_keys(false, true), Some((0.0, -1.0))); + // both cancel + assert_eq!(stick_from_page_keys(true, true), None); + } + #[test] fn mouse_speed_becomes_a_deflection() { // resting