Emit a keypress event when Button Clicked (Slightly Solved)

Just as the title says. I want to trigger the e key. This is my code so far:
var ePress = this.physics.add.image(800, 550, 'eBtn').setInteractive().setDepth(1000).setScrollFactor(0);

ePress.on('pointerdown', () => { /* Emit an E keypress*/ });

How do I do this? I’ve tried the emit() function but I don’t know how to use it.
Thanks,
UltimateProGrammer

You can try:
this.input.keyboard.emit('keydown-E');

Well, that works when I test it using .on but doesn’t in my use case (which I didn’t explain, so its my fault.) I am using keyboard.addKeys method in my case.
cursors = this.input.keyboard.addKeys( { e:Phaser.Input.Keyboard.KeyCodes.E });
When using if(cursors.e.isDown) it doesn’t register as an E press. I also tried cursors.emit('keydown-E') but that threw an error.

I am not sure if you can force a key to be down, so that ‘isDown’ would be true, without the user actually pressing it.
If you have a function that you want to call on input E, can’t you just call the same function when someone presses the button?

1 Like

Unfortunately, It’s not all based on a function. Some of it is, but some of it isn’t.

The only way I can think of doing it is to have a function which triggers when the button is pressed which sets some boolean to true, and set it to false when the e key isn’t pressed. Would this work?

Pseudo-Ish-Code:

In create():
var eDown = false
ePress.on('pointerdown', () => { eDown = true;});
ePress.on('pointerup', () => { eDown = false;});

In my functions:
if (down.isDown || eDown === true) {
// Do something
}

It’s not the most elegant, but for just one or two buttons it might work.