The easiest way for your customer to activate a key is to provide them with a simple form seamlessly inside your app. Your customer pastes in their key and with the press of a single button their key is activated. You can add Additional fields to the form if you wish and process the information however you wish.
Read more about form best practices from an end user’s point of view.
Example Forms #
To achieve a seamless integration we recommend creating a basic form styled to match your app. You can use any language to create a form, many of which have built in support for basic forms. All have easy to install libraries that provide form functionality.
Here are some examples in various programming languages.
NOTE: In the below examples we’ve left the handling of inputs up to you. For information about other critical steps, like making API calls, or getting domain names, or generating UUIDs and then sending those UUIDs, please see our other documentation.
HTML Forms #
For web apps, apps installed on a live web server, and apps that are part of a website (e.g. plugin, theme) a simple html form is all you need. This can include PHP, JavaScript, and more.
<!DOCTYPE html>
<html>
<body>
<form action="" method="post">
<input type="text" id="licenseKey" name="licenseKey" placeholder="Enter license key..." required>
<input type="submit" value="Submit">
</form>
</body>
</html>
If your app is written in PHP, or can utilize PHP, then we have a working sample available that will work for most situations.
Other Forms #
If your app is written in languages that cannot use html, you can still create forms using built in functions or libraries made specifically for your programming language.
Python #
In Python, you can create a GUI application that acts as a form input field. One popular choice is Tkinter, which is included with standard Python installations. Here’s an example.
import tkinter as tk
from tkinter import messagebox
def submit_license_key():
license_key = entry_license_key.get()
# Here you can add the code to check the license key or send it to an API
messagebox.showinfo("License Key", f"Entered License Key: {license_key}")
# Create the main window
root = tk.Tk()
root.title("License Key Form")
# Create a frame to hold the form widgets
frame = tk.Frame(root)
frame.pack(padx=10, pady=10)
# Create the entry widget for the license key
label_license_key = tk.Label(frame, text="Enter license key:")
label_license_key.grid(row=0, column=0, sticky="w")
entry_license_key = tk.Entry(frame)
entry_license_key.grid(row=0, column=1)
# Create the submit button
button_submit = tk.Button(frame, text="Submit", command=submit_license_key)
button_submit.grid(row=1, column=1, sticky="e")
# Start the Tkinter event loop
root.mainloop()
C #
This example uses GTK to create a window with a grid layout, containing a label, a text entry for the license key, and a submit button. You can modify this function to add your license key checking or API communication logic.
#include <gtk/gtk.h>
static void on_submit_button_clicked(GtkWidget *widget, gpointer data) {
GtkEntry *entry = GTK_ENTRY(data);
const gchar *license_key = gtk_entry_get_text(entry);
g_print("Entered License Key: %s\n", license_key);
// Here you can add the code to check the license key or send it to an API
}
int main(int argc, char *argv[]) {
GtkWidget *window;
GtkWidget *grid;
GtkWidget *label;
GtkWidget *entry;
GtkWidget *button;
gtk_init(&argc, &argv);
// Create the main window
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "License Key Form");
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
// Create a grid to hold the form widgets
grid = gtk_grid_new();
gtk_container_add(GTK_CONTAINER(window), grid);
// Create the entry widget for the license key
label = gtk_label_new("Enter license key:");
gtk_grid_attach(GTK_GRID(grid), label, 0, 0, 1, 1);
entry = gtk_entry_new();
gtk_grid_attach(GTK_GRID(grid), entry, 1, 0, 1, 1);
// Create the submit button
button = gtk_button_new_with_label("Submit");
g_signal_connect(button, "clicked", G_CALLBACK(on_submit_button_clicked), entry);
gtk_grid_attach(GTK_GRID(grid), button, 1, 1, 1, 1);
// Show the window
gtk_widget_show_all(window);
gtk_main();
return 0;
}
C++ #
This code creates a simple window with a form that includes a label, a line edit for entering the license key, and a submit button.
#include <QApplication>
#include <QWidget>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QMessageBox>
class LicenseKeyForm : public QWidget {
public:
LicenseKeyForm(QWidget *parent = nullptr) : QWidget(parent) {
auto *layout = new QVBoxLayout(this);
auto *label = new QLabel("Enter license key:");
layout->addWidget(label);
lineEdit = new QLineEdit;
layout->addWidget(lineEdit);
auto *button = new QPushButton("Submit");
connect(button, &QPushButton::clicked, this, &LicenseKeyForm::submitLicenseKey);
layout->addWidget(button);
}
private slots:
void submitLicenseKey() {
QString licenseKey = lineEdit->text();
// Here you can add the code to check the license key or send it to an API
QMessageBox::information(this, "License Key", "Entered License Key: " + licenseKey);
}
private:
QLineEdit *lineEdit;
};
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
LicenseKeyForm form;
form.setWindowTitle("License Key Form");
form.show();
return app.exec();
}
C# #
This code creates a simple window with a form that includes a text box for entering the license key and a submit button.
using System;
using System.Windows.Forms;
public class LicenseKeyForm : Form
{
private TextBox textBoxLicenseKey;
private Button buttonSubmit;
public LicenseKeyForm()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.textBoxLicenseKey = new TextBox();
this.buttonSubmit = new Button();
// TextBox for license key
this.textBoxLicenseKey.Location = new System.Drawing.Point(15, 25);
this.textBoxLicenseKey.Name = "textBoxLicenseKey";
this.textBoxLicenseKey.Size = new System.Drawing.Size(200, 20);
this.textBoxLicenseKey.TabIndex = 0;
this.textBoxLicenseKey.PlaceholderText = "Enter license key...";
// Submit button
this.buttonSubmit.Location = new System.Drawing.Point(15, 60);
this.buttonSubmit.Name = "buttonSubmit";
this.buttonSubmit.Size = new System.Drawing.Size(75, 23);
this.buttonSubmit.TabIndex = 1;
this.buttonSubmit.Text = "Submit";
this.buttonSubmit.UseVisualStyleBackColor = true;
this.buttonSubmit.Click += new EventHandler(this.buttonSubmit_Click);
// LicenseKeyForm
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(234, 101);
this.Controls.Add(this.buttonSubmit);
this.Controls.Add(this.textBoxLicenseKey);
this.Name = "LicenseKeyForm";
this.Text = "License Key Form";
}
private void buttonSubmit_Click(object sender, EventArgs e)
{
string licenseKey = textBoxLicenseKey.Text;
// Here you can add the code to check the license key or send it to an API
MessageBox.Show("Entered License Key: " + licenseKey, "License Key");
}
}
class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new LicenseKeyForm());
}
}
Java #
This code creates a simple window with a form that includes a text field for entering the license key and a submit button. You can modify this method to add the logic for checking the license key or sending it to an API.
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class LicenseKeyForm {
private JTextField textFieldLicenseKey;
private JButton buttonSubmit;
private JPanel panelMain;
public LicenseKeyForm() {
buttonSubmit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String licenseKey = textFieldLicenseKey.getText();
// Here you can add the code to check the license key or send it to an API
JOptionPane.showMessageDialog(null, "Entered License Key: " + licenseKey, "License Key", JOptionPane.INFORMATION_MESSAGE);
}
});
}
public static void main(String[] args) {
JFrame frame = new JFrame("License Key Form");
frame.setContentPane(new LicenseKeyForm().panelMain);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
Creating Forms In Game Engines #
If you’re making API calls from a game engine, try these steps…
Unreal Engine #
In Unreal Engine, you can create a form for entering a license key using UMG (Unreal Motion Graphics), which is Unreal Engine’s UI designer tool. Here’s a basic outline of how you can set up a license key entry form in Unreal Engine:
- Create a Widget Blueprint:
- Open the Unreal Engine Editor and go to the Content Browser.
- Right-click in the Content Browser and select “User Interface” > “Widget Blueprint” to create a new Widget Blueprint.
- Name the Widget Blueprint something like “LicenseKeyEntryWidget”.
- Design the Form:
- Open the LicenseKeyEntryWidget Blueprint.
- Use the Palette panel to drag and drop UI elements onto the canvas. For a simple license key form, you might want:
- A “Text Block” to display a label like “Enter License Key:”
- An “Editable Text” or “Editable Text Box” for the user to enter their license key.
- A “Button” for the user to submit their license key.
- Set Up the Logic:
- Go to the Graph section of the Widget Blueprint.
- Create a new function or event that will be triggered when the user clicks the submit button. You can do this by right-clicking on the button in the Designer view and selecting “Create Event” > “OnClicked”.
- In the function or event graph, you can add the logic to check the entered license key or send it to an API. You might need to create custom C++ classes or Blueprints to handle the license key validation.
- Display the Form in the Game:
- In your game’s level or main menu, you can create an instance of the LicenseKeyEntryWidget and add it to the viewport. This can be done in a Level Blueprint or in a custom Game Mode or Player Controller Blueprint.
- Use the “Create Widget” node to create an instance of your LicenseKeyEntryWidget.
- Use the “Add to Viewport” node to display the widget on the screen.
Here’s an example of how you might set up the logic in the Widget Blueprint to handle the button click event:
// This is a simple example of what you might do in the button's OnClicked event.
FString LicenseKey = LicenseKeyTextBox->GetText().ToString();
// Here you would add your logic to check the license key or send it to an API.
// For example, you could call a custom C++ function or Blueprint that validates the license key.
if (IsValidLicenseKey(LicenseKey))
{
// License key is valid, proceed with the game.
}
else
{
// License key is invalid, display an error message.
}
Unity Game Engine #
In Unity, you can create a form for entering a license key using the built-in UI system. Here’s a basic outline of how you can set up a license key entry form in Unity:
- Create a Canvas:
- In the Unity Editor, go to the Hierarchy window, right-click, and select “UI” > “Canvas” to create a new Canvas. This will be the container for your UI elements.
- Design the Form:
- Right-click on the Canvas in the Hierarchy window and select “UI” > “Text” to create a Text element for the label “Enter License Key:”.
- Right-click on the Canvas again and select “UI” > “Input Field” to create an input field where the user can enter their license key.
- Right-click on the Canvas once more and select “UI” > “Button” to create a submit button for the form.
- Set Up the Logic:
- Create a new C# script to handle the logic for your form. You can name this script something like “LicenseKeyForm”.
- Attach the script to an empty GameObject in your scene, or to the Canvas itself.
- In the script, you will need to reference the Input Field and the Button. You can do this by creating public variables for them and then dragging the corresponding UI elements from the Hierarchy window to these variables in the Inspector.
- Create a method in the script that will be called when the submit button is clicked. In this method, you can add the logic to check the entered license key or send it to an API.
- Hook Up the Button Event:
- Select the Button in the Hierarchy window.
- In the Inspector, find the “Button (Script)” component, and look for the “On Click ()” event.
- Click the “+” button to add a new event listener.
- Drag the GameObject with the “LicenseKeyForm” script attached to it into the field that appears.
- Select the method you created for handling the button click from the dropdown menu.
Here’s an example of what the C# script might look like:
using UnityEngine;
using UnityEngine.UI;
public class LicenseKeyForm : MonoBehaviour
{
public InputField licenseKeyInputField;
public Button submitButton;
void Start()
{
submitButton.onClick.AddListener(SubmitLicenseKey);
}
void SubmitLicenseKey()
{
string licenseKey = licenseKeyInputField.text;
// Here you can add the code to check the license key or send it to an API
Debug.Log("Entered License Key: " + licenseKey);
}
}
Godot Engine #
In Godot, you can create a form for entering a license key using the built-in Control nodes. Here’s a basic outline of how you can set up a license key entry form in Godot:
- Create a New Scene:
- In the Godot Editor, create a new scene by clicking on “Scene” > “New Scene”.
- Add a “Control” node as the root node of the scene. This will be the container for your UI elements.
- Design the Form:
- Right-click on the Control node and add a “Label” node. Set its “Text” property to “Enter License Key:”.
- Right-click on the Control node again and add a “LineEdit” node. This will be the input field where the user can enter their license key.
- Right-click on the Control node once more and add a “Button” node. Set its “Text” property to “Submit”. This will be the submit button for the form.
- Set Up the Script:
- Attach a new GDScript to the Control node by selecting the Control node, clicking on the “Script” tab, and clicking “New Script”. You can name the script something like “LicenseKeyForm.gd”.
- In the script, you can access the LineEdit and Button nodes and connect the button’s “pressed” signal to a function that will handle the license key submission.
Here’s an example of what the GDScript might look like:
extends Control
onready var license_key_input = $LineEdit
onready var submit_button = $Button
func _ready():
submit_button.connect("pressed", self, "_on_submit_button_pressed")
func _on_submit_button_pressed():
var license_key = license_key_input.text
# Here you can add the code to check the license key or send it to an API
print("Entered License Key: " + license_key)