henryliangt / usyd

0 stars 0 forks source link

hotkey combo key #35

Open henryliangt opened 1 year ago

henryliangt commented 1 year ago

RunCopynPaste.bat

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%cd%\CopynPaste.ps1'"

pause

exit

CopynPaste.ps1

Write-Host ""
Write-Host "Listening Started..." -ForegroundColor Red
Write-Host ""

$code = @'
    [DllImport("user32.dll")]
     public static extern IntPtr GetForegroundWindow();
'@
Add-Type $code -Name Utils -Namespace Win32
while(1){

    $CValue1 = Get-Clipboard

    $hwnd = [Win32.Utils]::GetForegroundWindow()

    if((Get-Process | 
        Where-Object { $_.mainWindowHandle -eq $hwnd } |
        Select-Object processName, MainWindowTItle, MainWindowHandle).MainWindowTItle -like "*word*"){

        if($CValue1 -ne $CValue2){

        [void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
        [System.Windows.Forms.SendKeys]::SendWait("^{v}")

            Write-Host "The text '$CValue1' has Pasted on Word." -ForegroundColor Green

        }

        $CValue2 = Get-Clipboard

        }else{

        #"Waiting"

        }

      #Start-Sleep -Milliseconds 0.5

}
henryliangt commented 1 year ago

SendComboKey.bat

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%cd%\SendComboKey.ps1'"

pause

exit

SendComboKey.ps1

Write-Host ""
Write-Host "Combo hot keys Listening Started..." -ForegroundColor Red
Write-Host ""

$key  = [Byte][Char]' ' ## Letter
$key2 = '0x11' ## Ctrl
$key3 = '0x12' ## Alt 
$Signature = @'
    [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)] 
    public static extern short GetAsyncKeyState(int virtualKeyCode); 
'@
Add-Type -MemberDefinition $Signature -Name Keyboard -Namespace PsOneApi
do
{   If( [bool]([PsOneApi.Keyboard]::GetAsyncKeyState($key) -eq -32767 -and 
        [PsOneApi.Keyboard]::GetAsyncKeyState($key2) -eq -32767 -and 
        [PsOneApi.Keyboard]::GetAsyncKeyState($key3) -eq -32767))
        { 

        Write-Host "The hotkeys Ctrl + Alt + Space has been pressed." -ForegroundColor Green

        [void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
        [System.Windows.Forms.SendKeys]::SendWait("{F1}")
        Write-Host "F1 key pushed to current active window." -ForegroundColor Green

        Start-Sleep -Milliseconds 100
        Write-Host "Start Sleep 0.1 s" -ForegroundColor Green

        [void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
        [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
        Write-Host "Enter key pushed to current active window." -ForegroundColor Green

        $ClipBoard = Get-Clipboard
        $ClipArray= $ClipBoard.Split(" ")
        Set-Clipboard -Value $ClipArray[0]
        [void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
        [System.Windows.Forms.SendKeys]::SendWait("^{v}")
        Write-Host "Get Clipboard to array and first word pushed to current active window." -ForegroundColor Green

        [void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
        [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
        Write-Host "Enter key pushed to current active window." -ForegroundColor Green

        Write-Host ""

        }

      Start-Sleep -Milliseconds 1

} while($true)