How to add a delay/pause to a macro that is used to simulate user keystrokes

Welcome Forums General PowerShell Q&A How to add a delay/pause to a macro that is used to simulate user keystrokes

Viewing 7 reply threads
  • Author
    Posts
    • #199019
      Participant
      Topics: 1
      Replies: 3
      Points: 21
      Rank: Member

      Hello all,

       

      I’m extremely new to powershell and I’ve been trying to add a delay to a macro command string with no luck. the command runs extremely fast and I want to add a tiny delay to it to at least see it for a sec or two. I’m working on a .csv file and I’ve figured out what I need to do so far with the exection of making it run a little slower. Is this even possible and if so what command should I used for this? TIA

    • #199022
      Participant
      Topics: 1
      Replies: 3
      Points: 21
      Rank: Member

    • #199025
      Senior Moderator
      Topics: 8
      Replies: 1169
      Points: 4,100
      Helping Hand
      Rank: Community Hero

      It would help us understand the problem much better if you can share your code or a sample code here.

    • #199028
      Participant
      Topics: 1
      Replies: 3
      Points: 21
      Rank: Member
      Window Macro Description
      C:\Program Files (x86)\Google\Chrome\Application\chrome.exe http://www.google.com~{CTRL}(W) 7.10 Chrome1-Macro

       

      This is what it looks like so far, I just want to add the pause or delay before it closes the window. Is this posible?

      • This reply was modified 1 month, 1 week ago by newb0178.
    • #199034
      Participant
      Topics: 2
      Replies: 1780
      Points: 3,735
      Helping Hand
      Rank: Community Hero

      Please share your Powershell code. Use the code tag button (“PRE”) to format it as code, please.

    • #199091
      js
      Participant
      Topics: 28
      Replies: 760
      Points: 2,140
      Helping Hand
      Rank: Community Hero

      You could use Autoit instead.

    • #199250
      Participant
      Topics: 4
      Replies: 51
      Points: 102
      Helping Hand
      Rank: Participant

      You might want to review Get-Help Start-Sleep

    • #199523
      Participant
      Topics: 1
      Replies: 3
      Points: 21
      Rank: Member
      #region Script Methods
      
      <#
      Description : Create runtime object collection from CSV data
      Input(s) : CSV Object
      Output(s) : Object array
      #>
      Function Import-MacroData([Object[]]$CSVData)
      {
      [Object[]]$OutData = @()
      $CSVData | ForEach-Object {
      [String]$Window = $_.Window
      [String]$Description = $_.Description
      [String]$pausePattern = '\{Pause.*?\}'
      
      if ($_.Macro -notmatch $pausePattern)
      {
      #Add macro that does not contain any pauses
      $OutData += Add-DataObject -Window $Window -RawMacro $_.Macro -Macro (ConvertTo-SendKeyString -InputString $_.Macro) -Description $Description
      }
      else
      {
      [String[]]$sMacro = $_.Macro -split $pausePattern
      [System.Text.RegularExpressions.MatchCollection]$pauses = [RegEx]::Matches($_.Macro, '\{Pause.*?\}')
      if ($_.Macro.Trim() -match '^\{Pause.*?\}$')
      {
      #Add single pause macro
      $OutData += Add-DataObject -Window $Window -RawMacro $_.Macro.Trim() -Macro (Get-PauseDuration -InputString $_.Macro.Trim()) -Description $Description -Pause
      }
      else
      {
      [Int]$count = $count = $sMacro.Count - 1
      for ([Int]$i = 0; $i -le $count; $i++ )
      {
      [String]$macro = $sMacro[$i]
      if (($i -gt 0) -and ($i -lt $sMacro.Count))
      {
      #Add pause macro after first non-pause macro and before preceeding macros
      [String]$pause = $pauses[$i-1].Value
      $OutData += Add-DataObject -Window $Window -RawMacro $pause -Macro (Get-PauseDuration -InputString $pause) -Description $Description -Pause
      $OutData += Add-DataObject -Window $Window -RawMacro $macro -Macro (ConvertTo-SendKeyString -InputString $macro) -Description $Description
      }
      else
      {
      #Add before pause macros and after pause macros
      $OutData += Add-DataObject -Window $Window -RawMacro $macro -Macro (ConvertTo-SendKeyString -InputString $macro) -Description $Description
      }
      }
      }
      
      }
      }
      $OutData
      }
      
Viewing 7 reply threads
  • You must be logged in to reply to this topic.