1

Start a computer

from halyard import Client

client = Client()                          # reads HALYARD_API_KEY
computer = client.computers.create(viewport={"width": 1920, "height": 1080})
try:
    with computer.connect() as pc:
        ...                                # the steps below go here
finally:
    computer.stop()
The viewport must be one of the display modes. A computer keeps running until it is stopped, so stop it in finally, which runs even when a step fails.
2

Start Notepad and wait for its window

pc.processes.start("notepad.exe")
note = pc.windows.wait_for(process="notepad.exe")
note.focus()
3

Fill in the text

pc.get_by_role("document", name="Text editor").fill("hello from Halyard")
pc.keyboard.press("Control+a")
pc.keyboard.press("Control+c")
print(pc.clipboard.read())                 # hello from Halyard
fill() waits until Notepad’s text area is ready, then types into it. Typing with pc.keyboard the moment a window appears can lose keystrokes, since the app may not be taking input yet. Every chord reaches Windows, the Windows key included.
4

Find controls by role and name

pc.processes.start("calc.exe")
calc = pc.get_by_role("window", name="Calculator")
for key in ["Seven", "Multiply by", "Six", "Equals"]:
    calc.get_by_role("button", name=key, exact=True).click()
print(pc.get_by_test_id("CalculatorResults").inner_text())   # Display is 42

print(pc.snapshot())                       # the native UI, with [ref=...] per element
Native apps are found through Windows UI Automation, with the same locators a page takes. get_by_test_id matches the automation id. See Native apps.
5

Work with files and commands

pc.files.write_text("Documents\\hello.txt", "written by my script\n")
print(pc.files.read_text("%USERPROFILE%\\Documents\\hello.txt"))

r = pc.processes.run("Get-Date")
print(r.stdout)

pc.screenshot(path="desktop.png")
6

Stop it

Leaving the with block closes the connection, and finally stops the computer. The machine is reset after it ends; nothing carries over to the next session.

The whole script

computer_quickstart.py
from halyard import Client

client = Client()
computer = client.computers.create(viewport={"width": 1920, "height": 1080})
try:
    with computer.connect() as pc:
        pc.processes.start("notepad.exe")
        pc.windows.wait_for(process="notepad.exe").focus()
        pc.get_by_role("document", name="Text editor").fill("hello from Halyard")

        pc.files.write_text("Documents\\hello.txt", "written by my script\n")
        print(pc.processes.run("Get-Date").stdout)
        pc.screenshot(path="desktop.png")
finally:
    computer.stop()

Next steps

Computer

The screen, mouse and keyboard.

Processes

Run commands and programs.