exl100

Émulateur Exelvision EXL 100 (1984) dans le navigateur : dsp-cpp en WebAssembly, cartouches et cassettes BASIC
git clone https://git.schurger.org/exl100.git
Log | Files | Refs | README

focus-grab.mjs (1547B)


      1 // Clic sur l'écran : focus + centrage + message « clavier pris » ; la barre d'espace et les flèches ne font
      2 // plus défiler la page tant que l'émulateur a le focus ; un clic ailleurs rend le clavier.
      3 //   node test/focus-grab.mjs [url]
      4 import { open, sleep } from './cdp.mjs';
      5 
      6 const url = process.argv[2] ?? 'http://127.0.0.1:8196/';
      7 const page = await open(url, { width: 900, height: 700 });
      8 await sleep(6000);
      9 const state = () => page.evaluate(`({ y: Math.round(scrollY), grab: !document.getElementById('grab').hidden, focus: document.activeElement && document.activeElement.id })`);
     10 console.log('départ :', JSON.stringify(await state()));
     11 await page.evaluate("document.getElementById('canvas').click()");
     12 await sleep(1200);
     13 const afterClick = await state();
     14 console.log('après clic :', JSON.stringify(afterClick));
     15 const y0 = afterClick.y;
     16 for (const [k, code, vk] of [[' ', 'Space', 32], ['ArrowDown', 'ArrowDown', 40], ['PageDown', 'PageDown', 34]]) {
     17   await page.send('Input.dispatchKeyEvent', { type: 'keyDown', key: k, code, windowsVirtualKeyCode: vk });
     18   await sleep(60);
     19   await page.send('Input.dispatchKeyEvent', { type: 'keyUp', key: k, code, windowsVirtualKeyCode: vk });
     20   await sleep(300);
     21 }
     22 const afterKeys = await state();
     23 console.log('après espace/flèche/page :', JSON.stringify(afterKeys), afterKeys.y === y0 ? '=> pas de défilement' : '=> A DÉFILÉ');
     24 await page.evaluate("document.getElementById('canvas').blur()");
     25 await sleep(200);
     26 console.log('après blur :', JSON.stringify(await state()));
     27 page.close();