Merge pull request #477 from ludovic111/fix/ctl-wait-keeps-held-keys

Keep held keys held through wait on the control socket
This commit is contained in:
Ludovic Marie
2026-10-16 11:02:24 +02:00
committed by GitHub
3 changed files with 27 additions and 5 deletions
@@ -256,7 +256,8 @@ pub const COMMANDS: &[Cmd] = &[
&[opt("all", Ty::Bool, "drop the whole stack")], mcp: true, local: false),
cmd!("hold", Act, "hold KEY SECONDS", "press a key, wait, release it", "Keys as for key.", ["horizon-ctl hold w 2"],
&[p("key", Ty::Str, "key name"), p("seconds", Ty::Num, "how long")], mcp: false, local: true),
cmd!("key", Act, "key KEY down|up|tap|repeat", "press, release or auto-repeat a key (w a s d space shift ctrl e q esc f3 1-9 arrows ...)", "",
cmd!("key", Act, "key KEY down|up|tap|repeat", "press, release or auto-repeat a key (w a s d space shift ctrl e q esc f3 1-9 arrows ...)",
"down holds the key until key ... up, release or stop; wait does not release it. move, goto, jump, break and the other actions release the movement keys when they end.",
["horizon-ctl key space tap"], &[p("key", Ty::Str, "key name"), p("action", Ty::Enum(&["down", "up", "tap", "repeat"]), "what to do")], mcp: true, local: false),
cmd!("mouse", Act, "mouse left|right|middle down|up|click", "press or release a mouse button in the world", "",
["horizon-ctl mouse right click"], &[p("button", Ty::Enum(&["left", "right", "middle"]), "button"), p("action", Ty::Enum(&["down", "up", "click"]), "what to do")], mcp: false, local: false),
@@ -323,7 +324,9 @@ pub const COMMANDS: &[Cmd] = &[
cmd!("summon", World, "summon KIND [X Y Z] [baby]", "spawn a mob", "", ["horizon-ctl summon cow"], &[p("kind", Ty::Str, "mob type")], mcp: true, local: false),
cmd!("effect", World, "effect ID SECONDS [AMPLIFIER] | effect clear", "give a status effect", "", ["horizon-ctl effect speed 30 1"], &[], mcp: false, local: false),
cmd!("render-distance", World, "render-distance N", "chunks, 2..64", "", ["horizon-ctl render-distance 8"], &[p("chunks", Ty::Int, "render distance")], mcp: false, local: false),
cmd!("wait", World, "wait TICKS", "wait until TICKS game ticks have passed (20 per second)", "", ["horizon-ctl wait 40"],
cmd!("wait", World, "wait TICKS", "wait until TICKS game ticks have passed (20 per second)",
"Keys and mouse buttons held with key ... down or mouse ... down stay held while it waits. Release them with key ... up, release or stop.",
["horizon-ctl wait 40", "horizon-ctl key w down && horizon-ctl wait 40 && horizon-ctl key w up"],
&[p("ticks", Ty::Int, "game ticks")], mcp: true, local: false),
// Scripting
cmd!("script", Scripting, "script [FILE] [--keep-going]", "run commands from FILE (or stdin), one per line",
+21 -2
View File
@@ -51,7 +51,7 @@ pub(super) const HELP: &[&str] = &[
"scroll-at X Y STEPS turn the wheel at GUI pixel X Y (positive scrolls up)",
"command TEXT run a /command",
"pause open the pause menu",
"wait TICKS wait for game ticks to pass",
"wait TICKS wait for game ticks to pass (held keys stay held)",
"stop cancel the running action and release every key",
];
@@ -231,6 +231,13 @@ enum TaskKind {
report_tick: u64,
},
}
impl TaskKind {
/// Whether the keys and buttons are released when the task ends. A wait
/// holds nothing, so what `key w down` pressed stays down through it.
fn releases_input(&self) -> bool {
!matches!(self, TaskKind::Wait { .. })
}
}
struct Goto {
target: [f64; 3],
near: f64,
@@ -1655,7 +1662,9 @@ impl Game<'_> {
let result = self.step_task(&mut task.kind, timed_out);
match result {
Some(value) => {
self.release_agent_keys();
if task.kind.releases_input() {
self.release_agent_keys();
}
let _ = task.reply.send(value.to_string());
}
None => self.agent.task = Some(task),
@@ -1959,6 +1968,16 @@ impl Game<'_> {
mod tests {
use super::*;
#[test]
fn only_wait_keeps_held_input() {
assert!(!TaskKind::Wait { until_tick: 40 }.releases_input());
let jump = TaskKind::Jump {
release_tick: 4,
from_y: 64.0,
};
assert!(jump.releases_input());
}
#[test]
fn parses_flags_and_values() {
let a = parse_args(&["1", "2", "--near", "3", "--sprint", "--timeout=9", "-4"]);
+1 -1
View File
@@ -53,7 +53,7 @@ Legend: **yes** complete, **part** partial (see note), **no** missing, **—** n
| Crafting (grid, result, recipe book) | part | part | grid by `click-slot`; the recipe book only by `click-at` |
| Movement, look, path-finding | yes | yes | `move`, `goto`, `look`, `look-at`, `turn --over`, `mouse-move` |
| Act on the world | yes | yes | `break`, `place`, `interact`, `use-item`, `attack`, `select`, `drop` |
| Raw input: keys, mouse buttons | yes | yes | `key`, `mouse`, `release` |
| Raw input: keys, mouse buttons | yes | yes | `key`, `mouse`, `release`; `key w down` stays held through `wait` until `key w up`, `release` or `stop` |
| Controllers | yes | yes | `pad` button/stick/trigger/status (a virtual pad) |
| Chat and commands | yes | yes | `chat`, `command`, `type`, `messages`, `chat-log` |
| Screens: which is open | yes | yes | `screen` gives a label (`title`, `options`, `inventory`...) but not the options page or sub-screen |