Key Wall
An endless wall of backlit mechanical keycaps. Staggered rows of dark keys (letters, dual-legend number and symbol keys, and wide modifiers like shift, tab and control) each have a sculpted top, a thin edge and soft grey legends. It is a real keyboard for your page: when a visitor types anywhere on the site, every matching key on the wall presses down and lights up. Your cursor is the backlight, so keys under it press in and glow through their legends and edges in a slowly shifting gradient of cobalt, violet and ember. A click sends a ripple of key presses outward like a keyboard lighting effect, scrolling slides alternate rows apart, keys ghost-type here and there so it is never still, and on load the backlight boots up row by row.
Tweak
LIVELIVEColour
Keys
Types with you
Every key you press on the page lights up on the wall
Motion
Interactive
Cursor backlight, click for a ripple of key presses
Usage
Follows your tweaks.
import { KeyWall } from "@/components/inreact/key-wall";
export function Hero() {
return (
<KeyWall
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the wall */}
</KeyWall>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/key-wall.jsonOr copy the source
Install the dependencies, then save this as components/inreact/key-wall.tsx.
npm install gsap"use client";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { useEffect, useRef, type ReactNode } from "react";
gsap.registerPlugin(ScrollTrigger);
/**
* Key Wall: an endless wall of backlit mechanical keycaps that types with you.
*
* Staggered rows of dark keycaps (letters, dual-legend number and symbol keys,
* and wide modifiers like shift, tab and control), each with a sculpted top,
* a thin edge and soft grey legends. It is a real keyboard for the page: when
* a visitor types anywhere on the site, every matching key on the wall presses
* down and lights up in the backlight colours.
*
* It reacts: your cursor is the backlight. Keys under it press in and glow
* through their legends and edges, in a slowly shifting RGB gradient. A click
* sends a ripple of key presses outward, like a keyboard lighting effect.
* Scrolling slides alternate rows past each other. Keys are ghost-typed here
* and there so it is never still, and on load the backlight boots up row by
* row.
*
* <KeyWall className="h-screen w-full">
* <YourHero />
* </KeyWall>
*
* WebGL2: one shader draws every keycap as a distance field with legends from
* a canvas atlas, then a bloom at 1/4 and 1/16 size. GSAP drives every motion.
* Pauses off-screen; reduced motion shows a still frame; a CSS gradient
* without WebGL2.
*/
export interface KeyWallProps {
/** Colour of the resting legends. */
legend?: string;
/** Colour of the keycap edges. */
edge?: string;
/** The three backlight colours. */
colors?: [string, string, string];
/** Background colour. */
background?: string;
/** Key size in px (scaled down on small screens). */
size?: number;
/** Light up keys when visitors type on the page. */
typing?: boolean;
/** Calms the centre so a headline on top stays readable, 0 to 1. */
focus?: number;
/** Speed of the backlight drift and ghost typing. */
speed?: number;
/** Strength of the bloom on lit keys. */
glow?: number;
/** Cursor backlight, click ripple, scroll response. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the wall. */
children?: ReactNode;
className?: string;
}
// ---- legends: what is printed on each key ----
const LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
const PAIRS = [
["!", "1"], ["@", "2"], ["#", "3"], ["$", "4"], ["%", "5"], ["^", "6"], ["&", "7"], ["*", "8"], ["(", "9"], [")", "0"],
["~", "`"], ["_", "-"], ["+", "="], ["{", "["], ["}", "]"], ["|", "\\"], [":", ";"], ["“", "'"], ["<", ","], [">", "."], ["?", "/"],
];
const MODS = [
{ label: "tab", key: "Tab", w: 1.5 },
{ label: "shift", key: "Shift", w: 2.25 },
{ label: "control", key: "Control", w: 1.75 },
{ label: "option", key: "Alt", w: 1.25 },
{ label: "command", key: "Meta", w: 1.5 },
{ label: "return", key: "Enter", w: 2 },
{ label: "delete", key: "Backspace", w: 1.5 },
{ label: "caps lock", key: "CapsLock", w: 1.75 },
{ label: "esc", key: "Escape", w: 1 },
{ label: "", key: " ", w: 4 },
];
const L_PAIR = LETTERS.length;
const L_MOD = L_PAIR + PAIRS.length;
const LEGENDS = L_MOD + MODS.length; // 57
const ATLAS_N = 8;
const CELL = 128;
const PATTERNS = 8; // distinct row layouts
const PKEYS = 16; // keys per row layout
const PERIOD = 15; // row layout width in key units
const MAXW = 4;
const QUAD = `#version 300 es
in vec2 aQ; out vec2 vUv;
void main(){ vUv = aQ * 0.5 + 0.5; gl_Position = vec4(aQ, 0.0, 1.0); }`;
const SCENE = `#version 300 es
precision highp float;
uniform vec2 uRes, uMouse; // css px, top-left origin
uniform float uDpr, uTime, uU, uSlide, uScrollY, uHover, uIntro, uFocus, uFlow;
uniform vec3 uLegend, uEdge, uA, uB, uC, uBg;
uniform float uPress[${LEGENDS}];
uniform vec4 uWave[${MAXW}];
uniform sampler2D uAtlas;
uniform highp sampler2D uRows; // x0, width, legend, - per key, one row per layout
in vec2 vUv;
out vec4 o;
float h11(float n) { return fract(sin(n * 127.1) * 43758.5453); }
float h21(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
vec3 pal(float t) {
t = fract(t) * 3.0;
return t < 1.0 ? mix(uA, uB, t) : t < 2.0 ? mix(uB, uC, t - 1.0) : mix(uC, uA, t - 2.0);
}
float rbox(vec2 p, vec2 b, float r) {
vec2 q = abs(p) - b + r;
return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - r;
}
void main() {
vec2 p = vec2(gl_FragCoord.x, uRes.y * uDpr - gl_FragCoord.y) / uDpr;
float U = uU;
float y = p.y + uScrollY;
float row = floor(y / U);
float pat = mod(row, ${PATTERNS}.0);
// every row starts somewhere different; scrolling slides alternate rows apart
float dir = mod(row, 2.0) * 2.0 - 1.0;
float shift = h11(row + 3.7) * ${PERIOD}.0 + uSlide * dir * (0.6 + 0.4 * h11(row));
float xu = p.x / U + shift;
float rep = floor(xu / ${PERIOD}.0);
float xm = xu - rep * ${PERIOD}.0;
vec4 K = vec4(0.0);
for (int k = 0; k < ${PKEYS}; k++) {
vec4 v = texelFetch(uRows, ivec2(k, int(pat)), 0);
if (v.y > 0.0 && xm >= v.x && xm < v.x + v.y) { K = v; break; }
}
vec3 col = uBg;
if (K.y > 0.0) {
float legend = K.z;
vec2 kc = vec2((K.x + K.y * 0.5 + rep * ${PERIOD}.0 - shift) * U, (row + 0.5) * U - uScrollY); // key centre, screen
vec2 lp = vec2((xm - K.x - K.y * 0.5) * U, (fract(y / U) - 0.5) * U); // pixel relative to key centre
float id = rep * 131.0 + K.x * 7.0 + row * 17.0;
// how pressed and how lit this key is
vec2 dm = kc - uMouse;
float cur = exp(-dot(dm, dm) / (U * U * 3.2)) * uHover;
float halo = exp(-dot(dm, dm) / (U * U * 18.0)) * uHover;
float wave = 0.0;
for (int i = 0; i < ${MAXW}; i++) {
vec4 W = uWave[i];
if (W.w <= 0.0) continue;
float age = uTime - W.z;
if (age < 0.0 || age > 2.6) continue;
float r = length(kc - W.xy);
wave = max(wave, exp(-pow((r - age * 640.0) / (U * 0.9), 2.0)) * exp(-age * 1.1) * W.w);
}
float typed = uPress[int(legend)];
// ghost typing: a key here and there taps itself
float slot = uFlow * 2.2 + h11(id) * 7.0;
float ghost = step(0.975, h21(vec2(id, floor(slot)))) * pow(1.0 - fract(slot), 2.0) * 0.8;
float press = clamp(max(max(cur, wave), max(typed, ghost)), 0.0, 1.0);
float lit = clamp(press + halo * 0.35, 0.0, 1.0);
// the backlight drifts across the wall in a slow gradient
vec3 light = pal(kc.x / uRes.x * 0.55 + kc.y / uRes.y * 0.3 - uFlow * 0.05 + h11(id) * 0.08);
// keycap: a skirt (outer outline) and a sculpted top that sinks when pressed
vec2 half_ = vec2(K.y * U, U) * 0.5 - U * 0.06;
float r = U * 0.13;
float sk = rbox(lp, half_ - press * U * 0.02, r);
vec2 topOff = vec2(0.0, -U * 0.035 * (1.0 - press));
vec2 topHalf = half_ - U * 0.085;
float tp = rbox(lp - topOff, topHalf, r * 0.8);
float aa = 1.0 / uDpr;
float inCap = clamp(0.5 - sk / aa, 0.0, 1.0);
float inTop = clamp(0.5 - tp / aa, 0.0, 1.0);
float edge = clamp(1.0 - abs(sk + aa * 0.6) / (aa * 1.2), 0.0, 1.0);
float topEdge = clamp(1.0 - abs(tp + aa * 0.5) / aa, 0.0, 1.0);
// a dark cap with a faint sheen down the top, a darker skirt
vec2 tu = (lp - topOff) / max(topHalf, vec2(1.0));
float sheen = 0.5 + 0.5 * (-tu.y);
vec3 cap = vec3(0.028) + vec3(0.02) * sheen * inTop;
cap = mix(cap * 0.7, cap, inTop);
cap += light * lit * (0.05 + 0.1 * press);
vec3 c = cap * inCap;
c += mix(uEdge * 0.8, light * 1.3, lit) * edge * (0.8 + 0.6 * lit);
c += mix(uEdge * 0.35, light * 0.6, lit) * topEdge * inCap * 0.5;
// legend, printed on the top surface; wide keys keep a 1u legend at their left
float H = topHalf.y * 2.0;
vec2 tl = (lp - topOff) - vec2(-topHalf.x, -topHalf.y); // from the top's top-left
vec2 luv = legend >= ${L_MOD}.0 ? vec2(tl.x / H, tl.y / H) : vec2((tl.x - (topHalf.x * 2.0 - H) * 0.5) / H, tl.y / H);
float ink = 0.0;
if (luv.x >= 0.0 && luv.x <= 1.0 && luv.y >= 0.0 && luv.y <= 1.0) {
vec2 slotUV = vec2(mod(legend, ${ATLAS_N}.0), floor(legend / ${ATLAS_N}.0));
vec2 gd = vec2(1.0 / (H * uDpr) / ${ATLAS_N}.0);
ink = textureGrad(uAtlas, (slotUV + luv) / ${ATLAS_N}.0, vec2(gd.x, 0.0), vec2(0.0, gd.y)).r * inTop;
}
c += mix(uLegend * 0.62, light * 1.9 + 0.25, lit) * ink;
// backlight spills out from under a pressed key
float spill = exp(-max(sk, 0.0) / (U * 0.12)) * (1.0 - inCap) * press;
c += light * spill * 0.35;
// a calm centre for headlines
vec2 cc = (kc - uRes * 0.5) / (uRes * 0.5);
float calm = 1.0 - uFocus * 0.75 * exp(-dot(cc * vec2(1.0, 1.3), cc * vec2(1.0, 1.3)) / 0.35);
// on load the backlight boots up row by row, sweeping across
float th = kc.x / uRes.x * 0.6 + h11(row) * 0.25 + h11(id) * 0.15;
float show = smoothstep(th, th + 0.15, uIntro * 1.2);
col = uBg + c * show * mix(calm, 1.0, lit);
}
col += (h21(gl_FragCoord.xy + fract(uTime) * 91.0) - 0.5) / 255.0;
o = vec4(col, 1.0);
}`;
const BLUR = `#version 300 es
precision mediump float;
uniform sampler2D uTex; uniform vec2 uStep; in vec2 vUv; out vec4 o;
void main() {
vec4 c = texture(uTex, vUv) * 0.2270;
c += (texture(uTex, vUv + uStep * 1.3846) + texture(uTex, vUv - uStep * 1.3846)) * 0.3162;
c += (texture(uTex, vUv + uStep * 3.2308) + texture(uTex, vUv - uStep * 3.2308)) * 0.0703;
o = c;
}`;
const BRIGHT = `#version 300 es
precision mediump float;
uniform sampler2D uTex; in vec2 vUv; out vec4 o;
void main() {
vec3 c = texture(uTex, vUv).rgb;
float l = max(c.r, max(c.g, c.b));
o = vec4(c * smoothstep(0.5, 1.05, l), 1.0);
}`;
const COMPOSITE = `#version 300 es
precision mediump float;
uniform sampler2D uScene, uBloom, uWide; uniform float uGlow, uTime; in vec2 vUv; out vec4 o;
float h(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
void main() {
vec3 sc = texture(uScene, vUv).rgb;
vec3 bl = texture(uBloom, vUv).rgb * 0.6 + texture(uWide, vUv).rgb * 0.4;
vec3 x = sc + bl * uGlow;
vec3 col = x / (1.0 + max(x - 0.8, 0.0) * 1.2);
col += (h(gl_FragCoord.xy + fract(uTime * 7.0) * 91.0) - 0.5) / 255.0;
o = vec4(min(col, vec3(1.0)), 1.0);
}`;
const isReducedMotion = () =>
typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
function rgb(hex: string): [number, number, number] {
let h = hex.replace("#", "");
if (h.length === 3) h = h.replace(/./g, (c) => c + c);
const n = parseInt(h, 16) || 0;
return [((n >> 16) & 255) / 255, ((n >> 8) & 255) / 255, (n & 255) / 255];
}
/** Which legend a keyboard event lights up, or -1. */
function legendFor(e: KeyboardEvent) {
const k = e.key;
if (k.length === 1) {
const up = k.toUpperCase();
const li = LETTERS.indexOf(up);
if (li >= 0) return li;
if (k === " ") return L_MOD + MODS.findIndex((m) => m.key === " ");
const pi = PAIRS.findIndex(([a, b]) => a === k || b === k || (k === '"' && a === "“"));
if (pi >= 0) return L_PAIR + pi;
return -1;
}
const mi = MODS.findIndex((m) => m.key === k);
return mi >= 0 ? L_MOD + mi : -1;
}
const DEFAULT_COLORS: [string, string, string] = ["#2b5cff", "#b44dff", "#ff5a36"];
export function KeyWall({
legend = "#c3c6ce",
edge = "#3a3d45",
colors = DEFAULT_COLORS,
background = "#030304",
size = 58,
typing = true,
focus = 0.35,
speed = 1,
glow = 0.8,
interactive = true,
scroller,
children,
className,
}: KeyWallProps) {
const hostRef = useRef<HTMLDivElement>(null);
const [c1, c2, c3] = colors;
const props = useRef({ legend, edge, c1, c2, c3, background, size, typing, focus, speed, glow, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { legend, edge, c1, c2, c3, background, size, typing, focus, speed, glow, interactive };
redraw.current?.();
}, [legend, edge, c1, c2, c3, background, size, typing, focus, speed, glow, interactive]);
useEffect(() => {
const host = hostRef.current;
if (!host) return;
if (getComputedStyle(host).position === "static") host.style.position = "relative";
const still = isReducedMotion();
const canvas = document.createElement("canvas");
canvas.setAttribute("aria-hidden", "true");
canvas.style.cssText = "position:absolute;inset:0;width:100%;height:100%;display:block;touch-action:pan-y;";
host.prepend(canvas);
const gl = canvas.getContext("webgl2", { alpha: false, antialias: false, powerPreference: "high-performance" });
if (!gl) {
const p = props.current;
host.style.background = `radial-gradient(80% 60% at 20% 10%, ${p.c1}1f, transparent 60%), radial-gradient(70% 60% at 90% 90%, ${p.c3}1a, transparent 60%), ${p.background}`;
canvas.remove();
return;
}
const build = (fs: string) => {
const pr = gl.createProgram()!;
for (const [type, src] of [
[gl.VERTEX_SHADER, QUAD],
[gl.FRAGMENT_SHADER, fs],
] as const) {
const sh = gl.createShader(type)!;
gl.shaderSource(sh, src);
gl.compileShader(sh);
if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) console.error(gl.getShaderInfoLog(sh));
gl.attachShader(pr, sh);
}
gl.bindAttribLocation(pr, 0, "aQ");
gl.linkProgram(pr);
if (!gl.getProgramParameter(pr, gl.LINK_STATUS)) console.error(gl.getProgramInfoLog(pr));
return pr;
};
const sceneProg = build(SCENE);
const blurProg = build(BLUR);
const brightProg = build(BRIGHT);
const compProg = build(COMPOSITE);
const uni = (pr: WebGLProgram, names: string[]) =>
Object.fromEntries(names.map((n) => [n, gl.getUniformLocation(pr, n)])) as Record<string, WebGLUniformLocation | null>;
const US = uni(sceneProg, [
"uRes", "uMouse", "uDpr", "uTime", "uU", "uSlide", "uScrollY", "uHover", "uIntro", "uFocus", "uFlow",
"uLegend", "uEdge", "uA", "uB", "uC", "uBg", "uPress", "uWave", "uAtlas", "uRows",
]);
const UB = uni(blurProg, ["uTex", "uStep"]);
const UR = uni(brightProg, ["uTex"]);
const UC = uni(compProg, ["uScene", "uBloom", "uWide", "uGlow", "uTime"]);
const vao = gl.createVertexArray();
gl.bindVertexArray(vao);
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
const drawQuad = () => gl.drawArrays(gl.TRIANGLES, 0, 3);
// ---- legend atlas: one cell per legend, laid out like a real keycap ----
const atlasTex = gl.createTexture()!;
{
const c = document.createElement("canvas");
c.width = c.height = ATLAS_N * CELL;
const x = c.getContext("2d")!;
x.fillStyle = "#000";
x.fillRect(0, 0, c.width, c.height);
x.fillStyle = "#fff";
const font = (px: number, wgt = 400) => `${wgt} ${px}px ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif`;
const at = (i: number) => [(i % ATLAS_N) * CELL, Math.floor(i / ATLAS_N) * CELL] as const;
x.textAlign = "center";
x.textBaseline = "middle";
LETTERS.forEach((l, i) => {
const [cx, cy] = at(i);
x.font = font(CELL * 0.36);
x.fillText(l, cx + CELL / 2, cy + CELL * 0.52);
});
PAIRS.forEach(([a, b], i) => {
const [cx, cy] = at(L_PAIR + i);
x.font = font(CELL * 0.26);
x.fillText(a, cx + CELL / 2, cy + CELL * 0.34);
x.fillText(b, cx + CELL / 2, cy + CELL * 0.66);
});
x.textAlign = "left";
x.textBaseline = "alphabetic";
MODS.forEach((m, i) => {
const [cx, cy] = at(L_MOD + i);
x.font = font(CELL * 0.17);
x.fillText(m.label, cx + CELL * 0.14, cy + CELL * 0.84);
});
gl.bindTexture(gl.TEXTURE_2D, atlasTex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, c);
gl.generateMipmap(gl.TEXTURE_2D);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
}
// ---- row layouts: keys of mixed widths that add up to one period ----
const rowsTex = gl.createTexture()!;
{
const data = new Float32Array(PKEYS * PATTERNS * 4);
let seed = 7;
const rnd = () => ((seed = (seed * 16807) % 2147483647) - 1) / 2147483646;
for (let r = 0; r < PATTERNS; r++) {
let x0 = 0, k = 0;
while (x0 < PERIOD - 1e-6 && k < PKEYS) {
const left = PERIOD - x0;
let wdt = 1, leg: number;
const roll = rnd();
if (roll < 0.14 && left >= 1.25) {
const fits = MODS.map((m, i) => ({ m, i })).filter(({ m }) => m.w <= left && (m.key !== " " || rnd() < 0.35));
const pick = fits[Math.floor(rnd() * fits.length)];
if (pick) {
wdt = pick.m.w;
leg = L_MOD + pick.i;
} else leg = Math.floor(rnd() * L_MOD);
} else if (roll < 0.36) leg = L_PAIR + Math.floor(rnd() * PAIRS.length);
else leg = Math.floor(rnd() * LETTERS.length);
// the last key soaks up any remainder so rows tile seamlessly
if (k === PKEYS - 1 || left - wdt < 1) {
// a stretched letter looks wrong: the filler key becomes a modifier (or a space bar)
if (Math.abs(left - wdt) > 1e-6 && leg < L_MOD) {
const fill = left >= 3 ? MODS.length - 1 : Math.floor(rnd() * (MODS.length - 2));
leg = L_MOD + fill;
}
wdt = left;
}
data.set([x0, wdt, leg, 0], (r * PKEYS + k) * 4);
x0 += wdt;
k++;
}
}
gl.bindTexture(gl.TEXTURE_2D, rowsTex);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA32F, PKEYS, PATTERNS, 0, gl.RGBA, gl.FLOAT, data);
}
type Target = { fb: WebGLFramebuffer; tex: WebGLTexture; w: number; h: number };
const target = (tw: number, th: number): Target => {
const tex = gl.createTexture()!;
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, tw, th, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
const fb = gl.createFramebuffer()!;
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
return { fb, tex, w: tw, h: th };
};
let T: { scene: Target; a: Target; b: Target; c: Target; d: Target } | null = null;
const freeTargets = () => {
if (!T) return;
for (const t of Object.values(T)) {
gl.deleteFramebuffer(t.fb);
gl.deleteTexture(t.tex);
}
T = null;
};
let w = 1, h = 1, dpr = 1;
const resize = () => {
dpr = Math.min(window.devicePixelRatio || 1, 1.75);
w = Math.max(1, host.clientWidth);
h = Math.max(1, host.clientHeight);
canvas.width = Math.round(w * dpr);
canvas.height = Math.round(h * dpr);
const sw = canvas.width, sh = canvas.height;
freeTargets();
T = {
scene: target(sw, sh),
a: target(Math.max(1, sw >> 2), Math.max(1, sh >> 2)),
b: target(Math.max(1, sw >> 2), Math.max(1, sh >> 2)),
c: target(Math.max(1, sw >> 4), Math.max(1, sh >> 4)),
d: target(Math.max(1, sw >> 4), Math.max(1, sh >> 4)),
};
};
resize();
const s = { intro: still ? 1 : 0, mx: -9999, my: -9999, hover: 0, slide: 0, scrollY: 0 };
let flow = still ? 5 : 0;
const press = new Float32Array(LEGENDS);
const held = new Uint8Array(LEGENDS);
const t0 = performance.now();
const clock = () => (still ? 10 : (performance.now() - t0) / 1000);
const waves: { x: number; y: number; t: number; s: number }[] = [];
const waveBuf = new Float32Array(MAXW * 4);
const blurPass = (src: Target, dst: Target, dx: number, dy: number) => {
gl.bindFramebuffer(gl.FRAMEBUFFER, dst.fb);
gl.viewport(0, 0, dst.w, dst.h);
gl.useProgram(blurProg);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, src.tex);
gl.uniform1i(UB.uTex, 0);
gl.uniform2f(UB.uStep, dx / src.w, dy / src.h);
drawQuad();
};
const draw = () => {
if (!T) return;
const p = props.current;
const X = T;
const now = clock();
const U = Math.max(28, p.size) * Math.max(0.68, Math.min(1, w / 1100));
gl.bindFramebuffer(gl.FRAMEBUFFER, X.scene.fb);
gl.viewport(0, 0, X.scene.w, X.scene.h);
gl.useProgram(sceneProg);
gl.uniform2f(US.uRes, w, h);
gl.uniform2f(US.uMouse, s.mx, s.my);
gl.uniform1f(US.uDpr, dpr);
gl.uniform1f(US.uTime, now);
gl.uniform1f(US.uU, U);
gl.uniform1f(US.uSlide, s.slide);
gl.uniform1f(US.uScrollY, s.scrollY);
gl.uniform1f(US.uHover, s.hover);
gl.uniform1f(US.uIntro, s.intro);
gl.uniform1f(US.uFocus, Math.max(0, Math.min(1, p.focus)));
gl.uniform1f(US.uFlow, flow);
gl.uniform3fv(US.uLegend, rgb(p.legend));
gl.uniform3fv(US.uEdge, rgb(p.edge));
gl.uniform3fv(US.uA, rgb(p.c1));
gl.uniform3fv(US.uB, rgb(p.c2));
gl.uniform3fv(US.uC, rgb(p.c3));
gl.uniform3fv(US.uBg, rgb(p.background));
gl.uniform1fv(US.uPress, press);
waveBuf.fill(0);
waves.forEach((v, i) => waveBuf.set([v.x, v.y, v.t, v.s], i * 4));
gl.uniform4fv(US.uWave, waveBuf);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, atlasTex);
gl.uniform1i(US.uAtlas, 0);
gl.activeTexture(gl.TEXTURE1);
gl.bindTexture(gl.TEXTURE_2D, rowsTex);
gl.uniform1i(US.uRows, 1);
drawQuad();
gl.bindFramebuffer(gl.FRAMEBUFFER, X.a.fb);
gl.viewport(0, 0, X.a.w, X.a.h);
gl.useProgram(brightProg);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, X.scene.tex);
gl.uniform1i(UR.uTex, 0);
drawQuad();
blurPass(X.a, X.b, 1, 0);
blurPass(X.b, X.a, 0, 1);
blurPass(X.a, X.c, 1, 0);
blurPass(X.c, X.d, 0, 1);
blurPass(X.d, X.c, 1.8, 0);
blurPass(X.c, X.d, 0, 1.8);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
gl.viewport(0, 0, canvas.width, canvas.height);
gl.useProgram(compProg);
[X.scene.tex, X.a.tex, X.d.tex].forEach((tex, i) => {
gl.activeTexture(gl.TEXTURE0 + i);
gl.bindTexture(gl.TEXTURE_2D, tex);
});
gl.uniform1i(UC.uScene, 0);
gl.uniform1i(UC.uBloom, 1);
gl.uniform1i(UC.uWide, 2);
gl.uniform1f(UC.uGlow, p.glow);
gl.uniform1f(UC.uTime, now);
drawQuad();
gl.activeTexture(gl.TEXTURE0);
};
const ro = new ResizeObserver(() => {
resize();
draw();
});
ro.observe(host);
if (still) {
draw();
redraw.current = draw;
return () => {
redraw.current = null;
ro.disconnect();
freeTargets();
gl.deleteTexture(atlasTex);
gl.deleteTexture(rowsTex);
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}
// ---- on load: the backlight boots up row by row ----
const intro = gsap.to(s, { intro: 1, duration: 2.2, ease: "power2.out", delay: 0.1 });
// ---- cursor: the backlight; keys under it press in and glow ----
const mxTo = gsap.quickTo(s, "mx", { duration: 0.25, ease: "power3" });
const myTo = gsap.quickTo(s, "my", { duration: 0.25, ease: "power3" });
const hoverTo = gsap.quickTo(s, "hover", { duration: 0.5, ease: "power2.inOut" });
let first = true;
const local = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
return { x: e.clientX - r.left, y: e.clientY - r.top };
};
const move = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
if (first) {
gsap.set(s, { mx: p.x, my: p.y });
first = false;
}
mxTo(p.x);
myTo(p.y);
hoverTo(1);
};
const leave = () => {
first = true;
hoverTo(0);
};
// ---- click: a ripple of key presses ----
const down = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
waves.push({ x: p.x, y: p.y, t: clock(), s: 1 });
if (waves.length > MAXW) waves.shift();
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- typing anywhere on the page presses every matching key on the wall ----
let visible = true;
const keydown = (e: KeyboardEvent) => {
if (!props.current.typing || !visible) return;
const i = legendFor(e);
if (i < 0) return;
press[i] = 1;
held[i] = 1;
};
const keyup = (e: KeyboardEvent) => {
const i = legendFor(e);
if (i >= 0) held[i] = 0;
};
const blur = () => held.fill(0);
window.addEventListener("keydown", keydown);
window.addEventListener("keyup", keyup);
window.addEventListener("blur", blur);
// ---- scroll: alternate rows slide apart, the wall drifts with the page ----
const slideTo = gsap.quickTo(s, "slide", { duration: 1, ease: "power3" });
const scrollYTo = gsap.quickTo(s, "scrollY", { duration: 1, ease: "power3" });
const st = ScrollTrigger.create({
trigger: host,
scroller: scroller ?? undefined,
start: "top bottom",
end: "bottom top",
onUpdate: (self) => {
slideTo((self.progress - 0.5) * 6);
scrollYTo((self.progress - 0.5) * -h * 0.25);
},
});
// ---- loop, only while on screen ----
let prev = performance.now();
const loop = () => {
const t = performance.now();
const dt = Math.min(0.05, (t - prev) / 1000);
prev = t;
if (!visible) return;
flow += dt * props.current.speed;
for (let i = 0; i < LEGENDS; i++) if (!held[i] && press[i] > 0) press[i] = Math.max(0, press[i] - dt * 1.8);
const now = clock();
for (let i = waves.length - 1; i >= 0; i--) if (now - waves[i].t > 2.8) waves.splice(i, 1);
draw();
};
const io = new IntersectionObserver(([en]) => {
visible = en.isIntersecting;
prev = performance.now();
});
io.observe(host);
gsap.ticker.add(loop);
redraw.current = null;
return () => {
gsap.ticker.remove(loop);
intro.kill();
st.kill();
io.disconnect();
ro.disconnect();
host.removeEventListener("pointermove", move);
host.removeEventListener("pointerleave", leave);
host.removeEventListener("pointerdown", down);
window.removeEventListener("keydown", keydown);
window.removeEventListener("keyup", keyup);
window.removeEventListener("blur", blur);
gsap.killTweensOf(s);
freeTargets();
gl.deleteTexture(atlasTex);
gl.deleteTexture(rowsTex);
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}, [scroller]);
return (
<div ref={hostRef} className={["isolate overflow-hidden", className].filter(Boolean).join(" ")} style={{ background }}>
{children && <div className="relative z-10 h-full">{children}</div>}
</div>
);
}
export default KeyWall;
One prompt, any AI agent
Paste into Claude Code, Codex, Cursor or Windsurf. It carries your tweaks and the full source, so the agent installs it exactly.
Props
13 propslegendstringColour of the resting legends.default "#c3c6ce"default "#c3c6ce"edgestringColour of the keycap edges.default "#3a3d45"default "#3a3d45"colors[string, string, string]The three backlight colours.default ["#2b5cff", "#b44dff", "#ff5a36"]default ["#2b5cff", "#b44dff", "#ff5a36"]backgroundstringBackground colour.default "#030304"default "#030304"sizenumberKey size in px (scaled down on small screens).default 58default 58typingbooleanLight up keys when visitors type on the page.default truedefault truefocusnumberCalms the centre so a headline on top stays readable, 0 to 1.default 0.35default 0.35speednumberSpeed of the backlight drift and ghost typing.default 1default 1glownumberStrength of the bloom on lit keys.default 0.8default 0.8interactivebooleanCursor backlight, click ripple and scroll response.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the wall.classNamestringSize it, e.g. h-screen w-full.