wailsapp/wails · error

unkown type

Error message

unkown type

What it means

The SendInput wrapper panics with 'unkown type' (sic) when an element of the inputs slice has a Type that is not INPUT_MOUSE, INPUT_KEYBOARD, or INPUT_HARDWARE. SendInput serializes a heterogeneous INPUT array; each element must tag which union member (mi/ki/hi) is populated, and the wrapper refuses untagged or corrupted values.

Source

Thrown at v3/pkg/w32/user32.go:1435

	return int32(ret)
}

/*
func SendInput(inputs []INPUT) uint32 {
	var validInputs []C.INPUT

	for _, oneInput := range inputs {
		input := C.INPUT{_type: C.DWORD(oneInput.Type)}

		switch oneInput.Type {
		case INPUT_MOUSE:
			(*MouseInput)(unsafe.Pointer(&input)).mi = oneInput.Mi
		case INPUT_KEYBOARD:
			(*KbdInput)(unsafe.Pointer(&input)).ki = oneInput.Ki
		case INPUT_HARDWARE:
			(*HardwareInput)(unsafe.Pointer(&input)).hi = oneInput.Hi
		default:
			panic("unkown type")
		}

		validInputs = append(validInputs, input)
	}

	ret, _, _ := procSendInput.Call(
		uintptr(len(validInputs)),
		uintptr(unsafe.Pointer(&validInputs[0])),
		uintptr(unsafe.Sizeof(C.INPUT{})),
	)
	return uint32(ret)
}*/

func SetWindowsHookEx(idHook int, lpfn HOOKPROC, hMod HINSTANCE, dwThreadId DWORD) HHOOK {
	ret, _, _ := procSetWindowsHookEx.Call(
		uintptr(idHook),
		uintptr(syscall.NewCallback(lpfn)),
		uintptr(hMod),

View on GitHub (pinned to 0e754b1b40)

Solutions

  1. Always set Type explicitly: w32.KeyboardInput uses {Type: w32.INPUT_KEYBOARD, Ki: ...}
  2. Map raw config integers to the three constants before building the slice
  3. Validate the slice in a loop before calling SendInput and reject/log unknown types instead of panicking

Example fix

// before
inputs := []w32.Input{{Ki: w32.KbdInput{...}}} // Type omitted -> panic
w32.SendInput(inputs)

// after
inputs := []w32.Input{{Type: w32.INPUT_KEYBOARD, Ki: w32.KbdInput{...}}}
w32.SendInput(inputs)
Defensive patterns

Strategy: type-guard

Type guard

func isValidInputType(t uint32) bool {
    return t == w32.INPUT_MOUSE || t == w32.INPUT_KEYBOARD || t == w32.INPUT_HARDWARE
}

Prevention

When it happens

Trigger: Building INPUT structs with Type left at the zero value (0 is not a valid input type — mouse is 0, keyboard 1, hardware 2 in the raw API, but the wrapper requires the named constants exactly); passing a struct literal that omits the Type field; bit flags ORed into Type.

Common situations: Synthetic input / automation code (simulated keystrokes for global shortcuts, test harnesses) where the Type field is forgotten in a struct literal; values coming from user config parsed as raw ints that do not match the constants.

Related errors


AI-assisted analysis of wailsapp/wails@0e754b1b40 (2026-08-15). Data as JSON: /api/errors/5ff5c953d1713c8f. Report an issue: GitHub.