Input.GetAxis never outputs 0 (keyboard as input device)

HI,

We are trying to debug an issue my son has on my laptop with his Unity game.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Keyboard : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
        Debug.Log(Input.GetAxis("Horizontal") + "\t" + Input.GetAxis("Vertical"));
    }
}

I would expect the debug to show “0 0” when I’m not pressing any arrow or WSAD keys on my keyboard.
But in reality it outputs “-1 1” and when I press the arrow keys they switch to -1/1 but never to 0.

I found several questions about this but as far as I could see those questions involved a joystick or gamecontroller which was not correctly calibrated. But I’m having these issues with my laptop keyboard.

Does anyone have a suggestion on what could be causing this?

Check the Input settings (Edit → ProjectSettings → Input)

By default there are other things mapped to these axes.

Normally those things don’t cause problems.

Perhaps in your case they do.

You could try isolating them so there is only key input.

ALWAYS use source control so you can instantly revert any potential changes you make anywhere with just one click.

Also, I find it better to check the keys I want rather than read the axes, something like Line 115 here:

or Line 182 here:

Another option would be the new input system, which replaces the old input system above entirely.

Thanks!!!

I think I fixed it by changing the dead value from 0.0001 to 0.1
9127417--1266736--upload_2023-7-5_22-58-43.png

I would have programmed it using the keycodes like you showed in your examples.
I’ll try to educate him :stuck_out_tongue: He is 13 and this is his first real experience with C# after a little Python.

That’s so awesome. Hope you two have LOADS of fun with this stuff… I wish I had Unity when I was 13!!