Back to insights

Building a Key Press Counter with ChatGPT

March 7, 20244 min read

A key press counter sounds trivial — until you start asking what the data is for, who can see it, and where the line sits between productivity tooling and surveillance. Building one with ChatGPT made both the technical setup and the ethics surprisingly concrete.

AI & Machine Learning Series — 27 articles
  1. Using ChatGPT for C# Development
  2. Trivia Spark: Building a Trivia App with ChatGPT
  3. Mastering LLM Prompt Engineering
  4. Building a Key Press Counter with ChatGPT
  5. ChatGPT Meets Jeopardy: C# Solution for Trivia Aficionados
  6. English: The New Programming Language of Choice
  7. Using Large Language Models to Generate Structured Data
  8. Prompt Spark: Revolutionizing LLM System Prompt Management
  9. Integrating Chat Completion into Prompt Spark
  10. WebSpark: Transforming Web Project Mechanics
  11. Accelerate Azure DevOps Wiki Writing
  12. The Brain Behind JShow Trivia Demo
  13. Interactive Chat in PromptSpark With SignalR
  14. Building Real-Time Chat with React and SignalR
  15. Workflow-Driven Chat Applications Powered by Adaptive Cards
  16. Understanding Neural Networks
  17. Creating a Law & Order Episode Generator
  18. The Transformative Power of MCP
  19. Computer Vision in Machine Learning
  20. Harnessing NLP: Concepts and Real-World Impact
  21. The Impact of Input Case on LLM Categorization
  22. The New Era of Individual Agency: How AI Tools Empower Self-Starters
  23. AI Observability Is No Joke
  24. Mountains of Misunderstanding: The AI Confidence Trap
  25. Measuring AI's Contribution to Code
  26. Building MuseumSpark - Why Context Matters More Than the Latest LLM
  27. Ithaka Gave You the Journey: AI-Assisted Development

Topic cluster

AI and Machine Learning

Applied AI, machine learning, and the practical limits of intelligent systems.

The Counter Was Easy. The Question Behind It Wasn't

A key press counter sounds like a harmless programming exercise. Listen for an event, increment a number, and print the result. When I asked ChatGPT to help sketch one in Python, the implementation took almost no time.

Then the more important questions arrived. What was I actually measuring? Who would see the count? Would the person using the keyboard know the listener was running? A dozen lines of code had crossed from input handling into behavior monitoring, and the difference had nothing to do with technical complexity.

That tension is what made the exercise worth revisiting. AI assistance can make a tool faster to build, but speed does not settle whether the tool should exist in a particular form.

What the Prototype Actually Does

The prototype uses Python and pynput to register a callback for each key-down event. It counts events in memory and prints the running total:

from pynput import keyboard

count = 0

def on_press(key):
    global count
    count += 1
    print(f"Total key presses: {count}")

with keyboard.Listener(on_press=on_press) as listener:
    listener.join()

The change from printing the pressed key to printing only the count is deliberate. Capturing the key value turns a counter into the beginning of a keylogger. The application does not need the content to answer the narrow question, so it should never collect it.

Even this smaller version is global: while the listener is active, it can observe keyboard events outside its own window. That may be acceptable for a personal experiment that is visible and easy to stop. It is a very different proposition on someone else's workstation.

Data Minimization Changes the Design

The first design decision is not which library to install. It is the smallest amount of data that can answer the question.

If the goal is to test whether a control receives keyboard input, an application-level event handler is usually enough. If the goal is to help someone understand their own typing habits, an opt-in counter with local-only totals may be reasonable. Neither case requires storing individual keys, timestamps, window titles, or application names.

Each additional field creates a more detailed record of behavior. It also creates another thing to explain, protect, retain, and eventually delete. That is where a tiny utility starts accumulating the responsibilities of a monitoring system.

A paragraph in a privacy policy is not meaningful consent for a background listener. The person being measured should be able to see that collection is active, understand exactly what is counted, and stop or reset it without asking an administrator.

For a responsible version of this prototype, I would expect four visible constraints:

  • collection is off by default;
  • the interface shows when the listener is active;
  • only aggregate counts are retained, preferably in memory;
  • stopping the tool stops collection immediately.

Those constraints are not polish added after the Python works. They are part of the system's behavior and should shape the implementation from the first prompt.

What ChatGPT Changed—and What It Didn't

ChatGPT reduced the friction of finding the right listener API and assembling a runnable example. That is useful, especially when working in a language or package that is not part of my daily stack.

It did not know the organizational context, the relationship between the person collecting data and the person being measured, or whether a global keyboard hook was proportionate to the problem. Those are engineering judgments. A generated implementation can reveal them, but it cannot make them on my behalf.

The lasting lesson from this small exercise is not how to count keyboard events. It is how quickly convenient code can outrun the question that justified it. The more capable the coding assistant becomes, the more deliberate I need to be about defining that question first.


References


Explore More

Working through a similar architecture decision?

If this article maps to a problem in your system, send a short note with the constraint, the risk, and what decision is blocked.