Help with unity UI script

Hi All…

OK so im probably being a nube here but im having an issue with the unity UI. All I want it to do is when I press the UI Button, it acts as a keycode... I should warn you im pretty usless at scripting!!!
i.e when I press the button it acts as keycode “escape”
This is the script I was using but it doesn’t work :

using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(Button))]
public class KeyButton : MonoBehaviour {

public KeyCode key;

public Button button {get; private set;}

Graphic targetGraphic;
Color normalColor;

void Awake() {
button = GetComponent();
button.interactable = false;
targetGraphic = GetComponent();

ColorBlock cb = button.colors;
cb.disabledColor = cb.normalColor;
button.colors = cb;
}

void Start() {
button.targetGraphic = null;
Up();
}

// Update is called once per frame
void Update () {
if (Input.GetKeyDown(key)) {
Down();
} else if (Input.GetKeyUp(key)) {
Up();
}
}

void Up() {
StartColorTween(button.colors.normalColor, false);
}

void Down() {
StartColorTween(button.colors.pressedColor, false);
button.onClick.Invoke();
}

void StartColorTween(Color targetColor, bool instant) {
if (targetGraphic == null)
return;

targetGraphic.CrossFadeColor(targetColor, instant ? 0f : button.colors.fadeDuration, true, true);
}

void OnApplicationFocus(bool focus) {
Up();
}

public void LogOnClick() {
Debug.Log ("LogOnClick() - " + GetComponentInChildren().text);
}
}

Thanks in advance

Please use code tags when posting code

EDIT: Fixed that for you

using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(Button))]
public class KeyButton : MonoBehaviour {

public KeyCode key;

public Button button {get; private set;}

Graphic targetGraphic;
Color normalColor;

void Awake() {
button = GetComponent<Button>();
button.interactable = false;
targetGraphic = GetComponent<Graphic>();

ColorBlock cb = button.colors;
cb.disabledColor = cb.normalColor;
button.colors = cb;
}

void Start() {
button.targetGraphic = null;
Up();
}

// Update is called once per frame
void Update () {
if (Input.GetKeyDown(key)) {
Down();
} else if (Input.GetKeyUp(key)) {
Up();
}
}

void Up() {
StartColorTween(button.colors.normalColor, false);
}

void Down() {
StartColorTween(button.colors.pressedColor, false);
button.onClick.Invoke();
}

void StartColorTween(Color targetColor, bool instant) {
if (targetGraphic == null)
return;

targetGraphic.CrossFadeColor(targetColor, instant ? 0f : button.colors.fadeDuration, true, true);
}

void OnApplicationFocus(bool focus) {
Up();
}

public void LogOnClick() {
Debug.Log ("LogOnClick() - " + GetComponentInChildren<Text>().text);
}
}

Sorry that was my first post!!!