title: Python PyWin32 send keys to DirectX game in the background
body: <p>I have made a script that can send keys to any app in the background, but it does not work on DirectX.</p>
  <p>I am trying to make my character jump in a game called &quot;roblox&quot;.</p>
  <p>This is the script</p>
  <pre><code>import time
  import psutil
  import win32con
  from win32 import win32gui
  from win32 import win32api
  from win32 import win32process
  
  keyDict = {&quot; &quot;: 0x20}
  for i in range(0x41, 0x5A+1):
      keyDict[chr(i)] = i
  
  def CloseExe(exeName):
      ID2Handle={}
      def get_all_hwnd(hwnd,mouse):
        if win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd) and win32gui.IsWindowVisible(hwnd):
          nID=win32process.GetWindowThreadProcessId(hwnd)
          del nID[0]
          for abc in nID:
            try:
              pro=psutil.Process(abc).name()
            except psutil.NoSuchProcess:
              pass
            else:
              if pro == exeName:
                       win32gui.PostMessage(hwnd,win32con.WM_CLOSE,0,0)
  
      win32gui.EnumWindows(get_all_hwnd, 0)
  
  def SendKeysSensitive(exeName, keysToSend):
      mID2Handle={}
      def get_all_hwnd(hwnd,mouse):
        hwndTwo = win32gui.GetWindow(hwnd, win32con.GW_CHILD)
        if win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd) and win32gui.IsWindowVisible(hwnd):
          nID=win32process.GetWindowThreadProcessId(hwnd)
          del nID[0]
          for abc in nID:
            try:
              pro=psutil.Process(abc).name()
            except psutil.NoSuchProcess:
              pass
            else:
              if pro == exeName:
                  for key in keysToSend:
                       win32gui.PostMessage(hwndTwo, win32con.WM_CHAR, key, 0)
  
  def SendKeys(exeName, keysToSend):
      mID2Handle={}
      def get_all_hwnd(hwnd,mouse):
        hwndTwo = hwnd
        if win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd) and win32gui.IsWindowVisible(hwnd):
          nID=win32process.GetWindowThreadProcessId(hwnd)
          del nID[0]
          for abc in nID:
            try:
              pro=psutil.Process(abc).name()
            except psutil.NoSuchProcess:
              pass
            else:
              if pro == exeName:
                  for key in keysToSend:
                       win32gui.PostMessage(hwndTwo, win32con.WM_CHAR, key, 0)
  
      win32gui.EnumWindows(get_all_hwnd, 0)
  
  
  def TranslateKeys(text):
      outKeys = []
      for char in text:
          outKeys.append(keyDict.get(char.upper()))
      return outKeys
  
  def ExE(name):
      return name
  
  if __name__ == '__main__':
      prog = ExE(&quot;RobloxPlayerBeta.exe&quot;)
      jump = TranslateKeys(&quot; &quot;)
      SendKeys(prog, jump)
  </code></pre>
  <p>It does not work due to &quot;RobloxPlayerBeta.exe&quot; being DirectX.</p>
  <p>I can not open the app, it 100% needs to be in the background.</p>
  <p>Is this possible?</p>