# giacomolaw/keylogger architecture

> Architecture diagram of the GitHub repository giacomolaw/keylogger, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/giacomolaw/keylogger
- Repository: https://github.com/giacomolaw/keylogger

## Overview

This repository contains three independent, platform-specific key-recording programs rather than a shared cross-platform runtime. In each, the principal workflow is startup, capture of keyboard events, conversion or formatting, and writing to a local log. Windows also records foreground-window context and rotates log files; macOS exposes a configurable log path and clear option; Linux uses pyxhook and writes a timestamped log. The source excerpts support these platform-specific flows; the macOS header declares interfaces and globals, while the Linux requirements file identifies the pyxhook dependency.

Main entry points: [`linux/keylogger.py`](https://github.com/giacomolaw/keylogger/blob/master/linux/keylogger.py) (Logger runtime), [`windows/klog_main.cpp`](https://github.com/giacomolaw/keylogger/blob/master/windows/klog_main.cpp) (Key formatting), [`mac/keylogger.c`](https://github.com/giacomolaw/keylogger/blob/master/mac/keylogger.c) (Logger runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_windows["Windows logger"]
  node_win_runtime["Logger runtime<br/>[klog_main.cpp]"]
  node_win_hook["Keyboard hook<br/>[klog_main.cpp]"]
  node_win_format["Key formatting<br/>[klog_main.cpp]"]
  node_win_context["Window context<br/>[klog_main.cpp]"]
  node_win_log[("Local log files<br/>[klog_main.cpp]")]
end

subgraph group_macos["macOS logger"]
  node_mac_runtime["Logger runtime<br/>[keylogger.c]"]
  node_mac_tap["Event tap<br/>[keylogger.c]"]
  node_mac_format["Key conversion<br/>[keylogger.c]"]
  node_mac_log[("Local log<br/>[keylogger.c]")]
end

subgraph group_linux["Linux logger"]
  node_linux_runtime["Logger runtime<br/>[keylogger.py]"]
  node_linux_hook["Hook manager<br/>[keylogger.py]"]
  node_linux_log[("Timestamped log<br/>[keylogger.py]")]
end

node_operator(("Operator"))
node_pyxhook["pyxhook library"]

node_operator -->|"runs"| node_win_runtime
node_operator -->|"runs"| node_mac_runtime
node_operator -->|"runs"| node_linux_runtime
node_win_runtime -->|"installs hook"| node_win_hook
node_win_hook -->|"passes key"| node_win_format
node_win_format -->|"adds context"| node_win_context
node_win_format -->|"writes entries"| node_win_log
node_mac_runtime -->|"creates tap"| node_mac_tap
node_mac_tap -->|"passes keycode"| node_mac_format
node_mac_format -->|"writes key text"| node_mac_log
node_linux_runtime -->|"configures listener"| node_linux_hook
node_linux_runtime -->|"uses library"| node_pyxhook
node_linux_hook -->|"delivers events"| node_linux_runtime
node_linux_runtime -->|"appends keystrokes"| node_linux_log

click node_win_runtime "https://github.com/giacomolaw/keylogger/blob/master/windows/klog_main.cpp"
click node_win_hook "https://github.com/giacomolaw/keylogger/blob/master/windows/klog_main.cpp"
click node_win_format "https://github.com/giacomolaw/keylogger/blob/master/windows/klog_main.cpp"
click node_win_context "https://github.com/giacomolaw/keylogger/blob/master/windows/klog_main.cpp"
click node_win_log "https://github.com/giacomolaw/keylogger/blob/master/windows/klog_main.cpp"
click node_mac_runtime "https://github.com/giacomolaw/keylogger/blob/master/mac/keylogger.c"
click node_mac_tap "https://github.com/giacomolaw/keylogger/blob/master/mac/keylogger.c"
click node_mac_format "https://github.com/giacomolaw/keylogger/blob/master/mac/keylogger.c"
click node_mac_log "https://github.com/giacomolaw/keylogger/blob/master/mac/keylogger.c"
click node_linux_runtime "https://github.com/giacomolaw/keylogger/blob/master/linux/keylogger.py"
click node_linux_hook "https://github.com/giacomolaw/keylogger/blob/master/linux/keylogger.py"
click node_linux_log "https://github.com/giacomolaw/keylogger/blob/master/linux/keylogger.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_win_runtime,node_win_hook,node_win_format,node_win_context,node_win_log toneBlue
class node_mac_runtime,node_mac_tap,node_mac_format,node_mac_log toneAmber
class node_linux_runtime,node_linux_hook,node_linux_log toneMint
class node_operator,node_pyxhook toneIndigo
```

## Components

### Windows logger

- [Logger runtime](https://github.com/giacomolaw/keylogger/blob/master/windows/klog_main.cpp): `windows/klog_main.cpp`
- [Keyboard hook](https://github.com/giacomolaw/keylogger/blob/master/windows/klog_main.cpp): `windows/klog_main.cpp`
- [Key formatting](https://github.com/giacomolaw/keylogger/blob/master/windows/klog_main.cpp): `windows/klog_main.cpp`
- [Window context](https://github.com/giacomolaw/keylogger/blob/master/windows/klog_main.cpp): `windows/klog_main.cpp`
- [Local log files](https://github.com/giacomolaw/keylogger/blob/master/windows/klog_main.cpp): `windows/klog_main.cpp`

### macOS logger

- [Logger runtime](https://github.com/giacomolaw/keylogger/blob/master/mac/keylogger.c): `mac/keylogger.c`
- [Event tap](https://github.com/giacomolaw/keylogger/blob/master/mac/keylogger.c): `mac/keylogger.c`
- [Key conversion](https://github.com/giacomolaw/keylogger/blob/master/mac/keylogger.c): `mac/keylogger.c`
- [Local log](https://github.com/giacomolaw/keylogger/blob/master/mac/keylogger.c): `mac/keylogger.c`

### Linux logger

- [Logger runtime](https://github.com/giacomolaw/keylogger/blob/master/linux/keylogger.py): `linux/keylogger.py`
- [Hook manager](https://github.com/giacomolaw/keylogger/blob/master/linux/keylogger.py): `linux/keylogger.py`
- [Timestamped log](https://github.com/giacomolaw/keylogger/blob/master/linux/keylogger.py): `linux/keylogger.py`

### Other components

- **Operator**
- **pyxhook library**

## Connections

- Operator → Logger runtime: runs (evidence: `README.md`)
- Operator → Logger runtime: runs (evidence: `README.md`)
- Operator → Logger runtime: runs (evidence: `README.md`)
- Logger runtime → Keyboard hook: installs hook (evidence: `windows/klog_main.cpp`)
- Keyboard hook → Key formatting: passes key (evidence: `windows/klog_main.cpp`)
- Key formatting → Window context: adds context (evidence: `windows/klog_main.cpp`)
- Key formatting → Local log files: writes entries (evidence: `windows/klog_main.cpp`)
- Logger runtime → Event tap: creates tap (evidence: `mac/keylogger.c`)
- Event tap → Key conversion: passes keycode (evidence: `mac/keylogger.c`)
- Key conversion → Local log: writes key text (evidence: `mac/keylogger.c`)
- Logger runtime → Hook manager: configures listener (evidence: `linux/keylogger.py`)
- Logger runtime → pyxhook library: uses library (evidence: `linux/keylogger.py`)
- Hook manager → Logger runtime: delivers events (evidence: `linux/keylogger.py`)
- Logger runtime → Timestamped log: appends keystrokes (evidence: `linux/keylogger.py`)
