How to use setForegroundWindow method in fMBT

Best Python code snippet using fMBT_python

MWTextMove256.py

Source:MWTextMove256.py Github

copy

Full Screen

1import win32.win32gui2import win32com.client3import keystrokeHandler4import pyautogui5import time6import array as arr78commandWindowID = win32.win32gui.GetForegroundWindow()9print("The HWND for the command window is " + str(commandWindowID))10gameWindowID = win32.win32gui.FindWindow(None,"QuadRay engine demo, (C) 2013-2020 VectorChief")11print("The HWND for the window is " + str(gameWindowID))1213#Now, begin automated control of the QuadRay Demo1415#First, run the demo with16# ------------------ TARGET CONFIG ---------------------17# SIMD size/type = 256x2v2, tile_W = 2xW, FSAA = 1 (off)18# Framebuffer X-row = 800, ptr = 0000000046A5008019# Framebuffer X-res = 800, Y-res = 480, l 0, h 020# Window-rect X-res = 800, Y-res = 480, u 0, o 021# Threads/affinity = 16/1, reserved = 0, d 3, c 122# --------------------- FPS LOG ------ ptr/fp = 64_64 --2324n_simd = [256]25k_size = [2, 1]26s_type = [2, 1]27anti_aliasing = [1, 2, 4]28scenes = [1, 2, 3]2930for scene in scenes:3132 #If we're on the second scene, we will need to reset back to 256x2v2 before proceeeding since its default is 128x33 #if (scene == 2):343536 for nsimd in n_simd:37 for ksize in k_size:38 for stype in s_type:39 for AA in anti_aliasing:40 41 print("Now entering trial:")42 print("Scene: " + str(scene))43 print("n_simd: " + str(nsimd))44 print("k_size: " + str(ksize))45 print("s_type: " + str(stype))46 print("Anti-Aliasing: " + str(AA))4748 #First, check if s_type = 4, because if so, it should only be used when n_simd = 12849 #Otherwise, if n_simd = 128, then s_type can ONLY be 450 if (stype == 4 and nsimd != 128):51 print("Invalid case, nsimd must be 128 for stype to be 4. Skipping...")52 print("Changing AA...")53 #Increase AA prematurely...54 shell = win32com.client.Dispatch("WScript.Shell")55 shell.SendKeys('%')56 win32.win32gui.SetForegroundWindow(gameWindowID)57 keystrokeHandler.F2Key()58 time.sleep(0.5)59 win32.win32gui.SetForegroundWindow(commandWindowID)60 61 continue62 if (nsimd == 128 and stype != 4):63 print("Invalid case, stype must be 4 for nsimd to be 128. Skipping...")64 print("Changing AA...")65 #Increase AA prematurely...66 shell = win32com.client.Dispatch("WScript.Shell")67 shell.SendKeys('%')68 win32.win32gui.SetForegroundWindow(gameWindowID)69 keystrokeHandler.F2Key()70 time.sleep(0.5)71 win32.win32gui.SetForegroundWindow(commandWindowID)7273 continue74 75 print("Waiting for 10 seconds for the trial to finish...")76 time.sleep(10) #Wait for 10 seconds to let the trial to run...7778 #Increase AA...79 print("Changing AA...")80 shell = win32com.client.Dispatch("WScript.Shell")81 shell.SendKeys('%')82 win32.win32gui.SetForegroundWindow(gameWindowID)83 keystrokeHandler.F2Key()84 time.sleep(0.5)85 win32.win32gui.SetForegroundWindow(commandWindowID)86 87 #Increase s_type...88 print("Changing s_type...")89 shell = win32com.client.Dispatch("WScript.Shell")90 shell.SendKeys('%')91 win32.win32gui.SetForegroundWindow(gameWindowID)92 keystrokeHandler.F7Key()93 time.sleep(0.5)94 win32.win32gui.SetForegroundWindow(commandWindowID)9596 #Increase k_size97 print("Changing k_size...")98 shell = win32com.client.Dispatch("WScript.Shell")99 shell.SendKeys('%')100 win32.win32gui.SetForegroundWindow(gameWindowID)101 keystrokeHandler.F6Key()102 time.sleep(0.5)103 win32.win32gui.SetForegroundWindow(commandWindowID)104105 # #Increase n_simd106 # print("Changing n_simd...")107 # shell = win32com.client.Dispatch("WScript.Shell")108 # shell.SendKeys('%')109 # win32.win32gui.SetForegroundWindow(gameWindowID)110 # keystrokeHandler.F8Key()111 # time.sleep(0.5)112 # win32.win32gui.SetForegroundWindow(commandWindowID)113114 #Change the scene...115 print("Changing scene...")116 shell = win32com.client.Dispatch("WScript.Shell")117 shell.SendKeys('%')118 win32.win32gui.SetForegroundWindow(gameWindowID)119 keystrokeHandler.F11Key()120 time.sleep(0.5)121 win32.win32gui.SetForegroundWindow(commandWindowID)122123#Finally, kill the program124print("Ending RooT Demo and saving data...")125shell = win32com.client.Dispatch("WScript.Shell")126shell.SendKeys('%')127win32.win32gui.SetForegroundWindow(gameWindowID)128keystrokeHandler.escKey()129time.sleep(0.5) ...

Full Screen

Full Screen

MWTextMove128.py

Source:MWTextMove128.py Github

copy

Full Screen

1import win32.win32gui2import win32com.client3import keystrokeHandler4import pyautogui5import time6import array as arr78commandWindowID = win32.win32gui.GetForegroundWindow()9print("The HWND for the command window is " + str(commandWindowID))10gameWindowID = win32.win32gui.FindWindow(None,"QuadRay engine demo, (C) 2013-2020 VectorChief")11print("The HWND for the window is " + str(gameWindowID))1213#Now, begin automated control of the QuadRay Demo1415#First, run the demo with16# ------------------ TARGET CONFIG ---------------------17# SIMD size/type = 256x2v2, tile_W = 2xW, FSAA = 1 (off)18# Framebuffer X-row = 800, ptr = 0000000046A5008019# Framebuffer X-res = 800, Y-res = 480, l 0, h 020# Window-rect X-res = 800, Y-res = 480, u 0, o 021# Threads/affinity = 16/1, reserved = 0, d 3, c 122# --------------------- FPS LOG ------ ptr/fp = 64_64 --2324n_simd = [128]25k_size = [2, 1]26s_type = [4]27anti_aliasing = [1, 2, 4]28scenes = [1, 2, 3]2930#First, set n_simd to 12831#Increase n_simd32print("Changing n_simd...")33shell = win32com.client.Dispatch("WScript.Shell")34shell.SendKeys('%')35win32.win32gui.SetForegroundWindow(gameWindowID)36keystrokeHandler.F8Key()37time.sleep(0.5)38win32.win32gui.SetForegroundWindow(commandWindowID)3940for scene in scenes:4142 #If we're on the second scene, we will need to reset back to 256x2v2 before proceeeding since its default is 128x43 #if (scene == 2):444546 for nsimd in n_simd:47 for ksize in k_size:48 for stype in s_type:49 goneOnce = False50 for AA in anti_aliasing:51 52 print("Now entering trial:")53 print("Scene: " + str(scene))54 print("n_simd: " + str(nsimd))55 print("k_size: " + str(ksize))56 print("s_type: " + str(stype))57 print("Anti-Aliasing: " + str(AA))5859 #First, check if s_type = 4, because if so, it should only be used when n_simd = 12860 #Otherwise, if n_simd = 128, then s_type can ONLY be 461 if (ksize == 1 and goneOnce == True):62 print("Invalid case, no other instances of AA exist for 128 beyond 1...")63 print("Changing AA...")64 #Increase AA prematurely...65 shell = win32com.client.Dispatch("WScript.Shell")66 shell.SendKeys('%')67 win32.win32gui.SetForegroundWindow(gameWindowID)68 keystrokeHandler.F2Key()69 time.sleep(0.5)70 win32.win32gui.SetForegroundWindow(commandWindowID)71 72 continue73 74 print("Waiting for 10 seconds for the trial to finish...")75 time.sleep(10) #Wait for 10 seconds to let the trial to run...7677 #Increase AA...78 print("Changing AA...")79 shell = win32com.client.Dispatch("WScript.Shell")80 shell.SendKeys('%')81 win32.win32gui.SetForegroundWindow(gameWindowID)82 keystrokeHandler.F2Key()83 time.sleep(0.5)84 win32.win32gui.SetForegroundWindow(commandWindowID)85 goneOnce = True86 87 #Increase s_type...88 # print("Changing s_type...")89 # shell = win32com.client.Dispatch("WScript.Shell")90 # shell.SendKeys('%')91 # win32.win32gui.SetForegroundWindow(gameWindowID)92 # keystrokeHandler.F7Key()93 # time.sleep(0.5)94 # win32.win32gui.SetForegroundWindow(commandWindowID)9596 #Increase k_size97 print("Changing k_size...")98 shell = win32com.client.Dispatch("WScript.Shell")99 shell.SendKeys('%')100 win32.win32gui.SetForegroundWindow(gameWindowID)101 keystrokeHandler.F6Key()102 time.sleep(0.5)103 win32.win32gui.SetForegroundWindow(commandWindowID)104105 # #Increase n_simd106 # print("Changing n_simd...")107 # shell = win32com.client.Dispatch("WScript.Shell")108 # shell.SendKeys('%')109 # win32.win32gui.SetForegroundWindow(gameWindowID)110 # keystrokeHandler.F8Key()111 # time.sleep(0.5)112 # win32.win32gui.SetForegroundWindow(commandWindowID)113114 #Change the scene...115 print("Changing scene...")116 shell = win32com.client.Dispatch("WScript.Shell")117 shell.SendKeys('%')118 win32.win32gui.SetForegroundWindow(gameWindowID)119 keystrokeHandler.F11Key()120 time.sleep(0.5)121 win32.win32gui.SetForegroundWindow(commandWindowID)122123#Finally, kill the program124print("Ending RooT Demo and saving data...")125shell = win32com.client.Dispatch("WScript.Shell")126shell.SendKeys('%')127win32.win32gui.SetForegroundWindow(gameWindowID)128keystrokeHandler.escKey()129time.sleep(0.5) ...

Full Screen

Full Screen

wmctrl.py

Source:wmctrl.py Github

copy

Full Screen

1from keyboardexpanse.oslayer.config import PLATFORM2if PLATFORM == "win":3 from ctypes import windll, wintypes4 GetForegroundWindow = windll.user32.GetForegroundWindow5 GetForegroundWindow.argtypes = []6 GetForegroundWindow.restype = wintypes.HWND7 SetForegroundWindow = windll.user32.SetForegroundWindow8 SetForegroundWindow.argtypes = [9 wintypes.HWND, # hWnd10 ]11 SetForegroundWindow.restype = wintypes.BOOL12elif PLATFORM == "mac":13 from Cocoa import (14 NSApplicationActivateIgnoringOtherApps,15 NSRunningApplication,16 NSWorkspace,17 )18 def GetForegroundWindow():19 return NSWorkspace.sharedWorkspace().frontmostApplication().processIdentifier()20 def SetForegroundWindow(pid):21 target_window = NSRunningApplication.runningApplicationWithProcessIdentifier_(22 pid23 )24 target_window.activateWithOptions_(NSApplicationActivateIgnoringOtherApps)25elif PLATFORM in {"linux", "bsd"}:26 from keyboardexpanse.oslayer.xwmctrl import WmCtrl27 wmctrl = WmCtrl()28 GetForegroundWindow = wmctrl.get_foreground_window...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful