import { execFile } from 'child_process' import { promisify } from 'util' import { POWERSHELL_EXE } from './systemPaths' const execFileAsync = promisify(execFile) const script = (keyCode: number, times: number): string => ` Add-Type -TypeDefinition @" using System; using System.Runtime.InteropServices; public class ForgeAvatarInput { [DllImport("user32.dll")] public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo); } "@ for ($i = 0; $i -lt ${times}; $i++) { [ForgeAvatarInput]::keybd_event(${keyCode}, 0, 0, [UIntPtr]::Zero) [ForgeAvatarInput]::keybd_event(${keyCode}, 0, 2, [UIntPtr]::Zero) Start-Sleep -Milliseconds 50 } ` /** Simule l'appui d'une touche virtuelle Windows (volume, media...) via user32.dll. */ export async function pressVirtualKey(keyCode: number, times = 1): Promise { await execFileAsync(POWERSHELL_EXE, ['-NoProfile', '-Command', script(keyCode, times)]) }