MCPcopy Create free account
hub / github.com/MaaXYZ/MaaFramework / test_background_managed_keys_api

Function test_background_managed_keys_api

test/python/binding_test.py:747–802  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

745
746
747def test_background_managed_keys_api():
748 print("\n=== test_background_managed_keys_api ===")
749
750 # Test with DbgController (non-Win32, should fail)
751 dbg_controller = DbgController(
752 install_dir / "test" / "PipelineSmoking" / "Screenshot",
753 )
754 dbg_ret = dbg_controller.set_background_managed_keys([0x57, 0x41])
755 print(f" dbg_controller set_background_managed_keys: {dbg_ret}")
756 assert not dbg_ret, "DbgController should not support BackgroundManagedKeys"
757
758 # Test with Win32 controller if available
759 desktop_windows = Toolkit.find_desktop_windows()
760 if desktop_windows:
761 win32_controller = None
762 for window in desktop_windows:
763 try:
764 win32_controller = Win32Controller(window.hwnd)
765 break
766 except RuntimeError:
767 continue
768
769 if win32_controller is not None:
770 # Set option before connection
771 ret = win32_controller.set_background_managed_keys([0x57, 0x41])
772 print(
773 f" win32_controller set_background_managed_keys (before connection): {ret}"
774 )
775 assert (
776 ret
777 ), "Win32Controller should support BackgroundManagedKeys before connection"
778
779 # After connection, setting non-empty array should succeed
780 win32_controller.post_connection().wait()
781 ret_post = win32_controller.set_background_managed_keys([0x57, 0x41])
782 print(
783 f" win32_controller set_background_managed_keys (after connection): {ret_post}"
784 )
785 assert (
786 ret_post
787 ), "Win32Controller should support BackgroundManagedKeys after connection"
788
789 # Empty array should clear managed keys
790 ret_clear = win32_controller.set_background_managed_keys([])
791 print(
792 f" win32_controller set_background_managed_keys (clear with empty): {ret_clear}"
793 )
794 assert (
795 ret_clear
796 ), "Win32Controller should support clearing BackgroundManagedKeys with empty array"
797 else:
798 print(" SKIP: failed to create Win32 controller")
799 else:
800 print(" SKIP: no desktop windows found for Win32 test")
801
802 print(" PASS: background managed keys API")
803
804

Callers 1

binding_test.pyFile · 0.85

Calls 6

DbgControllerClass · 0.90
Win32ControllerClass · 0.90
find_desktop_windowsMethod · 0.80
waitMethod · 0.65
post_connectionMethod · 0.45

Tested by

no test coverage detected