Advertisement
nerdemma

Input Control

Dec 17th, 2024
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 1.11 KB | Source Code | 0 0
  1.  
  2. function key_pressed($code) #funcion para capturar teclas presionadas
  3. {
  4. if($HOST.UI.RawUI.KeyAvailable)
  5.     {
  6.     $key = $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
  7.     return $key.VirtualKeyCode -eq $code
  8.     }
  9. return $false;
  10. }
  11.  
  12. function hora()
  13. {
  14. return Get-Date -Format "HH:mm:ss"
  15. }
  16.  
  17. #crear estructura de la tabla en base a la cantidad de campos que se ingresan indefinidamente
  18. function new_index()
  19. {
  20.     Add-Type -TypeDefinition @"
  21. using System;
  22. using System.Runtime.InteropServices;
  23. public class Keyboard {
  24.    [DllImport("user32.dll")]
  25.    public static extern short GetAsyncKeyState(int vKey);
  26. }
  27. "@
  28.    
  29. Write-Host "Nuevo Indice - Presione F1 para finalizar"
  30. while($true)
  31. {
  32.     if( [Keyboard]::GetAsyncKeyState(0x70) -ne 0 )
  33.     {
  34.     break
  35.     }  
  36.     $output = Read-Host ">"
  37.     Write-Host $output
  38. }
  39.     Write-Host "Ciclo finalizado"
  40. }
  41.  
  42. function main()
  43. {
  44. $Host.UI.RawUI.CursorSize = 1
  45.  
  46. while (-not (key_pressed(27))) #mientras no se oprima esc no se cierra el programa
  47. {
  48.     Write-Host "Hola Emma - Presione Esc para salir"
  49.     Write-Host(hora)   
  50.     Start-Sleep -Milliseconds 500
  51.    
  52.    
  53.    
  54. }  
  55. }
  56.  
  57.  
  58. #main
  59.  
  60. new_index
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement