title: Pynput and pyautogui are not performing keyboard commands for a specific program I'm running?
body: <p>I'm trying to write a 'hack' program in python to automate the use of a measurement system that we do not have the API for at my job. The idea is to open the program, and then utilize the keyboard to input user inputs from a GUI to run a measurement. I've tested this exact program using notepad and firefox to see if the hotkeys will open new windows, select the search bar, type a message, etc, etc. The thing is, while this works for every other program I've tried, for some reason the keyboard presses will <em>not</em> work for this one. I know hotkeys work using the keyboard because I can access everything I need via the keyboard hotkeys directly, only through pynput and pyautogui do the key presses not register.</p>
  <p>For now, this code should just open the device, wait 20 seconds for it to start up, then open one of the menus using a simple pyautogui hold and press command:</p>
  <pre><code>import pyautogui
  import subprocess
  from tkinter import *
  import time
  import threading
  
  # Sleep function
  def SleepSec(var):
       time.sleep(var)
  
  
  # Hotkey function runs hotkeys to take measurement
  def HotkeyEntry():
       
       # Open program
       subprocess.Popen(['C:\\Program Files (x86)\\program\\program.exe'],shell=True)
       print('Before 20 sec wait')
  
       intervalEntry = E1.get() #Interval time
       dataEntry = dropVar.get() #RAW or Radiometric data
       pathEntry = E2.get() #Path file
       filenameEntry = E3.get() #filename
       startNumEntry = E4.get() #Starting measurement number
       countEntry = E5.get() #Number of measurements to take
       commentEntry = E6.get() #Comments about measurement
  
       SleepSec(20)
       with pyautogui.hold('alt'):
                 pyautogui.press('c')
  
       print('Made it here #1')
  
  # Create a GUI
  root = Tk()
  
  root.title('Measurement')
  
  dropVar = StringVar(root)
  
  options = [
       &quot;RAW&quot;,
       &quot;Radiometric&quot;
  ]
  
  dropVar.set(options[0])
  
  # Labels and entries for desired measurement parameters
  L1 = Label(root, text = &quot;Measurement Interval&quot;).grid(row = 0)
  E1 = Entry(root, bd = 5)
  E1.insert(10,&quot;1&quot;)
  E1.grid(row=0,column=1)
  
  L2 = Label(root, text = &quot;Pathname&quot;).grid(row = 1)
  E2 = Entry(root, bd = 5)
  E2.insert(10,&quot;C:/Users/MainUser/Documents/data/test&quot;)
  E2.grid(row=1,column=1)
  
  L3 = Label(root, text = &quot;Filename&quot;).grid(row = 2)
  E3 = Entry(root, bd = 5)
  E3.insert(10,&quot;DefaultFilename&quot;)
  E3.grid(row=2,column=1)
  
  L4 = Label(root, text = &quot;Measurement #&quot;).grid(row = 3)
  E4 = Entry(root, bd = 5)
  E4.insert(10,&quot;0&quot;)
  E4.grid(row=3,column=1)
  
  L5 = Label(root, text = &quot;Number of files to save&quot;).grid(row = 4)
  E5 = Entry(root, bd = 5)
  E5.insert(10,&quot;30&quot;)
  E5.grid(row=4,column=1)
  
  L6 = Label(root, text = &quot;Comment&quot;).grid(row = 5)
  E6 = Entry(root, bd = 5)
  E6.insert(10,&quot;Comment here&quot;)
  E6.grid(row=5,column=1)
  
  O1 = OptionMenu(root, dropVar, *options).grid(row = 6)
  
  # Buttons for running measurement and quiting
  B1 = Button(root,
            text = 'Quit',
            command = root.quit).grid(row = 7,
                                     column = 0,
                                     sticky=W,
                                     pady=4)
  
  B2 = Button(root,
            text = &quot;Measure&quot;, command= lambda: threading.Thread(target = HotkeyEntry).start()).grid(row=7,
                                                         column=1,
                                                         sticky=W,
                                                         pady=4)
  
  root.mainloop()
  </code></pre>
  <p>Whenever I run the GUI, the program will start up and I can see in the command window that the program does reach the &quot;Made it here #1&quot; print out, so it's not getting stuck in the code somewhere, it's just not performing the keyboard commands. It is also not that I'm not clicking the window, because I can still manually enter in the alt+c hotkey directly and the menu I want pops up without clicking on anything once the program starts. It's as if the keyboard isn't listening to the python code to push those keys or something. this is true using both pynput and pyautogui. Has anyone seen something like this or could help me?</p>