#input #glfw #lookup #key #update #api-agnostic #mouse-axis

bidrag

一个简单的输入绑定系统(API无关)

1个不稳定版本

使用旧Rust 2015

0.1.0 2018年7月14日

#1809 in 硬件支持

MIT 协议

9KB
127

bidrag

一个用于管理可绑定游戏输入的Rust库。目前只支持键盘/鼠标,但将来将支持游戏手柄。

示例(使用GLFW)

let mut glfw = glfw3::init(glfw3::FAIL_ON_ERRORS).expect("Failed to init GLFW3");
let (mut window, events) = {
    glfw.window_hint(glfw3::WindowHint::Visible(true));

    let windowMode = glfw3::WindowMode::Windowed;
    // return
    glfw.create_window(1600, 900, APP_NAME, windowMode).expect("Failed to create a window!")
};
let mut cursorMode = glfw3::CursorMode::Disabled; // For mouse input

window.set_cursor_pos_polling(true);
window.set_cursor_mode(cursorMode);
window.set_key_polling(true);
window.make_current();

let mut inputSub = bidrag::InputSubsystem::new((2.0, 2.0));
// Axes are referred to by indices, rather than using a string lookup every time.
let yawIndex = inputSub.add_binding("Yaw".to_string(), Binding::MAxis
    (MouseAxis::X));
let quitIndex = inputSub.add_binding("Quit".to_string(), Binding::KBKey
    (glfw3::Key::Escape as i32));

let mut running = true;
while running {
    glfw.poll_events();
    for (_, ev) in glfw3::flush_messages(&events) {
        match ev {
            glfw3::WindowEvent::Key(key, _, action, _) => {
                // For now you manually update the binds, since I wanted this API-agnostic
                inputSub.update_kb_bind(key as i32, action == glfw3::Action::Press);
            },
            _ => {}
        }
    }

    inputSub.update_mouseaxes_bind(window.get_cursor_pos());

    running = running && !window.should_close();
}

待办

  • 游戏手柄
  • (可能)支持多个键盘/鼠标。
    • 至少,这个库可以支持它,并将选择权留给客户端

没有运行时依赖