1

I have some code written in python that uses PyAutoGui:

import pyautogui

def mult_choice(OPTION):
    if OPTION == 1:
        pyautogui.press('1')
    elif OPTION == 2:
        pyautogui.press('2')
    elif OPTION == 3:
        pyautogui.press('3')
    elif OPTION == 4:
        pyautogui.press('4')
    sleep(2)

I also plan to write some code in Javascript that will get the variable OPTION. As far as I know, you can't control the keyboard in Javascript, so I wrote that part in Python. However, I wasn't sure if it is possible to run a python function in a Javascript program. If this is possible, someone explaining it to me would be appreciated.

ADyson
  • 57,178
  • 14
  • 51
  • 63
Kai036
  • 190
  • 1
  • 2
  • 10
  • Is this for node.js or client-side? – Lawrence May 08 '19 at 22:06
  • This is for node.js. – Kai036 May 08 '19 at 22:08
  • you can run python in node.js enviroment, there are npm packages that will do that for you, but i dont think you can run python in browser enviroment without something like we asembly, but i am not really familiar with it – Mladen Skrbic May 08 '19 at 22:09
  • The only way I know of to run python in node would be to spawn a child process, however it seems like you should be able to do what you want to do entirely in one language. [This post](https://stackoverflow.com/questions/34974712/node-js-capture-keyboard-press-and-mouse-movement-not-on-web-browser) shows two different methods of capturing keyboard input in node.js – Lawrence May 08 '19 at 22:11
  • 1
    This question might help you with emitting keyboard events in JS: ["Node.js JavaScript: Simulate Keypress on Server (Like a Macro)"](https://stackoverflow.com/questions/21848747/node-js-javascript-simulate-keypress-on-server-like-a-macro) – kos May 08 '19 at 22:13

0 Answers0