Sign in to follow this  
Followers 0
gte

Script I wrote to sendkeys to windows that have to be active to accept the keystrokes

1 post in this topic

#1 ·  Posted (edited)

keywords for search: controlsend not working controlsend active window non active window

What this code does is look for title and text to match the proper window the keys need sent to. I could have used cases, but I think it's easier to understand this way. This is my first script I'm posting, so I'm sure it could be improved, but I hope it helps someone. I am using it in the case for peregrine software.

If it's minimized, it sets the transparency to 0, then brings it to the foreground and activates it, sends the key strokes, minimizes it again, and then brings transparency back to it

If it's in the foreground and active, it leaves it there and sends keystrokes

If it's not minimized, but in the background, it sets transparency to 0, activates it, sends keys, restores it back by reactivating the previous window and then brings transparency back

#include <GUIConstantsEx.au3>
#include <Timers.au3>
#include <Array.au3>

Opt("WinTitleMatchMode", 1)
Opt("SendKeyDelay", 50)

While 1

If ProcessExists('scguiw32.exe') Then
    
    If _Timer_GetIdleTime () <= "5000" Then
        Sleep(2000)
        
    Else
    
    $originalwindow = WinGetState("ServiceCenter - [Incident", "Incident Queue:")
    If $originalwindow < 8 OR $originalwindow > 15 Then 
        $activewindow = WinGetHandle("[active]")
        WinSetTrans ("ServiceCenter - [Incident", "Incident Queue:", 0)
        EndIf
    
        WinActivate("ServiceCenter - [Incident", "Incident Queue:")
        
    If $originalwindow < 16 Then 
        do 
        Until _Timer_GetIdleTime () >= "5000"
        Sleep(250)
        EndIf
    
    If $originalwindow > 15 Then
        WinSetState("ServiceCenter - [Incident", "Incident Queue:",@SW_RESTORE)
    EndIf   

    sleep(100)
    
        $winposition = WinGetPos("ServiceCenter", "Incident Queue:")
        $array = _ArrayToString($winposition, @CRLF, 0)
        $array2 = StringSplit($array, @CRLF)

        $originalXaxis = $array2[1]
        $originalYaxis = $array2[3]

    If $originalwindow > 15 Then
    WinMove("ServiceCenter - [Incident", "Incident Queue:", 2700, 102)
    EndIf

    Sleep(250)
            
    ControlSend("ServiceCenter - [Incident", "Incident Queue:", "xSC4550child05", "!P")
    
    ControlSend("ServiceCenter - [Incident", "Incident Queue: ", "xSC4550child05", "r")
    
    sleep(100)
    If $originalwindow > 15 Then
    WinMove("ServiceCenter - [Incident", "Incident Queue:", $originalXaxis, $originalYaxis)
    EndIf
    Sleep(500)
    
    if $originalwindow > 15 Then
    WinSetState("ServiceCenter - [Incident", "Incident Queue:", @SW_MINIMIZE)
    EndIf
    Sleep(500)
    
    if $originalwindow < 8 OR $originalwindow > 15 then 
        WinActivate($activewindow)
        EndIf
    Sleep(500)
    
    WinSetTrans ("ServiceCenter - [Incident", "Incident Queue:", 255 )
        
    Sleep(5000)
    
    EndIf

Else
    
    Sleep(15000)
    
EndIf

WEnd
Edited by gte

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0