import string
import random


def generate_key(key_length: int = 16, key_pattern: str = "x#x#"):
    """
    generates a unique activation key with a length and a pattern
    key_length: length of the key (default 16)
    key_pattern: set of x's and #'s in a string (default "x#x#")
    "x": random letter
    "#": random number
    """
    if key_length % len(key_pattern) == 0:
        alphabet = string.ascii_uppercase
        key = ""
        for _ in range(key_length // len(key_pattern)):
            if _ != 0:
                key += "-"
            for t in key_pattern.lower():
                if t == "x":
                    key += str(random.choice(alphabet))
                elif t == "#":
                    key += str(random.randint(0, 9))
        return key
    return False