Compare commits

..

2 Commits

Author SHA1 Message Date
Aveline efdd72ce87
Merge 854cdc8e82 into c8dd84c6b7 2025-09-10 00:43:14 +00:00
Siyuan Miao 854cdc8e82 more proper type checking 2025-09-10 02:42:36 +02:00
1 changed files with 23 additions and 13 deletions

View File

@ -1111,28 +1111,38 @@ func rpcKeyboardReportMulti(ctx context.Context, macro []map[string]any) (usbgad
}
var modifier byte
if m, ok := step["modifier"].(float64); ok {
switch m := step["modifier"].(type) {
case uint8:
modifier = m
case int:
modifier = byte(m)
case float64:
modifier = byte(int(m))
} else if mi, ok := step["modifier"].(int); ok {
modifier = byte(mi)
} else if mb, ok := step["modifier"].(uint8); ok {
modifier = mb
default:
return last, fmt.Errorf("invalid modifier type: %T", m)
}
var keys []byte
if arr, ok := step["keys"].([]any); ok {
switch k := step["keys"].(type) {
case []byte:
keys = k
case []any:
arr := k
keys = make([]byte, 0, len(arr))
for _, v := range arr {
if f, ok := v.(float64); ok {
switch f := v.(type) {
case uint8:
keys = append(keys, f)
case int:
keys = append(keys, byte(f))
case float64:
keys = append(keys, byte(int(f)))
} else if i, ok := v.(int); ok {
keys = append(keys, byte(i))
} else if b, ok := v.(uint8); ok {
keys = append(keys, b)
default:
return last, fmt.Errorf("invalid key type: %T", f)
}
}
} else if bs, ok := step["keys"].([]byte); ok {
keys = bs
default:
return last, fmt.Errorf("invalid keys type: %T", k)
}
// Use context-aware sleep that can be cancelled