Skip to content
Closed
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
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
24 changes: 24 additions & 0 deletions crates/xcl/src/hle/kbm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
Loading