Repository navigation
feat(recording): show pressed keys on screen while a take is live #1633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
akahoz94
wants to merge
4
commits into
getopenscreen:main
Choose a base branch
from
akahoz94:pr/keystroke-overlay
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+789
−1
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8833736
feat(recording): show pressed keys on screen while a take is live
akahoz94 d263732
fix(keystroke): show real modifier combos and paint the overlay befor…
akahoz94 f7bac5e
fix(keystroke): capture keys in every cursor mode and harden overlay …
akahoz94 0bef5ee
fix(keystroke): own pending session teardown on Stop and block overla…
akahoz94 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import { BrowserWindow, type Rectangle } from "electron"; | ||
| import { createKeystrokeOverlayWindow } from "./windows"; | ||
|
|
||
| /** | ||
| * Lifecycle of the keystroke overlay: one window, alive only while a take is live, | ||
| * bounded to the display being recorded. The window is destroyed on hide rather than | ||
| * cached — a hidden window would otherwise linger as the app's last window and block | ||
| * quit on Windows, the same way the countdown overlay's lingering is special-cased in | ||
| * `main.ts`. A take recreates it lazily, and the first badges may land during the | ||
| * ~0.2 s the renderer needs to load: acceptable for a hint overlay. | ||
| */ | ||
| let overlayWindow: BrowserWindow | null = null; | ||
| // The first-frame wait, stored alongside the window so EVERY caller awaits it — | ||
| // including callers that receive an already-created window still mid-load. Without | ||
| // this, a second recording start could showInactive an unpainted window (#1633). | ||
| let overlayReady: Promise<void> | null = null; | ||
|
|
||
| async function ensureOverlayWindow(): Promise<BrowserWindow | null> { | ||
| if (!overlayWindow || overlayWindow.isDestroyed()) { | ||
| overlayWindow = createKeystrokeOverlayWindow(); | ||
| if (overlayWindow.isDestroyed()) { | ||
| overlayWindow = null; | ||
| return null; | ||
| } | ||
| // Wait for the first frame before showing, else Chromium flashes a black | ||
| // rectangle because it has not rendered any pixels yet. The resolve is | ||
| // idempotent and shared by all callers for this window's lifetime. | ||
| overlayReady = new Promise<void>((resolve) => { | ||
| const win = overlayWindow; | ||
| if (!win || win.isDestroyed()) { | ||
| resolve(); | ||
| return; | ||
| } | ||
| if (win.webContents.isLoading()) { | ||
| win.once("ready-to-show", resolve); | ||
| // A window destroyed before its first frame must not leave waiters | ||
| // hanging; resolve on close too, the destroyed check below then bails. | ||
| win.once("closed", resolve); | ||
| } else { | ||
| resolve(); | ||
| } | ||
| }); | ||
| } | ||
| // Capture the window we are about to wait on. A stop + start during the await | ||
| // can replace `overlayWindow`; this continuation must not then pick up the new | ||
| // window and show it with the old bounds before its own first frame (#1633). | ||
| const awaited = overlayWindow; | ||
| // Every caller, new window or reused, waits on the same readiness signal. | ||
| await overlayReady; | ||
| if (!awaited || awaited.isDestroyed() || overlayWindow !== awaited) { | ||
| // Only clear the globals if the window we waited on is still the current one; | ||
| // otherwise a replacement (with its own readiness wait) owns them. | ||
| if (overlayWindow === awaited) { | ||
| overlayWindow = null; | ||
| overlayReady = null; | ||
| } | ||
| return null; | ||
| } | ||
| return awaited; | ||
| } | ||
|
|
||
| export async function showKeystrokeOverlay(bounds: Rectangle): Promise<void> { | ||
| const win = await ensureOverlayWindow(); | ||
| if (!win || win.isDestroyed()) { | ||
| return; | ||
| } | ||
|
|
||
| win.setBounds(bounds); | ||
| if (!win.isVisible()) { | ||
| win.showInactive(); | ||
| } | ||
| } | ||
|
|
||
| export function hideKeystrokeOverlay(): void { | ||
| const win = overlayWindow; | ||
| overlayWindow = null; | ||
| overlayReady = null; | ||
| if (win && !win.isDestroyed()) { | ||
| win.destroy(); | ||
| } | ||
| } | ||
|
|
||
| /** Forwarded live keydowns (`windowsNativeRecordingSession` → `handlers`). */ | ||
| export function broadcastKeystroke(vk: number, modifiers: number): void { | ||
| const win = overlayWindow; | ||
| if (win && !win.isDestroyed() && win.isVisible()) { | ||
| win.webContents.send("keystroke-overlay-key", vk, modifiers); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capture keys independently of editable cursor telemetry.
This callback receives events only while
startCursorRecordingruns. Native Windows starts skip that function unlesscursorCaptureMode === "editable-overlay"at Line 3289. The browser path also stops the session for other cursor modes at Lines 4463–4466.A fresh take with system cursor capture therefore shows an overlay that receives no keys. Give keyboard capture its own recording lifetime, or keep its producer active without enabling editable cursor telemetry. Preserve the selected cursor mode.