You can create and dispatch an InputEvent for cases like this. Here's the script for a function I use to simulate a click event at a given position, for example:
func fake_click(position, flags=0):
var ev = InputEvent()
ev.type = InputEvent.MOUSE_BUTTON
ev.button_index=BUTTON_LEFT
ev.pressed = true
ev.global_pos = position
ev.meta = flags
get_tree().input_event(ev)
For a keypress, you might have something like this:
func simulate_key(which_key):
var ev = InputEvent()
ev.type = InputEvent.KEY
ev.scancode = which_key
get_tree().input_event(ev)
Note that this example would expect a scancode like KEY_F, not a simple string like F; those are all pretty much what you'd expect, but you can check the class reference for @GlobalScope if you need to look one up.
You should also take a look at the documentation and the demo for using the InputMap - which might be more what you're looking for, depending on your use case. It provides a way to bind multiple types of input to one 'action' code, which can in turn be hooked up to whatever functions you want it to call.