Pyautogui and pynput help

import pyautogui, sys
import pynput
import time

from pynput.keyboard import Key, Controller
keyboard = Controller

time.sleep(5)
pyautogui.drag(30, 0, 300)

I want to make that if you press f12 the code stops. Please help