Change Input.GetKey to Input.GetAxis

Hi, I have some code for controlling player’s movement but there is one problem - the keys are set fixed in code and generally can’t be changed. I know that Unity has something like Input.GetAxis() method where I can use “Horizontal” or “Vertical” keys. According to this, I can change keys via Application Config Dialog which is fine because game could be playable via keyboard or gamepad.

I’m thinking about using GetAxis methods but I don’t have any idea how to change the code below. The idea should be the same as it’s current. Could you suggest me how I can rewrite this code to use Input.GetAxis for horizontal?

if (Input.GetKey("Q")) {
	rigidBody.AddForce(-myForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);

if (Input.GetKey("W")) {
	rigidBody.AddForce(myForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);

There is a good example in the documentation for Input.GetAxis(). When you get the result back for a joystick or keyboard, the value will range from -1 to 1, so you can just multiply that value by your force. Try this:

var hoizontalAxis = Input.GetAxis("Horizontal");
rigidBody.AddForce(myForce * Time.deltaTime * hoizontalAxis, 0, 0, ForceMode.VelocityChange);