Please enable JavaScript to use CodeHS

Cybersecurity · Malware

What is a keylogger?

A keylogger is software — or sometimes even a tiny physical device — that quietly records every single key you press and sends it to an attacker. No damage, no popup, no warning. Just silent watching. Learn how they get in, how to spot one, and try an interactive simulator that shows exactly what an attacker would see.

Malware ~9 min Middle School / Early High School
The Big Idea

What is a keylogger?

A keylogger is software — or, less often, a small physical device — built to secretly record every key you press on your keyboard. Its name is literally its job: it logs your keys, the way a ship's log records everything that happens on a voyage. Every letter, number, and symbol you type gets written down, then sent off to an attacker somewhere else.

That means a keylogger can capture your passwords, the messages you send friends, your credit card number when you type it into a checkout page — literally anything you type, with no idea which parts matter to you and which don't. It just records all of it.

Simple definition: a keylogger is a program (or device) that watches every keystroke you make and reports it back to whoever planted it.

You've already met other kinds of malware, and a keylogger behaves very differently from most of them. A virus spreads by attaching itself to files. Ransomware locks up or scrambles your files and demands payment. Both of those want you to notice something is wrong. A keylogger wants the opposite: it wants to stay completely invisible while it watches and reports, often without breaking anything or slowing your computer down enough for you to suspect a thing.

The pattern to remember: viruses spread, ransomware locks, keyloggers watch and report — silently, and usually without any visible damage at all.


Two Kinds

Software vs. hardware keyloggers

Most keyloggers are software — a program that gets installed on a device, usually bundled quietly alongside something else you downloaded on purpose. It runs in the background like any other program, watching what you type and sending it out over the internet.

A much rarer kind is a hardware keylogger: a tiny physical device, sometimes no bigger than a thumb drive, plugged in between a keyboard's cable and the computer it connects to. It doesn't need to install anything or trick any software — it just sits in the middle of the wire, quietly copying every signal your keyboard sends before passing it along to the computer like normal. Because it never touches the software on the computer at all, antivirus programs can't find it. The only way to catch one is to physically look at the cable.

Why this matters: a hardware keylogger is invisible to every scan and every piece of security software, because it isn't software. It's a real object plugged into a real cable — which is exactly why it shows up later in this tutorial as something worth physically checking for on shared computers.


Delivery

How attackers plant one

A keylogger almost never appears on its own. Like most malware, it needs a way in — usually one of these:

  • Phishing emails and attachments. An email disguised as something normal — an invoice, a shared document, a school notice — hides the keylogger inside its attachment or a link. This is one of the most common ways keyloggers spread; see Don't Fall for a Phishing Email for how to spot these before you click.
  • Fake "free" downloads. A cracked game, a "free" version of paid software, or a sketchy browser extension installs the keylogger silently alongside whatever you thought you were getting.
  • Infected USB drives. A USB stick — found, borrowed, or handed to you — can run a keylogger automatically the moment it's plugged in.
  • Physical access (rarer). Someone with a few unsupervised minutes at a shared or public computer can plug in a small hardware keylogger by hand, or quietly install the software version themselves.

Notice the pattern: almost every delivery method depends on you (or someone else) doing one small, ordinary-seeming thing — opening a file, installing a "free" program, plugging something in. That one small action is the entire attack.


The Scary Part

What it actually sees — and sends

Once a keylogger is running, here's concretely what it can gather: every single keystroke you type, in order. Some keyloggers go further and also grab whatever you copy to your clipboard, or take periodic screenshots of your screen. All of that gets bundled up and sent to a server the attacker controls — usually on a timer, every few minutes or hours, not the instant you type it.

Why this is the scary part: there is usually no popup, no error message, and no noticeable slowdown. Your device can look and feel completely normal while a keylogger sits in the background, quietly building a complete transcript of your passwords, your private messages, and anything else you ever typed — and mailing it off piece by piece.


Stay Alert

Warning signs to actually check

A keylogger tries hard to hide, but it isn't perfect. Here's what to actually look for — not vague "something feels off," but specific things you can check:

Noticeable typing lag

Letters appear on screen a beat after you press the key, even in simple apps like a text editor.

An unfamiliar running process

Your device's task or activity manager shows a program running that you don't recognize and never opened.

A new browser toolbar or extension

Something got added to your browser that you never installed — a common side effect of a bundled install.

Camera or microphone indicator lights up

Your device shows "an app is using your camera/microphone" or the little camera light turns on, but you haven't opened anything that should need it.

Logins you didn't make

An account shows a sign-in from a device or location you don't recognize — a sign a captured password is already being used.

None of these prove it alone — a slow computer can just be old, and a strange login could be you forgetting a device. But two or three of these together is worth investigating, not ignoring.


Stay Safe

Real defenses

No single habit stops every keylogger, but together these make a real difference:

Keep software updated. Updates patch the exact security holes attackers use to sneak a keylogger onto a device in the first place. An out-of-date app or operating system is an open door.

Use antivirus / antimalware software. It scans for known keyloggers and can catch one before it starts recording — though it can't catch a hardware keylogger, since that isn't software at all.

Avoid cracked or pirated software. "Free" versions of paid programs are one of the most common places attackers hide keyloggers, because you already expect the install to feel a little unofficial.

Use a password manager and multi-factor authentication. Autofill isn't typed character by character, so a basic keylogger records far less useful data — and even if a password does get captured, MFA means it isn't enough on its own to log in.

Physically check shared or public computers. Before typing anything sensitive on a library, school, or hotel-business-center computer, glance at the cable between the keyboard and the computer for any small unfamiliar device plugged in between them.

Key idea: these defenses work in layers. No single one is perfect alone — antivirus misses hardware keyloggers, updates don't stop a pirated download, and a password manager doesn't fix an already-infected device. Stack several layers, and a keylogger has to get past all of them, not just one.


Interactive

Keylogger simulator

Type a fake "password" into the box on the left. Watch the panel on the right — that's what an attacker's keylogger would see, revealed key by key as you type. Notice what happens if you delete something: the deletion shows up in the log too. Clearing the box doesn't erase what you typed from the attacker's record.

You type here

Try typing a fake password, then delete a few characters, then hit "Clear field."

Attacker's log

This is what gets recorded and sent — whether or not you ever hit submit.

This is a purely visual demo that runs entirely in your browser. Nothing you type here is ever sent anywhere or stored anywhere — it only appears in the log panel above, for as long as this page stays open.


Your Turn

Check yourself

1. A friend says, "I have antivirus installed, so I don't need to worry about keyloggers." What would you tell them?

Sample answer: Antivirus helps catch known software keyloggers, but it can't detect a hardware keylogger plugged into a cable, and it can't catch a brand-new keylogger it doesn't recognize yet. I'd tell them to also keep software updated, avoid pirated downloads, and use a password manager with multi-factor authentication, since defenses work best stacked together.

2. You need to log into your email on a library computer. What could you check or do before typing your password?

Sample answer: I would glance at the cable running from the keyboard to the computer to check for any small unfamiliar device plugged in between them. I'd also make sure multi-factor authentication is turned on for the account, so even if a keylogger did capture the password, it wouldn't be enough on its own to log in.


Check Yourself

Quick quiz

1. What makes a keylogger different from malware like a virus or ransomware?

2. Which of these is a real warning sign of a possible keylogger?

3. Why does using a password manager and multi-factor authentication together help defend against keyloggers?

Keep learning about modern scams and cyber threats

A keylogger works by watching quietly, but plenty of attacks work by tricking you directly instead. If you want a refresher first, revisit What Is Malware? or lock down your accounts with a password manager. Otherwise, keep going with the next tutorial in this series, where texts and phone calls become the attack.

Part of the “Modern Scams and Cyber Threats” tutorial series from CodeHS.