key-probe.mjs (1917B)
1 // Quelle combinaison donne ( et ) sur le clavier EXL 100 émulé ? Tape chaque candidat sur sa 2 // propre ligne BASIC (puis Entrée) et capture l'écho. 3 // node test/key-probe.mjs [base-url] 4 import { open, sleep } from './cdp.mjs'; 5 const base = process.argv[2] ?? 'http://127.0.0.1:8195'; 6 const url = base + '/?game=exl100&rom=/roms/exl100.zip&exelmem=0&args=' + encodeURIComponent('--tape /roms/cartridges/exelbasic.bin'); 7 const page = await open(url, { width: 900, height: 1100 }); 8 const ev = (type, k, code, vk, mods = 0) => 9 page.send('Input.dispatchKeyEvent', { type, key: k, code, windowsVirtualKeyCode: vk, modifiers: mods }); 10 const key = async (k, code, vk, hold = 80, gap = 350) => { await ev('keyDown', k, code, vk); await sleep(hold); await ev('keyUp', k, code, vk); await sleep(gap); }; 11 const shifted = async (k, code, vk) => { 12 await ev('keyDown', 'Shift', 'ShiftLeft', 16); await sleep(80); 13 await ev('keyDown', k, code, vk, 8); await sleep(80); await ev('keyUp', k, code, vk, 8); await sleep(80); 14 await ev('keyUp', 'Shift', 'ShiftLeft', 16); await sleep(350); 15 }; 16 const cands = [ 17 ['S5', () => shifted('%', 'Digit5', 53)], ['S8', () => shifted('*', 'Digit8', 56)], ['S9', () => shifted('(', 'Digit9', 57)], 18 ['S0', () => shifted(')', 'Digit0', 48)], ['S1', () => shifted('!', 'Digit1', 49)], ['S2', () => shifted('@', 'Digit2', 50)], 19 ['S4', () => shifted('$', 'Digit4', 52)], ['S6', () => shifted('^', 'Digit6', 54)], ['S7', () => shifted('&', 'Digit7', 55)], 20 ]; 21 await sleep(9000); 22 for (const [label, fn] of cands) { 23 for (const ch of label) { if (ch === 'S') await key('s', 'KeyS', 83); else if (/[0-9]/.test(ch)) await key(ch, 'Digit' + ch, ch.charCodeAt(0)); else await key('x', 'KeyX', 88); } 24 await key(' ', 'Space', 32); 25 await fn(); 26 await key('Enter', 'Enter', 13); await sleep(250); 27 } 28 await page.screenshot('/tmp/keys.png'); 29 console.log('Capture : /tmp/keys.png'); 30 page.close();