ConvertTo-GamepadInput.ps1

function ConvertTo-GamepadInput {
    param(
    [Collections.Generic.Dictionary[string,string]]
    $Dictionary
    )
    
    process {
        Set-StrictMode -Off
        $VerbosePreference = "continue"
        Write-Verbose ($Dictionary | Out-String)
        $gamepadInput = [Xap.XapController]::NewGamepadInput()
        foreach ($kv in $Dictionary.GetEnumerator()) {
            if ($kv.Key -like "*Trigger*") {
                $gamePadInput.($kv.Key) = 
                    ($kv.Value -as [float]) * 255
                continue
            }
            if ($kv.Key -like "*Stick*") {                
                $gamePadInput.($kv.Key) = 
                    ($kv.Value -as [float]) * [int16]::MaxValue
                continue
            }
            $gamePadInput.Button = 
                $gamePadInput.Button -bor ($kv.Key -as $gamePadInput.Button.GetType())
        }
        Write-Verbose ($GamepadInput | Out-String)
        $GamepadInput
    }
}