You can use the wincapture library to capture screens, wait for specific changes, and perform advanced image analysis like finding colors or pictures using a BitmapBuffer.
Capture and Save
Use captureAndSave() to capture the screen. You can pass a Buffer to define a specific capture range (x, y, width, height).
Waiting for Changes
waitScreenChange(timeout, box) allows you to pause execution until a specific region (defined by a box buffer) changes on the screen.
Image Analysis with BitmapBuffer
When capturing via callback, you receive raw pixel data which can be wrapped in a BitmapBuffer to perform:
findPic(&x, &y, picture): Search for a specific image.findColor(&x, &y, color): Search for a specific pixel color.findMultiColors(&x, &y, array): Search for a specific combination of multiple pixel colors and offsets.
; Initialize DXGI capture
dxcp := wincapture.DXGI()
; Define a capture range (x, y, x2, y2)
box := Buffer(16, 0)
NumPut("uint", 0, "uint", 0, "uint", 500, "uint", 500, box)
; Wait up to 15 seconds for the screen area to change
if dxcp.waitScreenChange(15000, box)
MsgBox "Screen changed!"
; Capture and save to file
dxcp.captureAndSave(box).save('capture.bmp')
; Capture via callback for real-time processing
cb := CallbackCreate(MyCallback)
dxcp.capture(cb)
MyCallback(pdata, pitch, sw, sh, tick) {
if tick && pdata {
bb := BitmapBuffer(pdata, pitch, sw, sh)
; Example: Find a specific color
targetColor := 0xFF0000
if bb.findColor(&x, &y, targetColor)
MsgBox "Found color at " x "," y
; Example: Find a picture
pic := BitmapBuffer.loadPicture("template.bmp")
if bb.findPic(&x, &y, pic)
MsgBox "Found picture at " x "," y
}
}