# ============================================================================ # RMS TECH - INPUT LAG BOOST / Reducao de Input Lag (Mouse / Teclado) # Interface + logica · by @rms.tech · distribuicao gratuita / free to share # Executado pelo RMS-TECH-INPUTLAG-BOOST.bat (nao rode este .ps1 direto). # ============================================================================ $ErrorActionPreference = 'Stop' # --- pasta do script / script folder ------------------------------------ $ScriptDir = $PSScriptRoot if (-not $ScriptDir) { $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path } try { Set-Location -LiteralPath $ScriptDir } catch {} try { [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 } catch {} # --- liga cores ANSI 24-bit no console classico / enable truecolor ----- if (-not $env:WT_SESSION) { try { Add-Type -Namespace RmsVT -Name Native -MemberDefinition '[DllImport("kernel32.dll")] public static extern IntPtr GetStdHandle(int h); [DllImport("kernel32.dll")] public static extern bool GetConsoleMode(IntPtr h, out uint m); [DllImport("kernel32.dll")] public static extern bool SetConsoleMode(IntPtr h, uint m);' $hOut = [RmsVT.Native]::GetStdHandle(-11) $cmode = [uint32]0 [void][RmsVT.Native]::GetConsoleMode($hOut, [ref]$cmode) [void][RmsVT.Native]::SetConsoleMode($hOut, $cmode -bor 0x0004) } catch {} } # --- tamanho da janela / window size (best effort) -------------------- try { $ui = $Host.UI.RawUI $mx = $ui.MaxPhysicalWindowSize $cols = [Math]::Min(104, [int]$mx.Width) $rws = [Math]::Min(46, [int]$mx.Height) $bs = $ui.BufferSize; if ($bs.Width -lt $cols) { $bs.Width = $cols }; $bs.Height = 3000; $ui.BufferSize = $bs $ws = $ui.WindowSize; $ws.Width = $cols; $ws.Height = $rws; $ui.WindowSize = $ws } catch {} # --- paleta / palette -------------------------------------------------- $ESC = [char]27 $RS = "$ESC[0m" $BLD = "$ESC[1m" function fg ($r, $g, $b) { "$ESC[38;2;$r;$g;${b}m" } function bgc ($r, $g, $b) { "$ESC[48;2;$r;$g;${b}m" } $CY = fg 90 210 255 $MG = fg 200 100 255 $GR = fg 90 230 150 $RD = fg 255 100 115 $YL = fg 255 205 100 $DM = fg 120 126 145 $WH = fg 236 239 246 $TX = fg 205 210 226 $DOT = [char]183 $PTR = [char]187 $AUP = [char]24 $ADN = [char]25 # --- banner (fonte ANSI Shadow, chars CP437-safe) ------------------- $RMS = @( '██████╗ ███╗ ███╗███████╗', '██╔══██╗████╗ ████║██╔════╝', '██████╔╝██╔████╔██║███████╗', '██╔══██╗██║╚██╔╝██║╚════██║', '██║ ██║██║ ╚═╝ ██║███████║', '╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝') $TECH = @( '████████╗███████╗ ██████╗██╗ ██╗', '╚══██╔══╝██╔════╝██╔════╝██║ ██║', ' ██║ █████╗ ██║ ███████║', ' ██║ ██╔══╝ ██║ ██╔══██║', ' ██║ ███████╗╚██████╗██║ ██║', ' ╚═╝ ╚══════╝ ╚═════╝╚═╝ ╚═╝') function GradBlock ($arr, $c1, $c2, $ind) { $n = $arr.Count for ($i = 0; $i -lt $n; $i++) { if ($n -le 1) { $q = 0 } else { $q = $i / ($n - 1) } $cr = [int]($c1[0] + ($c2[0] - $c1[0]) * $q) $cg = [int]($c1[1] + ($c2[1] - $c1[1]) * $q) $cb = [int]($c1[2] + ($c2[2] - $c1[2]) * $q) Write-Host ((' ' * $ind) + (fg $cr $cg $cb) + $arr[$i] + $RS) } } function Header { try { Clear-Host } catch {} Write-Host '' GradBlock $RMS @(95, 215, 255) @(150, 130, 255) 6 GradBlock $TECH @(150, 130, 255) @(210, 95, 255) 6 Write-Host '' Write-Host (' ' + $DM + ('─' * 58) + $RS) Write-Host (' ' + $WH + $BLD + 'INPUT LAG BOOST' + $RS + $DM + " Reducao de Input Lag $DOT Mouse / Keyboard" + $RS) Write-Host (' ' + $DM + 'by ' + $RS + $MG + $BLD + '@rms.tech' + $RS + $DM + " $DOT distribuicao gratuita" + $RS) Write-Host '' } # --- menu com setas / arrow-key menu ------------------------------- function Menu ($items, $title) { $sel = 0 $w = 58 while ($true) { Header if ($title) { Write-Host (' ' + $YL + $title + $RS); Write-Host '' } Write-Host (' ' + $DM + '┌' + ('─' * $w) + '┐' + $RS) Write-Host (' ' + $DM + '│' + (' ' * $w) + '│' + $RS) for ($i = 0; $i -lt $items.Count; $i++) { $lab = ' ' + $items[$i].Key + ' ' + $items[$i].Text if ($i -eq $sel) { $cell = ' ' + $PTR + ' ' + $lab $cell = $cell + (' ' * [Math]::Max(0, $w - $cell.Length)) Write-Host (' ' + $DM + '│' + $RS + (bgc 38 44 62) + (fg 130 232 255) + $BLD + $cell + $RS + $DM + '│' + $RS) } else { $cell = ' ' + $lab $cell = $cell + (' ' * [Math]::Max(0, $w - $cell.Length)) Write-Host (' ' + $DM + '│' + $RS + $TX + $cell + $RS + $DM + '│' + $RS) } } Write-Host (' ' + $DM + '│' + (' ' * $w) + '│' + $RS) Write-Host (' ' + $DM + '└' + ('─' * $w) + '┘' + $RS) Write-Host '' Write-Host (' ' + $DM + "$AUP $ADN" + $RS + $TX + ' navegar ' + $RS + $DM + 'Enter' + $RS + $TX + ' confirmar ' + $RS + $DM + 'Esc' + $RS + $TX + ' voltar' + $RS) $k = [Console]::ReadKey($true) if ($k.Key -eq 'UpArrow') { $sel = ($sel - 1 + $items.Count) % $items.Count; continue } if ($k.Key -eq 'DownArrow') { $sel = ($sel + 1) % $items.Count; continue } if ($k.Key -eq 'Enter') { return $items[$sel].Id } if ($k.Key -eq 'Escape') { return 'BACK' } foreach ($it in $items) { if ($it.Key -ne '' -and ([string]$k.KeyChar -eq [string]$it.Key)) { return $it.Id } } } } # --- helpers de status / status helpers --------------------------- function SLine ($txt) { Write-Host (' ' + $DM + ' ... ' + $RS + $TX + $txt + $RS) -NoNewline } function SOk ($txt) { Write-Host ("`r" + $ESC + '[2K' + ' ' + (bgc 30 90 55) + $GR + $BLD + ' OK ' + $RS + ' ' + $TX + $txt + $RS) } function SFail ($txt) { Write-Host ("`r" + $ESC + '[2K' + ' ' + (bgc 100 35 40) + $RD + $BLD + ' ERRO ' + $RS + ' ' + $TX + $txt + $RS) } function SWarn ($txt) { Write-Host ("`r" + $ESC + '[2K' + ' ' + (bgc 95 75 20) + $YL + $BLD + ' AVISO ' + $RS + ' ' + $TX + $txt + $RS) } function Bar ($total, $done) { $wd = 34 if ($total -le 0) { $f = 0 } else { $f = [int][Math]::Round($wd * $done / $total) } ' ' + $CY + ('█' * $f) + $DM + ('░' * ($wd - $f)) + $RS + $TX + (' {0}/{1}' -f $done, $total) + $RS } function GBox ($lines, $col) { $lines = @($lines) $w = 50 Write-Host (' ' + $col + $BLD + '╔' + ('═' * $w) + '╗' + $RS) foreach ($l in $lines) { $s = ' ' + $l if ($s.Length -gt $w) { $s = $s.Substring(0, $w) } $s = $s + (' ' * ($w - $s.Length)) Write-Host (' ' + $col + $BLD + '║' + $s + '║' + $RS) } Write-Host (' ' + $col + $BLD + '╚' + ('═' * $w) + '╝' + $RS) } function Pause2 { Write-Host '' Write-Host (' ' + $DM + 'pressione qualquer tecla para voltar ao menu...' + $RS) [void][Console]::ReadKey($true) } # --- executa reg.exe silencioso / run reg.exe quietly ------------ function RegRun { param([Parameter(ValueFromRemainingArguments = $true)] $a) $old = $ErrorActionPreference $ErrorActionPreference = 'SilentlyContinue' try { $null = & reg @a 2>&1 } catch {} $ok = ($LASTEXITCODE -eq 0) $ErrorActionPreference = $old return $ok } # --- plano de energia / power plan -------------------------------- function GetActiveScheme { $old = $ErrorActionPreference $ErrorActionPreference = 'SilentlyContinue' $o = '' try { $o = (& powercfg /getactivescheme 2>&1 | Out-String) } catch {} $ErrorActionPreference = $old if ($o -match '([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})') { return $Matches[1] } return '' } function SetScheme ($s) { $old = $ErrorActionPreference $ErrorActionPreference = 'SilentlyContinue' try { $null = & powercfg /setactive $s 2>&1 } catch {} $ok = ($LASTEXITCODE -eq 0) $ErrorActionPreference = $old return $ok } # --- chaves / keys ------------------------------------------------- $K_PRIO = 'HKLM\SYSTEM\CurrentControlSet\Control\PriorityControl' $K_MKEYS = 'HKCU\Control Panel\Accessibility\MouseKeys' $K_KBRESP = 'HKCU\Control Panel\Accessibility\Keyboard Response' $K_STICKY = 'HKCU\Control Panel\Accessibility\StickyKeys' $K_TOGGLE = 'HKCU\Control Panel\Accessibility\ToggleKeys' $K_MOUSE ='HKCU\Control Panel\Mouse' $K_GDVR = 'HKCU\Software\Microsoft\Windows\CurrentVersion\GameDVR' $K_GCS = 'HKCU\System\GameConfigStore' $K_DWM = 'HKLM\SOFTWARE\Microsoft\Windows\Dwm' # Del = apaga o valor no "Restaurar" (so os que podem nao existir de fabrica) function Tweaks { @( @{ K = $K_PRIO; N = 'Win32PrioritySeparation'; T = 'REG_DWORD'; D = '38'; Del = $false; L = 'Win32PrioritySeparation = 38' } @{ K = $K_MKEYS; N = 'Flags'; T = 'REG_SZ'; D = '0'; Del = $false; L = 'Mouse Keys desligado' } @{ K = $K_KBRESP; N = 'Flags'; T = 'REG_SZ'; D = '0'; Del = $false; L = 'Keyboard Response (Filter Keys) desligado' } @{ K = $K_STICKY; N = 'Flags'; T = 'REG_SZ'; D = '506'; Del = $false; L = 'Atalho do Sticky Keys (5x Shift) desligado' } @{ K = $K_TOGGLE; N = 'Flags'; T = 'REG_SZ'; D = '58'; Del = $false; L = 'Atalho do Toggle Keys desligado' } @{ K = $K_MOUSE; N = 'MouseSpeed'; T = 'REG_SZ'; D = '0'; Del = $false; L = 'Aceleracao do mouse desligada (MouseSpeed = 0)' } @{ K = $K_MOUSE; N = 'MouseThreshold1'; T = 'REG_SZ'; D = '0'; Del = $false; L = 'MouseThreshold1 = 0' } @{ K = $K_MOUSE; N = 'MouseThreshold2'; T = 'REG_SZ'; D = '0'; Del = $false; L = 'MouseThreshold2 = 0' } @{ K = $K_GDVR; N = 'AppCaptureEnabled'; T = 'REG_DWORD'; D = '0'; Del = $true; L = 'Game DVR: AppCaptureEnabled = 0' } @{ K = $K_GCS; N = 'GameDVR_Enabled'; T = 'REG_DWORD'; D = '0'; Del = $true; L = 'Game DVR: GameDVR_Enabled = 0' } @{ K = $K_DWM; N = 'OverlayTestMode'; T = 'REG_DWORD'; D = '5'; Del = $true; L = 'DWM OverlayTestMode = 5' } ) } # --- tela de confirmacao / confirm screen -------------------- function Confirm { Header $w = 58 Write-Host (' ' + $YL + 'Isto sera gravado no Registro do Windows:' + $RS) Write-Host '' $rows = @( 'PriorityControl Win32PrioritySeparation 38', 'MouseKeys Flags 0', 'Keyboard Response Flags 0', 'StickyKeys Flags 506', 'ToggleKeys Flags 58', 'Mouse MouseSpeed 0', 'Mouse MouseThreshold1 0', 'Mouse MouseThreshold2 0', 'GameDVR AppCaptureEnabled 0', 'GameConfigStore GameDVR_Enabled 0', 'Dwm OverlayTestMode 5', 'Plano de energia Alto desempenho (SCHEME_MIN)') Write-Host (' ' + $DM + '┌' + ('─' * $w) + '┐' + $RS) foreach ($r in $rows) { $s = ' ' + $r $s = $s + (' ' * [Math]::Max(0, $w - $s.Length)) Write-Host (' ' + $DM + '│' + $RS + $TX + $s + $RS + $DM + '│' + $RS) } Write-Host (' ' + $DM + '└' + ('─' * $w) + '┘' + $RS) Write-Host '' Write-Host (' ' + $DM + 'MouseSpeed/Threshold = 0 desliga "Aprimorar precisao' + $RS) Write-Host (' ' + $DM + 'do ponteiro". Vale melhor depois de reiniciar.' + $RS) Write-Host '' Write-Host (' ' + $DM + 'backup em ' + $RS + (fg 170 176 196) + (Join-Path $ScriptDir 'Backup_RMS_INPUTLAG') + $RS) Write-Host '' Write-Host (' ' + (bgc 30 90 55) + $BLD + ' S ' + $RS + $TX + ' aplicar agora ' + $RS + (bgc 100 35 40) + $BLD + ' N ' + $RS + $TX + ' cancelar' + $RS) while ($true) { $k = [Console]::ReadKey($true) $c = [string]$k.KeyChar if ($c -match '^[sySY]$') { return $true } if ($c -match '^[nN]$' -or $k.Key -eq 'Escape') { return $false } } } # --- aplicar / apply --------------------------------------- function RunApply { Header Write-Host (' ' + $WH + $BLD + "1 $DOT BACKUP" + $RS) Write-Host '' $stamp = Get-Date -Format 'yyyy-MM-dd_HH-mm-ss' $bkdir = Join-Path (Join-Path $ScriptDir 'Backup_RMS_INPUTLAG') $stamp New-Item -ItemType Directory -Force -Path $bkdir | Out-Null $bkeys = @( @{ K = $K_PRIO; F = 'PriorityControl.reg' } @{ K = $K_MKEYS; F = 'MouseKeys.reg' } @{ K = $K_KBRESP; F = 'KeyboardResponse.reg' } @{ K = $K_STICKY; F = 'StickyKeys.reg' } @{ K = $K_TOGGLE; F = 'ToggleKeys.reg' } @{ K = $K_MOUSE; F = 'Mouse.reg' } @{ K = $K_GDVR; F = 'GameDVR.reg' } @{ K = $K_GCS; F = 'GameConfigStore.reg' } @{ K = $K_DWM; F = 'Dwm.reg' } ) foreach ($x in $bkeys) { SLine $x.F Start-Sleep -Milliseconds 55 if (RegRun query $x.K) { if (RegRun export $x.K (Join-Path $bkdir $x.F) /y) { SOk ('backup ' + $x.F) } else { SWarn ('sem backup ' + $x.F) } } else { Set-Content -LiteralPath (Join-Path $bkdir ('MISSING_' + $x.F + '.txt')) -Value $x.K -Encoding ASCII SWarn ('nao existia, ok ' + $x.F) } } SLine 'PowerScheme.txt' Start-Sleep -Milliseconds 55 $curScheme = GetActiveScheme if ($curScheme) { Set-Content -LiteralPath (Join-Path $bkdir 'PowerScheme.txt') -Value $curScheme -Encoding ASCII SOk ('backup plano de energia atual ' + $curScheme) } else { SWarn 'nao consegui ler o plano de energia atual' } Write-Host '' Write-Host (' ' + $WH + $BLD + "2 $DOT APLICANDO / APPLYING" + $RS) Write-Host '' $tw = Tweaks $total = $tw.Count + 1 $done = 0; $fail = 0 foreach ($t in $tw) { SLine $t.L Start-Sleep -Milliseconds 70 if (RegRun add $t.K /v $t.N /t $t.T /d $t.D /f) { SOk $t.L; $done++ } else { SFail $t.L; $fail++ } } SLine 'Plano de energia: Alto desempenho' Start-Sleep -Milliseconds 70 if (SetScheme 'SCHEME_MIN') { SOk 'Plano de energia: Alto desempenho'; $done++ } else { SWarn 'Alto desempenho indisponivel neste PC, plano mantido' } Write-Host '' Write-Host (Bar $total $done) Write-Host '' if ($fail -eq 0) { GBox @( "TWEAKS APLICADOS $DOT REINICIE O PC", "TWEAKS APPLIED $DOT RESTART YOUR PC") $GR } else { GBox @("$fail item(s) falharam.", 'Feche e rode como administrador.') $YL } Write-Host '' Write-Host (' ' + $DM + 'backup: ' + $RS + (fg 170 176 196) + $bkdir + $RS) Write-Host '' Write-Host (' ' + $MG + $BLD + 'curtiu? compartilha com a galera e segue @rms.tech' + $RS) try { Start-Process 'https://otimizar.superpackultimate.com/?de=packs' } catch {} Pause2 } # --- restaurar / restore -------------------------------- function RunRestore { Header Write-Host (' ' + $WH + $BLD + 'RESTAURAR / RESTORE' + $RS) Write-Host '' $bkroot = Join-Path $ScriptDir 'Backup_RMS_INPUTLAG' if (-not (Test-Path -LiteralPath $bkroot)) { GBox @('Nenhum backup encontrado.', 'No backup found.') $RD Pause2; return } $latest = Get-ChildItem -LiteralPath $bkroot -Directory -ErrorAction SilentlyContinue | Sort-Object Name -Descending | Select-Object -First 1 if (-not $latest) { GBox @('Nenhum backup encontrado.', 'No backup found.') $RD Pause2; return } Write-Host (' ' + $DM + 'de / from: ' + $RS + (fg 170 176 196) + $latest.FullName + $RS) Write-Host '' Write-Host (' ' + $WH + $BLD + 'removendo valores adicionados / removing added values' + $RS) Write-Host '' foreach ($t in (Tweaks)) { if (-not $t.Del) { continue } SLine ('remover ' + $t.N) Start-Sleep -Milliseconds 40 [void](RegRun delete $t.K /v $t.N /f) SOk ('removido ' + $t.N) } Write-Host '' Write-Host (' ' + $WH + $BLD + 'reimportando originais / re-importing originals' + $RS) Write-Host '' $imported = 0 Get-ChildItem -LiteralPath $latest.FullName -Filter *.reg -ErrorAction SilentlyContinue | ForEach-Object { SLine ('import ' + $_.Name) Start-Sleep -Milliseconds 40 if (RegRun import $_.FullName) { SOk ('import ' + $_.Name); $imported++ } else { SFail ('import ' + $_.Name) } } if ($imported -eq 0) { Write-Host (' ' + $DM + ' (nenhum .reg neste backup)' + $RS) } foreach ($mk in (Get-ChildItem -LiteralPath $latest.FullName -Filter 'MISSING_*.txt' -ErrorAction SilentlyContinue)) { $origKey = (Get-Content -LiteralPath $mk.FullName -Raw).Trim() [void](RegRun delete $origKey /f) SWarn ('chave removida (nao existia antes) ' + $mk.Name) } $pf = Join-Path $latest.FullName 'PowerScheme.txt' if (Test-Path -LiteralPath $pf) { $orig = (Get-Content -LiteralPath $pf -Raw).Trim() SLine 'plano de energia original' Start-Sleep -Milliseconds 40 if ($orig -and (SetScheme $orig)) { SOk ('plano de energia restaurado ' + $orig) } else { SWarn 'nao consegui restaurar o plano de energia' } } Write-Host '' GBox @("RESTAURADO $DOT REINICIE O PC", "RESTORED $DOT RESTART YOUR PC") $GR Pause2 } # ============================ MAIN ===================================== try { [Console]::CursorVisible = $false } catch {} try { while ($true) { $c = Menu @( @{ Id = 'APPLY'; Key = '1'; Text = "Aplicar otimizacoes $DOT Apply tweaks" } @{ Id = 'RESTORE'; Key = '2'; Text = "Restaurar ultimo backup $DOT Restore backup" } @{ Id = 'EXIT'; Key = '3'; Text = "Sair $DOT Exit" } ) '' if ($c -eq 'APPLY') { if (Confirm) { RunApply } } elseif ($c -eq 'RESTORE') { RunRestore } elseif ($c -eq 'EXIT' -or $c -eq 'BACK') { break } } } catch { Write-Host '' Write-Host (' ' + $RD + $BLD + 'ERRO INESPERADO / UNEXPECTED ERROR:' + $RS) Write-Host (' ' + $TX + $_.Exception.Message + $RS) Write-Host '' Write-Host (' ' + $DM + 'pressione qualquer tecla para fechar...' + $RS) try { [void][Console]::ReadKey($true) } catch { Read-Host | Out-Null } } finally { try { [Console]::CursorVisible = $true } catch {} Write-Host $RS Write-Host '' }