How do i Input action_just_pressed with code without manually having to push the button

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By javrocks

For Example

var can_move = (true)

If can_move == (true):

#This dosent seem to input anything so do u always have to input actions manually

:bust_in_silhouette: Reply From: bloodsign

Input.is_action_just_pressed() returns a boolean value (true/false), it “checks” for input and not used to “trigger” one.

Assuming you have a movement code when you press up:

 if Input.is_action_just_pressed("ui_up"):

You could simply do:

  if can_move:

Of course, if it is really important to simulate a keypress, then:

func simulate_up_key():
       var simulated_input = InputEvent()
       simulated_input.type = InputEvent.KEY
       simulated_input.scancode = 16777232#this number is scancode for UP