AutoHotkey Community

It is currently May 24th, 2012, 3:15 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: January 16th, 2006, 12:49 am 
Offline

Joined: January 27th, 2005, 3:28 pm
Posts: 120
Location: Germany, Dresden
Edit (Dec. 2009): There's a new version in the German Forum . Enjoy!
Halwegs Fensterpflege ("Halwegs Window Care")

(Sorry, still in German :? )

Here are the keys to control Halwegs Fensterpflege:
SCROLLLOCK - record data from the actual window to create a new "care instruction" / Start a care procedure that needs a trigger (when caretime is set to 9999)
WIN-SCROLLLOCK - Manage care instructions
SHIFT-WIN-SCROLLLOCk - Reset all windows, so Window Care will think they are new.
F9 - reactivate/close tool tips


Older stuff:


Edit: A window specific time delay before sending the key sequence was added.

Use this script in order to kill dialog boxes and make automatic logins.

Here's how it works:
A timer examines every 200 milliseconds if a new window appears and in this cases compares it with stored samples. If the window title matches a saved before title string and the window text (WINGETTEXT) contains a saved before text string a key sequence stored before is sent. A couple of tool tips and beeps illustrate the scripts work. That's all.

The more challenging part was the automated collection of samples (by SCROLLLOCK-Key, pressed when a new dialog box is open). The dialog box should be recognized reliable, so there must be both a title match and a text match. To get a text match string the script sends the actual window text (WINGETTEXT) to a notepad window. So the user can select a part of that text in order to make a matching string.
Sometimes it's difficult to find the differences between the window texts of dialog boxes inside the same application. In this case it's recommended to use the Window Spy.

I'm sure there is some optimization potential …
Code:
; AutoHotkey Version: 1.0.40.11
; Language:       English
; Platform:       WinXP
; Author:         halweg
; Send keysequences to dialog boxes

;**************************************************************************************
;******************************* Initialization ***************************************
;**************************************************************************************

;!!! Change the next two lines as required !!!
inifile = %A_MYDOCUMENTS%\Hotkey-Skripte\komforteingabe.ini
title_of_a_new_notepad_window = Unbenannt - Editor

COORDMODE, TOOLTIP, SCREEN
SETTITLEMATCHMODE, 1
DETECTHIDDENTEXT, ON

;*** Read saved keysequences
number_of_dialogs := my_iniread("Dialoge", "Number_of_dialogs")
LOOP, %number_of_dialogs%
  {
  wtitle%A_INDEX% := my_iniread("Dialoge", "Title" . A_INDEX)
  wtext%A_INDEX% := my_iniread("Dialoge", "Text" . A_INDEX)
  wkeys%A_INDEX% := my_iniread("Dialoge", "Keys" . A_INDEX)
  }

;*** Start the dialog-watching
last_id = leer
SETTIMER, handle_dialog_boxes, 200
RETURN


;**************************************************************************************
;*************************** Timed dialogbox handler **********************************
;**************************************************************************************
handle_dialog_boxes:
;*** It's time so look for new active windows
new_id := WINACTIVE("A")
IF new_id <> %last_id%
  {
  last_id =%new_id%
  ;*** A new window was found - Now: Compare the active window's title with all saved titles one by one
  LOOP, %number_of_dialogs%
    {
    IF WINACTIVE(wtitle%A_INDEX%)
      {
      keys_to_send := wkeys%A_INDEX%
      title_to_watch := wtitle%A_INDEX%
      text_to_watch := wtext%A_INDEX%
      ;*** Window title found - Now: Does it contain the right text?
      WINGETTEXT, act_wintext, A
      IFINSTRING, act_wintext, %text_to_watch%
        {
        ;*** The text is ok - Now: Do we need a SLEEP?
        IFINSTRING, keys_to_send, SLEEP
          {
          STRINGLEFT, sleeptime, keys_to_send, 4
          STRINGTRIMLEFT, keys_to_send, keys_to_send, 9
          SLEEP, %sleeptime%
          }
        ;*** SLEEP was done - Now: Send the keys
        my_beeps(2, 70)
        timed_tooltip("Sending """ . keys_to_send . """", 2000)
        SEND, %keys_to_send%
        ;*** Keys was sent - Now: Watch the dialogbox disappears
        WINWAITCLOSE, %title_to_watch%, %text_to_watch%, 2
        IF ERRORLEVEL = 1
          MSGBOX, No success!`nThe actual Window couldn't be handled by ""%keys_to_send%""
        }
     }
    }
  }

RETURN

;**************************************************************************************
;************************* Registration of a new dialog-handling keysequence **********
;**************************************************************************************
SCROLLLOCK::
my_beeps(1, 70)

;*** 1. Analyse the current active window (dialogbox to be registered)
WINGETTITLE, new_title, A
WINGETTEXT, all_window_text, A

;*** 2. User should select a significant piece of text from the dialogbox window by notepad
CLIPBOARD =
RUN notepad.exe
WINWAITACTIVE, %title_of_a_new_notepad_window%
SETKEYDELAY, -1
SEND, %all_window_text%
SETKEYDELAY, 10
MSGBOX, Plese select (by mouse) a significant piece (maximum one line) of text to identify the dialogbox in future`nThen press OK
SEND, ^c
new_text = %CLIPBOARD%
;*** Close notepad without changes
SEND, !{BS}!{F4}

;*** 3. User should input the keysequence for future handling of the dialogbox
INPUTBOX, new_keys, Dialog-Box Handler for %new_title%,
(
Please enter a keyssequence that should handle this dialogbox in future. Use AHK - codes.
If the dialogbox needs a delay, include a SLEEP time in ms.
EXAMPLES:
my_name{TAB}my_password{ENTER}
2500SLEEP{TAB}1234{ENTER}
)
IF ERRORLEVEL = 0
  {
  IF new_keys =
    MSGBOX, Please Enter at least one key!
  ELSE
    {      

;*** 4. Test the new keysequence, ask if the dialogbox was handled successful
    WINACTIVATE, %new_title%
    keys_to_send = %new_keys%   
    IFINSTRING, new_keys, SLEEP
      {
      STRINGLEFT, sleeptime, new_keys, 4
      STRINGTRIMLEFT, keys_to_send, new_keys, 9
      SLEEP, %sleeptime%
      }
    my_beeps(2, 70)
    timed_tooltip("Sende" . keys_to_send, 5000)
    SEND, %keys_to_send%
    MSGBOX, 36, Successful dialogbox handling?, Save new Keysequence?
    IFMSGBOX, Yes
      {

;*** 5. Save dialogbox data
      new_number_of_dialogs := number_of_dialogs + 1

      INIWRITE, %new_number_of_dialogs%, %inifile%, Dialoge, Number_of_dialogs
      INIWRITE, %new_title%, %inifile%, Dialoge, Title%new_number_of_dialogs%
      INIWRITE, %new_text%, %inifile%, Dialoge, Text%new_number_of_dialogs%
      INIWRITE, %new_keys%, %inifile%, Dialoge, Keys%new_number_of_dialogs%

;*** 6. Enable the handling of the new dialogbox in the current script
      wtitle%new_number_of_dialogs% := new_title
      wtext%new_number_of_dialogs% := new_text
      wkeys%new_number_of_dialogs% := new_keys
      number_of_dialogs := new_number_of_dialogs        ;*** Enable the Dialogwatching of the new registred dialogbox
      timed_tooltip("The Window """ new_title """`nText """ new_text """`nin future will be handled by """ new_keys """",5000)
      my_beeps(1, 500)
      }
    }
  }
RETURN

;**************************************************************************************
;********************************** Functions  ****************************************
;**************************************************************************************

;*** This function makes a number of beeps
my_beeps(number, duration)
{
  LOOP, %number%
    {
    SOUNDBEEP, 650, %duration%
    SLEEP, 50
    }
}

;*** This function shows a tooltip and will close it later
timed_tooltip(text, milliseconds=2000)
{
  TOOLTIP, %text%, 0, 0
  SETTIMER, close_tooltip, %milliseconds%
}
close_tooltip:              ;*** Closes the standard tooltip
SETTIMER, close_tooltip, Off
TOOLTIP
RETURN

;*** This function reads a value from the inifile and will finish the script if ERROR value detected
my_iniread(m_section, m_key)
{
  global inifile
  INIREAD, m_value, %inifile%, %m_section%, %m_key%
  IF m_value = ERROR
    {
    MSGBOX, An Error was encountered while reading inifile`nKey: %m_key%
            ,`nsection:%m_section%
            ,`nfile:%inifile%
    EXITAPP
    }
  ELSE
    RETURN %m_value%
}


The samples are stored in an ini-file like this:
Code:
[Dialoge]
Number_of_dialogs=2
Title1=System-PIN
Text1=System-PIN speichern?
Keys1=1234{TAB} {ENTER}
Title2=Sonic RecordNow!
Text2=&Nein
Keys2=n


Last edited by halweg on December 18th, 2009, 1:28 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 18th, 2006, 12:52 pm 
Offline

Joined: January 27th, 2005, 3:28 pm
Posts: 120
Location: Germany, Dresden
I found some bugs, now they are removed. 8)

The script works fine, it saves me a lot of clicks and inputs. :D
The last 3 days I found over a dozen dialogs to "kill". Whenever I close the script I feel myself like a windows beginner doing some very stupid things :x


Last edited by halweg on January 18th, 2006, 6:13 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 18th, 2006, 5:50 pm 
Offline

Joined: November 8th, 2004, 12:46 am
Posts: 1271
Hi halweg, I've always thought AutoHotkey would be perfect for this kind of thing. I tried your script but I get an error message saying:

Quote:
An Error was encountered while reading inifile
Key: Number_of_dialogs,
section:Dialoge,
file:settings.ini

_________________
"Anything worth doing is worth doing slowly." - Mae West
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 18th, 2006, 6:08 pm 
Offline

Joined: January 27th, 2005, 3:28 pm
Posts: 120
Location: Germany, Dresden
Hi Serenity. I'm happy you try the script out.
There seems to be some problems with the ini-file:
Or the file or the section or the key or the value are not properly prepared.
See example in my post.
To start try an inifile like this:
Code:
[Dialoge]
Number_of_dialogs=0

Don't forget to customize the two lines at the begin of the script.
Halweg


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 18th, 2006, 6:48 pm 
Offline

Joined: November 8th, 2004, 12:46 am
Posts: 1271
Thanks, I added this to the top of your script so that the ini file is created if it doesn't exist:

Code:
setworkingdir, %A_ScriptDir%
ifnotexist, %inifile%
  fileappend, [Dialoge]`nNumber_of_dialogs=0, %inifile%

_________________
"Anything worth doing is worth doing slowly." - Mae West
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 18th, 2006, 7:12 pm 
Offline

Joined: January 27th, 2005, 3:28 pm
Posts: 120
Location: Germany, Dresden
Thanks. The inifile is still the weakest point of the script.
It may happens that you must remove a bad registred dialogbox sample. Some annoying renumbering will be required. :x
That's why I'll keep some focus to the inifile, that user should be abel to find and edit it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2007, 2:21 pm 
the script is very cool.

but how do I write the below command in the dialogbox?:

send, name
send{ENTER}
sleep, 500
send{TAB}


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2007, 3:16 pm 
Offline

Joined: January 27th, 2005, 3:28 pm
Posts: 120
Location: Germany, Dresden
This is still not possible in the above shown script.
But a workaround could be possible: if the dialogbox to handle changes it's text information after the {ENTER} (gathered by wingettext) this would be detectable by the script as a new dialog situation with the possibility of using the Sleep feature.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 29th, 2007, 11:27 pm 
Offline

Joined: August 29th, 2007, 11:22 pm
Posts: 1
THIS IS GREAT!

I suggest adding one more thing. Keyboard and Mouse lockout. That way users can't mess around while an installation or something is going on.

This works great for those Driver Signing prompts!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 23rd, 2008, 4:58 pm 
I recovered just your great script. I am using it with my laptop. Unfortunately the intern sound of my laptop is very loud. How could I stop the repeatingly peep sound if the script detects an appropriate window?

And even though the sending of a keystoke was succesfull I will get the message: "No success! The actuall window couldnt be handled by "{enter}"


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2008, 4:18 pm 
Good script. This auto-close popup dialog is what I'm looking for.
Why?
Here, we have to run a kind of safety agent program before connecting to Internet. This program will shutdown the network connection if the socket- or some-kind-of- connections (sorry, that is not my major) are to much. A Warning dialog will popup and have to be closed before the computer can access to internet again. Therefore, during unmanned running, some downloading tools, eg. bitorrent tools or emule, can be blocked from the net. This script can close the warning dialog right after it appears.

But...
This script detects a new dialog/window that steals the focus. So, it won't work on those popups that do not take the focus, for example, the warning popup I want to kill here. When change the focus to my target using Alt-Tab, this script works very well.

Solution
I close all dialog/window before the unmanned downloading. When the Warning popup, aimed with Alt-Tab, this script shoots it down. After that, no window should be opened, or the focus will change. If the warning showup again, it will automatically come into focus and be closed. This may not be the best solution, but at least it works for the time being.

Ye


Report this post
Top
  
Reply with quote  
PostPosted: January 30th, 2008, 4:23 pm 
Write them on one line with | for newline, then loop parse for | in the code


Report this post
Top
  
Reply with quote  
 Post subject: Easier Solution
PostPosted: March 3rd, 2008, 8:17 pm 
From: http://www.autohotkey.com/docs/commands/SetTimer.htm


; Example #1: Close unwanted windows whenever they appear:
#Persistent
SetTimer, CloseMailWarnings, 250
return

CloseMailWarnings:
WinClose, Microsoft Outlook, A timeout occured while communicating
WinClose, Microsoft Outlook, A connection to the server could not be established
return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 3rd, 2008, 10:11 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1832
you might be able to improve this by using:

Code:
DllCall("RegisterShellHookWindow", "UInt", hwnd)
MsgNum := DllCall("RegisterWindowMessage", "Str", "SHELLHOOK")


instead of checking every 200ms. search the forums for others that have made versions that use this instead


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 1st, 2008, 6:36 pm 
Offline

Joined: April 30th, 2006, 6:23 pm
Posts: 358
Location: Shigle Springs
halweg, GREAT script, well thought out.

Mr. Tic is right.. Loops and stuff are heavy.. Shellhook is light.
http://www.autohotkey.com/forum/viewtop ... 323#123323
Code:
Gui +LastFound
hWnd := WinExist()

DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )

Return ;                                                 // End of Auto-Execute Section //

ShellMessage( wParam,lParam ) {
  If ( wParam = 4 ) ;  HSHELL_WINDOWACTIVATED
     {
       WinGetTitle, Title, ahk_id %lParam%

       If InStr( Title, "fire" )
          SetTimer, fire, -1

       If InStr( Title, "notepad" )
          SetTimer, notepad, -1

     }
}


fire:
 msgbox, fire
return

notepad:
 msgbox, Notepad
return


For IE and FF titles that change, replace
Code:
   If ( wParam = 4 ) ;  HSHELL_WINDOWACTIVATED
with this
Code:
 if Wparam in 1,4,6
for better results.


SKAN is a god!

_________________
CPULOCK.com
virusSWAT.com
Computer Repair Computer Service.com
911PCFIX.com


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Exabot [Bot], sks and 26 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group