Reputation: 31
I tried this :
import win32gui
import win32con
import time
# Fonction pour trouver le handle de la fenêtre BlueStacks
def find_bluestacks_window():
def callback(hwnd, extra):
title = win32gui.GetWindowText(hwnd)
if "BlueStacks" in title:
extra.append(hwnd)
return True
bluestacks_windows = []
win32gui.EnumWindows(callback, bluestacks_windows)
return bluestacks_windows
# Fonction pour simuler l'appui sur la touche gauche dans une fenêtre spécifique
def press_left_key(hwnd):
win32gui.PostMessage(hwnd, win32con.WM_KEYDOWN, win32con.VK_LEFT, 0)
time.sleep(0.1) # Attente courte
win32gui.PostMessage(hwnd, win32con.WM_KEYUP, win32con.VK_LEFT, 0)
# Trouver la fenêtre BlueStacks
bluestacks_windows = find_bluestacks_window()
if bluestacks_windows:
# Sélectionner la première fenêtre BlueStacks
bluestacks_window = bluestacks_windows[0]
# Simuler l'appui sur la touche gauche
press_left_key(bluestacks_window)
else:
print("La fenêtre BlueStacks n'a pas été trouvée.")
But the script does not want to perform the requested action when the bluestack window is not active. When the window is active (in the main window) then it works, but I would like it to work in the background, I would like the action to take place even if the window is not active.
Upvotes: 0
Views: 70