Add input handling functionality to the agent. Implement API endpoints for mouse click and text input, and update the web interface to support video capture and interaction features.

This commit is contained in:
2026-08-18 19:12:25 +03:00
parent f24e31da27
commit 16d7aa75b3
8 changed files with 447 additions and 26 deletions
+69 -6
View File
@@ -13,6 +13,8 @@ import (
"tea.chunkbyte.com/kato/go-worm/lib/models"
)
var ErrMonitorNotFound = errors.New("monitor not found")
var (
user32 = syscall.NewLazyDLL("user32.dll")
gdi32 = syscall.NewLazyDLL("gdi32.dll")
@@ -68,19 +70,80 @@ func Capture(format string, quality int) ([]models.CapturedImage, error) {
}
result := make([]models.CapturedImage, 0, len(monitors))
for _, monitor := range monitors {
img, err := captureRect(monitor)
frame, err := captureAndEncode(monitor, format, quality)
if err != nil {
return nil, err
}
data, contentType, err := encodeImage(img, format, quality)
if err != nil {
return nil, err
}
result = append(result, models.CapturedImage{ContentType: contentType, Data: data})
result = append(result, frame)
}
return result, nil
}
func CaptureMonitor(index int, format string, quality int) (models.CapturedImage, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if err := attachInputDesktop(); err != nil {
return models.CapturedImage{}, err
}
monitors, err := enumerateMonitors()
if err != nil {
return models.CapturedImage{}, err
}
if index < 0 || index >= len(monitors) {
return models.CapturedImage{}, ErrMonitorNotFound
}
return captureAndEncode(monitors[index], format, quality)
}
func MonitorCount() (int, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if err := attachInputDesktop(); err != nil {
return 0, err
}
monitors, err := enumerateMonitors()
if err != nil {
return 0, err
}
return len(monitors), nil
}
func MonitorBounds(index int) (left, top, width, height int, err error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if err := attachInputDesktop(); err != nil {
return 0, 0, 0, 0, err
}
monitors, err := enumerateMonitors()
if err != nil {
return 0, 0, 0, 0, err
}
if index < 0 || index >= len(monitors) {
return 0, 0, 0, 0, ErrMonitorNotFound
}
r := monitors[index]
return int(r.Left), int(r.Top), int(r.Right - r.Left), int(r.Bottom - r.Top), nil
}
func captureAndEncode(monitor rect, format string, quality int) (models.CapturedImage, error) {
img, err := captureRect(monitor)
if err != nil {
return models.CapturedImage{}, err
}
data, contentType, err := encodeImage(img, format, quality)
if err != nil {
return models.CapturedImage{}, err
}
return models.CapturedImage{
ContentType: contentType,
Data: data,
Left: int(monitor.Left),
Top: int(monitor.Top),
Width: int(monitor.Right - monitor.Left),
Height: int(monitor.Bottom - monitor.Top),
}, nil
}
func attachInputDesktop() error {
h, _, err := procOpenInputDesktop.Call(0, 0, 0x0001|0x0040)
if h == 0 {