From 6767b7567cca181441dec04129c782a92eee970a Mon Sep 17 00:00:00 2001 From: Kevin Lukritz Date: Mon, 9 Nov 2020 10:31:14 -0600 Subject: [PATCH] Should work --- KeyPresser.ps1 | 75 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 25 deletions(-) diff --git a/KeyPresser.ps1 b/KeyPresser.ps1 index 4e70e4a..a7b2aa2 100644 --- a/KeyPresser.ps1 +++ b/KeyPresser.ps1 @@ -1,20 +1,27 @@ #region Header + $Version = "1.0.0" + #Dependencies - [Reflection.Assembly]::LoadWithPartialName("System.Windows/Forms") | Out-Null + [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName PresentationFramework #Hide Console Window Add-Type -Name Window -Namespace Console -MemberDefinition ' - [DllImport("Kernal32.dll")] + [DllImport("Kernel32.dll")] public static extern IntPtr GetConsoleWindow(); [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow); ' + $consolePtr = [Console.Window]::GetConsoleWindow() + [Console.Window]::ShowWindow($consolePtr, 0) > $null + + + #Talking across runspaces $Sync = [Hashtable]::Synchronized(@{}) @@ -27,29 +34,17 @@ $script = [Powershell]::Create().AddScript({ Param ($Keys) - - $sleep = ".5" - while($X -eq $null){ - sleep $sleep - [System.Windows.Forms.SendKeys]::SendWait("{4}") - sleep $sleep - [System.Windows.Forms.SendKeys]::SendWait("{3}") - sleep $sleep - [System.Windows.Forms.SendKeys]::SendWait("{2}") - sleep $sleep - [System.Windows.Forms.SendKeys]::SendWait("{3}") - sleep $sleep - [System.Windows.Forms.SendKeys]::SendWait("{1}") - sleep $sleep - [System.Windows.Forms.SendKeys]::SendWait("{3}") - sleep $sleep - [System.Windows.Forms.SendKeys]::SendWait("{5}") - sleep $sleep - [System.Windows.Forms.SendKeys]::SendWait("{3}") + + while($sync["x"] -eq 1){ + $keys = $keys -split "," + Foreach ($key in $keys){ + Start-Sleep -Milliseconds 500 + [System.Windows.Forms.SendKeys]::SendWait("{$key}") + } } }).AddArgument($Keys) - $runsapce = [RunspaceFactory]::CreateRunspace() + $runspace = [RunspaceFactory]::CreateRunspace() $runspace.ApartmentState = "STA" $runspace.Threadoptions = "ReuseThread" $runspace.open() @@ -65,12 +60,42 @@ #region Form $form = New-Object System.Windows.Forms.Form - $form.text = "Keypresser" - $Form.Size = "500,500" + $form.text = "Keypresser Version $Version" + $Form.Size = "450,110" + $Form.FormBorderStyle = 'FixedDialog' + $form.TopMost = $True $Form.Add_FormClosing({Get-Process -id $pid | Stop-Process}) + $KeysLabel = New-Object 'System.Windows.Forms.Label' + $KeysLabel.text = "Enter in the keys you wish to be pressed seperated by a comma `",`"" + $KeysLabel.Width = '425' + $KeysLabel.Location = New-Object System.Drawing.Point(5,5) + $form.controls.add($KeysLabel) + $KeysTextBox = New-Object 'System.Windows.Forms.TextBox' + $KeysTextBox.Location = New-Object System.Drawing.Point(5,25) + $KeysTextBox.Width = '425' + $form.controls.add($KeysTextBox) + $KeysButton = New-Object 'System.Windows.Forms.Button' + $KeysButton.Location = New-Object System.Drawing.Point(5,45) + $KeysButton.text = "Start" + $KeysButton.add_click({ + if ($KeysButton.text -ne "Stop"){ + $KeysButton.text = "Stop" + $sync["x"] = 1 + $Keys = $KeysTextBox.text + Keypress $Keys + } + Else{ + $KeysButton.text = "Start" + $sync["x"] = 0 + } -#endregion Form \ No newline at end of file + }) + $form.controls.add($KeysButton) + +#endregion Form + +[Windows.Forms.Application]::Run($form) \ No newline at end of file