samples/02_input_basics/01_keyboard/app/main.rb
# args.inputs.keyboard.key_up.a will check to see if the a key has been pressed
# This will work with the other keys as well
args.inputs.keyboard.key_up.a will check to see if the a key has been pressed
This will work with the other keys as well
args . inputs . keyboard . key_up . a will check to see if the a key has been pressed This will work with the other keys as well
def tick args
  tick_instructions args, "Sample app shows how keyboard events are registered and accessed.", 360
  args.outputs.labels << { x: 460, y: row_to_px(args, 0), text: "Current game time: #{args.state.tick_count}", size_enum: -1 }
  args.outputs.labels << { x: 460, y: row_to_px(args, 2), text: "Keyboard input: args.inputs.keyboard.key_up.h", size_enum: -1 }
  args.outputs.labels << { x: 460, y: row_to_px(args, 3), text: "Press \"h\" on the keyboard.", size_enum: -1 }
  if args.inputs.keyboard.key_up.h
    args.state.h_pressed_at = args.state.tick_count
  end
  args.state.h_pressed_at ||= false
  if args.state.h_pressed_at
    args.outputs.labels << { x: 460, y: row_to_px(args, 4), text: "\"h\" was pressed at time: #{args.state.h_pressed_at}", size_enum: -1 }
  else
    args.outputs.labels << { x: 460, y: row_to_px(args, 4), text: "\"h\" has never been pressed.", size_enum: -1 }
  end
  tick_help_text args
end
def tick args tick_instructions args , "Sample app shows how keyboard events are registered and accessed." , 360 args . outputs . labels << { x : 460 , y : row_to_px ( args , 0 ) , text : "Current game time: #{args.state.tick_count}" , size_enum : - 1 } args . outputs . labels << { x : 460 , y : row_to_px ( args , 2 ) , text : "Keyboard input: args.inputs.keyboard.key_up.h" , size_enum : - 1 } args . outputs . labels << { x : 460 , y : row_to_px ( args , 3 ) , text : "Press \"h\" on the keyboard." , size_enum : - 1 } if args . inputs . keyboard . key_up . h args . state . h_pressed_at = args . state . tick_count end args . state . h_pressed_at ||= false if args . state . h_pressed_at args . outputs . labels << { x : 460 , y : row_to_px ( args , 4 ) , text : "\"h\" was pressed at time: #{args.state.h_pressed_at}" , size_enum : - 1 } else args . outputs . labels << { x : 460 , y : row_to_px ( args , 4 ) , text : "\"h\" has never been pressed." , size_enum : - 1 } end tick_help_text args end
args.inputs.keyboard.key_up.a will check to see if the a key has been pressed
This will work with the other keys as well
args . inputs . keyboard . key_up . a will check to see if the a key has been pressed This will work with the other keys as well
# Notice how small_font accounts for all the remaining parameters # Input on a specifc key can be found through args.inputs.keyboard.key_up followed by the key # This code simplifies to if args.state.h_pressed_at has not been initialized, set it to false
args