0

I have a executable file (.exe) that performs 3 different actions. Once in its main screen, the user can type '1', '2' or '3', to select which action the .exe must perform.

Now, as many of these actions are performed repeatedly, I am trying to automate this process. That is, I am trying to create a script that, based on a specific rule, determines which action is needed and, then, execute the .exe file, and type and send either '1', '2' or '3' (plus ENTER) in the executable screen.

I have tried this using:

  1. BAT: Calling the .exe file with START, but I dont think it is possible to interact with the program after it is launched. It would be possible to send the options as a parameter, but the .exe file doesnt accept any.

  2. AutoHotKey: I have never used it before, and I couldnt find in the documentation a way to type and send commands to the program.

  3. Python: I tried using popen, and I could execute the .exe file, but then again, could not send the '1', '2' or '3' options. The code used for that is:

.

import time
from subprocess import Popen, PIPE

process = Popen(["executable.exe", "1"], stderr=PIPE, shell=True)
stdout, stderr = process.communicate()

time.sleep(2)

process.communicate("1") # send '1' to select action

This launches the .exe file, but doesn type and send '1' in the program screen to select the action.

JohnCalms
  • 87
  • 7
  • 1
    What is your code + error. – BrainFl Mar 23 '22 at 14:26
  • 1
    Communicating with an .exe is a very vague requirement. You exe process should support a channel for communication like a port, or a data stream or rpc kind of options. The host program can capture the outputs on output stream by default. Not the reverse – Kris Mar 23 '22 at 14:32
  • you want to get hacky? arduino leonardo to emulate a keyboard and send the options in a loop. –  Mar 23 '22 at 14:35
  • The thing is I dont have access to the exe source code, and, therefore I dont know if/how it supports such channel – JohnCalms Mar 23 '22 at 14:37
  • 1
    Your Python code is very wrong, it should be something closer to `Popen("executable.exe 1", shell=True, stdin=PIPE, encoding='utf8').communicate(input="1\n")` – Anon Coward Mar 23 '22 at 15:47
  • @JohnCalms. Are you still trying to find a solution for this? There might be an easier way to do this with AHK depending on what the 3 actions are, but would need a lot more information about what you are trying to do. – T_Lube Jun 02 '22 at 08:03

1 Answers1

0

For AutoHotkey, if you have it installed open install dir and launch Window Spy then click on the text area or list you are typing 1, 2 or 3 in your .exe window then see if there is special class in focused control area in Window Spy. If there is, it's easy, just check here for ControlFocus then here for sending keys. You can check here as well. If there is no class or it's main class of your .exe, you can add wait time with Sleep, Xms then send keys or wait for app to load after launching it wit RunWait then sending keys or looping an ImageSearch function then making sure your app's window visible then either sending keys directly or clicking on coords then sending.

ahk window spy

Toorop
  • 26
  • 5