Changing input key with variable

I want to make a JavaScript so that i can use a variable as the key in
Input.GetKeyDown(KeyCode.stringVariableHere)

I tried to use my code below but i only got the error message “Input key named: is unknown”

So would it be possible to use a variable as an input key?

`
var raiseGunKey : String;

function Update(){
if (Input.GetKeyDown(KeyCode.raiseGunKey) && reloading == false){
Debug.Log(“Key working!”);
}
`

No you cannot do that.

But you can do what you are trying to do.

You do it by declaring an axis as a key/joystick button axis in edit->Project Settings->Input.

Then you read it with Input.GetAxis()

You can change what key is bound to that axis be default in the edit->Project Settings->Input, and the user can redefine
it at runtime with options.

You could do like this:

var raiseGunKey : KeyCode;

if(Input.GetKey(raiseGunKey))
{
//Raise gun function here
}