Faking app.keyboard.isPressed for selenium+capybara tests

Hello! Testing my game with Capybara, i got a pretty cool system where i download the build into rspec, run it in a selenium browser and test it with Capybara. Stuck on something: I have in my game for my players update() loop:

self.moveHorizontal = (function(event) {
      if(self.app.keyboard.isPressed(pc.KEY_LEFT)) {            return 1;        }
      if(self.app.keyboard.isPressed(pc.KEY_RIGHT)) {            return -1;        }    
      return 0;    
self.moveVertical = (function() {       
      if(self.app.keyboard.isPressed(pc.KEY_DOWN)) {            return -1;        }           
      if(self.app.keyboard.isPressed(pc.KEY_UP)) {            return 1;        }       
      return 0;    

But i cannot figure out how to trigger it with javascript (via capybara) I have tried

document.dispatchEvent(new KeyboardEvent('keydown', {'key': '40'}))

As well as

document.dispatchEvent(new KeyboardEvent('keydown', {'key': 'ArrowDown'}))

(have also tried event ‘keypress’ instead of ‘keydown’) Nothing seems to be working to simulate a keyboard press! Any guidence here? I guess understanding how the


function works would help?

You can see how it’s implemented here: engine/keyboard.js at main · playcanvas/engine · GitHub

I think it listens for the down/up events on the window. Best to add breakpoints in the engine file to check.