Holding the drop key keeps dropping, in game and in menus
KeyboardHandler.keyPress sends a key repeat (InputConstants.REPEAT) to Screen.keyPressed and KeyMapping.click like a press, so holding key.drop keeps throwing the held item, the hovered slot's item in a menu, and the hovered item of a creative tab. Horizon dropped every repeat; the drop key's now reach key_pressed. horizon-ctl `key KEY repeat` sends one auto-repeat, for scripted checks. Fixes #443 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -256,8 +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", "press or release a key (w a s d space shift ctrl e q esc f3 1-9 arrows ...)", "",
|
||||
["horizon-ctl key space tap"], &[p("key", Ty::Str, "key name"), p("action", Ty::Enum(&["down", "up", "tap"]), "what to do")], mcp: true, local: false),
|
||||
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 ...)", "",
|
||||
["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),
|
||||
cmd!("pad", Act, "pad BUTTON down|up|tap | pad stick left|right X Y | pad trigger left|right V | pad release | pad status", "a virtual controller: buttons, sticks and triggers as a real pad would send them",
|
||||
|
||||
@@ -3399,7 +3399,10 @@ impl Game<'_> {
|
||||
} else {
|
||||
self.keys.insert(key);
|
||||
}
|
||||
if repeat {
|
||||
// KeyboardHandler.keyPress: a repeat (InputConstants.REPEAT) reaches
|
||||
// Screen.keyPressed and KeyMapping.click like a press, so holding
|
||||
// key.drop keeps throwing, in game and over a menu slot.
|
||||
if repeat && key != KeyCode::KeyQ {
|
||||
return Ok(());
|
||||
}
|
||||
self.key_pressed(key)
|
||||
|
||||
@@ -11,7 +11,7 @@ use winit::{event::MouseButton, event_loop::ActiveEventLoop, keyboard::KeyCode};
|
||||
|
||||
const HELP: &[&str] = &[
|
||||
"status game, player, streaming and renderer state",
|
||||
"key KEY down|up|tap press or release a key (w a s d space shift ctrl e q esc f3 1-9 arrows ...)",
|
||||
"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 ...)",
|
||||
"release release every key and mouse button",
|
||||
"mouse left|right|middle down|up|click",
|
||||
"look YAW PITCH set the view direction in degrees",
|
||||
@@ -201,7 +201,7 @@ impl Game<'_> {
|
||||
}
|
||||
// The zoom extra sees the key as the keyboard hook does.
|
||||
let action = arg(2)?;
|
||||
self.extras_key(physical, action != "up", false);
|
||||
self.extras_key(physical, action != "up", action == "repeat");
|
||||
if action == "tap" {
|
||||
self.extras_key(physical, false, false);
|
||||
}
|
||||
@@ -233,6 +233,11 @@ impl Game<'_> {
|
||||
self.keys.remove(&key);
|
||||
self.physical_keys.remove(&key);
|
||||
}
|
||||
// The system's auto-repeat while the key is held.
|
||||
"repeat" => {
|
||||
self.physical_keys.insert(physical);
|
||||
self.mapped_key(key, true, true)?;
|
||||
}
|
||||
"tap" => {
|
||||
self.control_key_down(key)?;
|
||||
self.keys.remove(&key);
|
||||
@@ -240,9 +245,10 @@ impl Game<'_> {
|
||||
self.debug_key(physical, horizon_client::debug_keys::KeyAction::Release);
|
||||
}
|
||||
other => {
|
||||
return Err(
|
||||
format!("key action must be down, up or tap, not {other}").into()
|
||||
);
|
||||
return Err(format!(
|
||||
"key action must be down, up, tap or repeat, not {other}"
|
||||
)
|
||||
.into());
|
||||
}
|
||||
}
|
||||
ok()
|
||||
|
||||
Reference in New Issue
Block a user