KKKIIO/selene/inputs does not have a README file
let key_code = @inputs.Code::from_string("KeyA")
inspect(key_code, content="Some(KeyA)")
// Check if a key is currently pressed
if @inputs.is_pressed(KeyW) {
println("W key is being held down")
}
// Check if a key was just pressed this frame
if @inputs.is_just_pressed(Space) {
println("Space was just pressed")
}let key_a = @inputs.Code::from_string("KeyA")
inspect(key_a, content="Some(KeyA)")
let space_key = @inputs.Code::from_string("Space")
inspect(space_key, content="Some(Space)")
let invalid_key = @inputs.Code::from_string("InvalidKey")
inspect(invalid_key, content="None")pub(all) struct GamepadButtonInput {
gamepad : Gamepad
button : GamepadButton
} derive(Eq, Hash, Debug)fn GamepadButtonInput::GamepadButtonInput(gamepad : Gamepad, button : GamepadButton) -> GamepadButtonInputpub(all) struct InputSnapshot {
pressed_keys : Set[Code]
mouse : Mouse
mouse_relative_delta : Vec2?
mouse_wheel : MouseWheel
touches : Map[TouchId, TouchPoint]
touch_changes : Array[TouchEvent]
connected_gamepads : Set[Gamepad]
pressed_gamepad_buttons : Set[GamepadButtonInput]
gamepad_axis_values : Map[GamepadAxisInput, Double]
}// Access the global mouse state
inspect(@inputs.mouse.pos, content="Vec2(0, 0)")
inspect(@inputs.mouse.left_button, content="false")// Access the global mouse movement
inspect(@inputs.mouse_movement.movement, content="Vec2(0, 0)")
// Update movement vector
@inputs.mouse_movement.movement = @math.Vec2(10.0, -5.0)pub(all) struct PointerEvent {
id : PointerId
source : PointerSource
phase : PointerPhase
position : Vec2
previous_position : Vec2
delta : Vec2
primary : Bool
}pub(all) struct TouchEvent {
id : TouchId
source : PointerSource
phase : TouchPhase
position : Vec2
previous_position : Vec2
delta : Vec2
primary : Bool
}pub(all) struct TouchGestureEvent {
kind : TouchGestureKind
primary_id : TouchId?
secondary_id : TouchId?
position : Vec2
delta : Vec2
scale : Double
distance : Double
duration : Double
}pub(all) struct TouchPoint {
id : TouchId
source : PointerSource
position : Vec2
previous_position : Vec2
delta : Vec2
primary : Bool
}fn advanced_key_system(_delta : Double) -> Unit// This function is typically called once per frame by the game engine
@inputs.advanced_key_system(0.016) // 60 FPS = ~16ms per frame
// After calling advanced_key_system, you can check for just-pressed keys
if @inputs.is_just_pressed(@inputs.KeyW) {
println("W was just pressed this frame")
}
if @inputs.is_just_released(@inputs.Space) {
println("Space was just released this frame")
}fn advanced_mouse_system(_delta : Double) -> Unitinspect(@inputs.is_mouse_just_pressed(Left), content="false")
inspect(@inputs.is_mouse_pressed(Right), content="false")// Check if the space key was just pressed this frame
if @inputs.is_just_pressed(Space) {
println("Space key was just pressed!")
}
// Check for WASD movement keys
if @inputs.is_just_pressed(KeyW) {
println("Started moving forward")
}
if @inputs.is_just_pressed(KeyA) {
println("Started moving left")
}// Check if the space key was just released this frame
if @inputs.is_just_released(Space) {
println("Space key was just released!")
}
// Check for WASD movement keys
if @inputs.is_just_released(KeyW) {
println("Stopped moving forward")
}
if @inputs.is_just_released(KeyA) {
println("Stopped moving left")
}inspect(@inputs.is_mouse_just_pressed(MouseButton::Left), content="false")inspect(@inputs.is_mouse_just_released(MouseButton::Left), content="false")inspect(@inputs.is_mouse_pressed(MouseButton::Left), content="false")inspect(@inputs.is_mouse_released(Left), content="true")// Check if the W key is currently pressed
if @inputs.is_pressed(@inputs.KeyW) {
println("W key is being held down")
}
// Check multiple keys
if @inputs.is_pressed(@inputs.Space) {
println("Space is pressed")
}
if @inputs.is_pressed(@inputs.ArrowUp) {
println("Up arrow is pressed")
}// Check if the W key is currently released
inspect(@inputs.is_released(KeyW), content="true")// Check if left mouse button was just pressed
if @inputs.just_pressed_mouse.left_button {
println("Left mouse button was just clicked!")
}
// Access the state directly
inspect(@inputs.just_pressed_mouse.left_button, content="false")
inspect(@inputs.just_pressed_mouse.right_button, content="false")// Check if left mouse button was just released
if @inputs.just_release_mouse.left_button {
println("Left mouse button was just released!")
}
// Access the state directly
inspect(@inputs.just_release_mouse.left_button, content="false")
inspect(@inputs.just_release_mouse.right_button, content="false")// Get movement vector for WASD keys
let movement = @inputs.key_vector(KeyW, KeyS, KeyA, KeyD)
inspect(movement, content="Vec2(0, 0)")
// Get movement vector for arrow keys
let arrow_movement = @inputs.key_vector(ArrowUp, ArrowDown, ArrowLeft, ArrowRight)
inspect(arrow_movement, content="Vec2(0, 0)")// Access the global mouse state
inspect(@inputs.mouse.pos, content="Vec2(0, 0)")
inspect(@inputs.mouse.left_button, content="false")// Access the global mouse movement
inspect(@inputs.mouse_movement.movement, content="Vec2(10, -5)")
// Update movement vector
@inputs.mouse_movement.movement = @math.Vec2(10.0, -5.0)// Check if a specific key is currently pressed
if @inputs.pressed_keys.contains(@inputs.KeyW) {
println("W key is being held down")
}
// Get all currently pressed keys
let current_keys = @inputs.pressed_keys.to_array()
inspect(current_keys, content="[]")ECS game engine in MoonBit
Dependencies