How to set KeyCode with Number for load? C#

ok I’d like to find out if I give number 97 what KeyCode will I get not the otherway around

function that works now

public KeyCode[] keyControllKeyCode = new KeyCode [50];

void SaveData(){
	PlayerPrefs.SetInt("asdf",(int)KeyCode.A);
	
	using(var writer = new BinaryWriter(File.OpenWrite("c:/Programming/asdf.txt"))){
		writer.Write((int)KeyCode.A);
		writer.Close();
	}
}

void LoadData(){
	keyControllKeyCode[0] = (KeyCode)PlayerPrefs.GetInt("asdf");
	
	using(var reader = new BinaryReader(File.OpenRead("c:/Programming/asdf.txt"))){
	keyControllKeyCode[10] = (KeyCode)reader.ReadInt32();
	reader.Close();
	}
}

any way I would like to convert integer back in to keycode like I’m trying with KeyCode whatever

I’m kinda bad in enums and read around 7 articles and Q/A and just can’t get a grip

from all that I’ve managed in around 4 hours to get KeyCode in to int

thanks in advance

Even I have stuck with this many a times.

–

1 Answer

1

I'm saying I don't get it public KeyCode[] keyControllKeyCode = new KeyCode [50]; KeyCode keyControllKeyCode[1] = (KeyCode)97; Assets/Scripts/MainMenu.cs(237,17): error CS0650: Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type

–

To add the actual example: selectedi = (Keycode)reader.ReadInt32(); or KeyCode whatever = (KeyCode)PlayerPrefs.GetInt("asdf", (int)KeyCode.A); I've passed "A" as default value.

–

gr8 thanks Bunny83 you can change your comment to an answer as it works didn't know tho that KeyCode has to be in front of 2. example even if that was declared before

–