Capture: what a computer will tell you about its owner
Six signals Windows gives without a screenshot or a keyboard hook, ordered by what each costs, how the text a person typed is told from the text that was already there, and when to fall back on reading a picture.
- List the signals an operating system gives about what its user is doing, and order them by cost.
- Read the text of a window without taking a picture of it, and explain why one query beats walking the tree.
- Tell text a person typed from text that was already in the field, and from a paste.
- Say when reading a picture of a window is justified, and what it costs.
2.1The problem: learning from a screen without filming it
The obvious way to know what is on a screen is to photograph it every second and run text recognition on the pictures. It works, and it is expensive: pictures are large, recognition is slow, and a folder of screenshots is the most sensitive thing a person could keep. This chapter gets most of the same knowledge from signals the system already holds as text.
2.2Six signals, cheapest first
| Signal | How | When | Cost of one reading |
|---|---|---|---|
| Program and window in front | GetForegroundWindow, the title, the program's file name | every 2 s | 0.1 ms |
| Is the owner there | GetLastInputInfo: time since the last key or mouse movement | every 2 s | included |
| Browser address | the address bar, through the accessibility interface | when a browser's title changes | 90 ms |
| Text in the window | the accessibility interface: what a screen reader is told | once on settling, then at most every 30 s | 0.1 to 1 s |
| What is being typed | the field that has the keyboard | every 2 s while typing | 11 ms |
| Files opened | Windows' Recent list | every 60 s | 13 ms |
A stretch during which one window keeps the keyboard is stored as one record, a span, with a start and an end. After two minutes with no key or mouse movement the span is closed at the moment of the last input, and nothing is recorded until the owner returns.
2.3Reading a window's text
- Accessibility interface
- The service through which a screen reader learns what is in a window: a tree of elements (buttons, links, paragraphs), each with a type and a name. On Windows it is called UI Automation.
The first version walked that tree, asking each element for its children. Each question crosses from one program to another. On a browser window of 490 elements that took 2.1 seconds. The interface also accepts one query, "every text-bearing element under this window, with its name, already filled in", and answers it in one crossing. The same kind of window, with 1,143 elements, then took 0.8 seconds. Verified, one window each.
cond = self._ui.CreateAndCondition(self._any(P_TYPE, TEXT_TYPES),
self._ui.CreatePropertyCondition(P_PASSWORD, False))
found = el.FindAllBuildCache(DESCENDANTS, cond, self._cache(P_NAME, P_TYPE))
The condition does two jobs. It keeps only kinds of element that carry text, and it leaves password fields out of the query itself, so their contents are never asked for (Chapter 3).
Only lines not seen before in that window are stored. A page that is read every thirty seconds and has not changed writes nothing.
2.4What the owner typed
A keyboard hook would see every key, including passwords, and is how spyware works. Athena does not use one. It reads the field that has the keyboard, every two seconds while the owner is typing, and compares readings.
A reply box often starts full of someone else's words. So the piece that counts as the owner's is only what was added between the first reading and the last:
def _inserted(before: str, after: str) -> str:
"""What was put into a field between two readings: the part of `after`
between what the two share at each end."""
n = min(len(before), len(after))
a = 0
while a < n and before[a] == after[a]:
a += 1
b = 0
while b < n - a and before[-1 - b] == after[-1 - b]:
b += 1
return after[a:len(after) - b]
A piece ends when the owner leaves the field, clears it (a message sent), or stops for twenty seconds. A jump of more than 200 characters between two readings is a paste, and the piece is marked as pasted, which later means "probably somebody else's words" (Chapter 4). Pieces under fifteen characters or three words are dropped, which removes web addresses and "ok thanks". On twelve scripted cases, all twelve were attributed correctly. Verified; typing in real programs has been checked only through tests with a pretend Windows.
2.5When the window says nothing
Some windows tell the accessibility interface almost nothing: a remote desktop, a drawing canvas, some packaged web apps. For those, and only when a reading gives under 200 characters, Athena asks the window to draw itself into memory and hands the picture to the text recognition that ships with Windows. The picture is never written to disk.
On a one-megapixel window that took 1.4 seconds, 0.3 of it processor time, and returned 52 lines; two thirds of its longer words also appeared in that window's accessibility text. Verified, one window. How accurate it is on windows that have no accessibility text to compare with has not been measured.
Private browser windows were to be recognised by their title. Edge writes "[InPrivate]" in it and Firefox writes "Private Browsing". Chrome writes nothing: an Incognito window's title is the page's title. This was found by opening one. Chrome does put a button named for the mode in its toolbar, so for browsers the buttons are read as well. A Chrome Incognito window on a made-up page, held in front for eight seconds, then left no trace. Verified
- Six signals, all already text, cost between a tenth of a millisecond and a second each. No picture is kept.
- Ask the accessibility interface one question, not one per element.
- What the owner typed is what they added to a field; what was there before is not theirs, and a large jump is a paste.
- Reading a picture is a fallback for windows that say nothing, and costs about ten times a normal reading.
- The window is read every two seconds. What is lost by reading it every ten? What is gained?
_insertedreturns one stretch of text. Construct a sequence of readings in which the owner edits two separate places, and say what is returned. Is that acceptable?- Typing in a terminal is not captured as typed text. Propose a way to capture it that does not use a keyboard hook, and name its weakness.
- Extend the code: record which monitor the window was on. Which of the six signals would you add it to, and what would it cost?