0

I have a piece of code in javascript that sends a request to the server with a list of my keypresses. The way I get the keycodes is like this:

   window.onkeypress = function (event) {
     keypresses.push(event.which);
   }

On my golang code, I'm trying to use these as to type some text in the chromedp instance using:

chromedp.Run(ctx, chromedp.KeyEvent(key))

The problem is that this types literally the key code, I've been trying to find out a way to do this but I have no idea.

Does anyone know how to do this?

Thanks in advance.

Edit

I have added the code to github, here's the repo: https://github.com/ericmackrodt/netscape-proxy

The client collects the keycodes and sends them as a query param here:

https://github.com/ericmackrodt/netscape-proxy/blob/main/templates/browser.html#L48

The server receives the keycodes from the client here:

https://github.com/ericmackrodt/netscape-proxy/blob/main/server.go#L80

And then parses it and tries to type them here:

https://github.com/ericmackrodt/netscape-proxy/blob/main/browser/browser.go#L70

The code should be fairly easy to reproduce.

Eric.M
  • 827
  • 1
  • 14
  • 29
  • It would help if you showed a somewhat more complete example of your Go code. For example, what is `key`? What is its type and where is it coming from. Please follow the advice in https://stackoverflow.com/help/minimal-reproducible-example – Eli Bendersky Mar 24 '21 at 15:30
  • What does "literally the key code" mean? – Christian Mar 24 '21 at 15:36
  • Hi @EliBendersky, I have added more details in the post. – Eric.M Mar 24 '21 at 22:47
  • Hey @Christian, it's the key code that comes from `event.which` in the client. It's literally an integer. – Eric.M Mar 24 '21 at 22:47

0 Answers0