AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

controlsend/ loop script

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
suoabb



Joined: 08 Dec 2009
Posts: 30

PostPosted: Thu Mar 11, 2010 1:24 am    Post subject: controlsend/ loop script Reply with quote

i've been working on a script for work for reprinting labels but i seem to be having some problems. i red through alot of post and got pretty far.

Code:
F1::
winName = Reprint Label ;child win name inside specimen main window
appName = Specimen ;main window with multiple child windows
WinGet, conList, ControlListHwnd, % appName
Loop, Parse, conList, `n
{
    curHwnd := A_Loopfield
    WinGetTitle, curWin, ahk_id %curHwnd%
    CoordMode, Tooltip, Screen
        if (curWin = winName)
                Break
}
WinSet, Top,, % "ahk_id " curHwnd
;is there a way to make it so that if the reprint label window is not active in specimen window than it allows me to send keystroke to open that window  under specimen window? i need it done in the background (NA style) or just msgbox that reprint label window is not open. i've tried but didn't work out.
Loop
{
IfWinNotExist Specimen
MsgBox, Specimen window not active
Else
IfWinExist Specimen
Inputbox,CID,Please enter CID to reprint,,,,100 ;i need this always on top
If ErrorLevel ;end loop also how can i make it so that if the value is empty(press enter without entering any numbers to inputbo), that it will also end the loop
{
   break
}
Else
DetectHiddenWindows, On
ControlSendRaw,Edit1,%CID%,Specimen Management Routing and Tracking
ControlClick,Button6,Specimen,,,,NA
;i need to add that if a window call SMART(an error message) come up than to activate that window and also end loop
;else continue loop
Winwait,Printer Select,,,,4
ControlClick,Button1,Printer Select,,,,NA
}
Return



i been working on it for a week now and just would really appreciate any help. i've tried to work on those thing i am asking help on, but it never seem to work the way i want it to.
Back to top
View user's profile Send private message
jl34567



Joined: 03 Jan 2010
Posts: 262

PostPosted: Thu Mar 11, 2010 5:50 am    Post subject: Reply with quote

Try this......not tested.
To make sure specimen is open:
Code:
IfWinNotExist, Specimen Window Title
run, c:\whatever the path is\specimen.exe
WinWaitExist, Specimen Window Title


To alert that window smart exists:
Code:

IfWinExist, SMART
  {
  MsgBox, SOME TEXT
  WinActivate, SMART
  Break
  }
Back to top
View user's profile Send private message AIM Address
suoabb



Joined: 08 Dec 2009
Posts: 30

PostPosted: Thu Mar 11, 2010 9:14 am    Post subject: Reply with quote

well specimen window is open from another application so there is no specimen.exe.
i am not to worry about that part but rather the other part of the script like how to tell if the child window "reprint label" is active
Back to top
View user's profile Send private message
jl34567



Joined: 03 Jan 2010
Posts: 262

PostPosted: Thu Mar 11, 2010 4:27 pm    Post subject: Reply with quote

suoabb wrote:
well specimen window is open from another application so there is no specimen.exe.
i am not to worry about that part but rather the other part of the script like how to tell if the child window "reprint label" is active


Active or exists? 2 totally different ideas there.

If you mean exists.
Code:
IfWinExist, Program name
  IfWinNotExist, Print Label
    ControlSend/ControlClick/WinMenuSelectItem????


http://www.autohotkey.com/docs/commands.htm
Back to top
View user's profile Send private message AIM Address
suoabb



Joined: 08 Dec 2009
Posts: 30

PostPosted: Thu Mar 11, 2010 5:55 pm    Post subject: Reply with quote

i mean exist, because i am trying to make all the script work in the background. that is why i use the script
Code:

WinSet, Top,, % "ahk_id " curHwnd


so it set that Reprint Label window on top of all other windows open in the main Specimen window and not active it
sorry for the confusion
Back to top
View user's profile Send private message
jl34567



Joined: 03 Jan 2010
Posts: 262

PostPosted: Thu Mar 11, 2010 6:36 pm    Post subject: Reply with quote

If it exists, I don't see why it needs to be on top.....ControlSend/ControlClick should take care of everything you need......How do you open the window you need? Is it a button? Is it in a drop down menu?
Back to top
View user's profile Send private message AIM Address
suoabb



Joined: 08 Dec 2009
Posts: 30

PostPosted: Fri Mar 12, 2010 1:50 pm    Post subject: Reply with quote

my post is similar to this post http://www.autohotkey.com/forum/topic55080.html&highlight=selectsubwin
i need that reprint label window on the top because the classNN of the field that i want to controlsend to change depending on if it is the top or behind other window in the specimen main window. i will upload some pictures.
maybe that will give you a better idea.
i am not too good at explaining.
the reprint label window is open in a drop down menu.
Back to top
View user's profile Send private message
TLM



Joined: 21 Aug 2006
Posts: 2926
Location: The Shell

PostPosted: Fri Mar 12, 2010 3:32 pm    Post subject: Reply with quote

I see your adopting some of my code so I will try to help you out.

I did wrap the whole thing into a somewhat stable function (NOTE: there is no error checking!!).
Sending a call to it should bring the child window to the front as long as it is not maximized in an app.
Code:
; Static subwindow calls.
SelectSubWin("PIC1.jpg","Microsoft Photo Editor") ; Call 1
SelectSubWin("Text2","Microsoft Visual C++") ; Call 2

SelectSubWin(wN,aN){
    WinGet, conList, ControlListHwnd, % aN
    Loop, Parse, conList, `n
    {
        WinGetTitle, cW, % "ahk_id " curHwnd := A_Loopfield
            if (cW = wN)
                    Break
    }
    WinActivate, % aN
    WinActivate % "ahk_id " curHwnd
}
Another thing to consider is to send a query followed by a condition to figure out exactly what window/control is in front. Something like ControlGetFocus would suffice.

Go ahead and post some pictures anyway as it will help gain a better idea of exactly how your application windows are setup.

hth


edit

TLM wrote:
Sending a call to it should bring the child window to the front as long as it is not maximized in an app.

Actually I just tested this on maximized child windows and it still works Shocked! So scrub what I said eariler.
_________________
paradigm.shift:=(•_•)┌П┐RTFM||^.*∞
Back to top
View user's profile Send private message
suoabb



Joined: 08 Dec 2009
Posts: 30

PostPosted: Fri Mar 12, 2010 11:51 pm    Post subject: Reply with quote

okay here is a picture i took and edit, hope this help out, i have more pictures but let me take care of this first.



Back to top
View user's profile Send private message
suoabb



Joined: 08 Dec 2009
Posts: 30

PostPosted: Sun Mar 21, 2010 1:18 pm    Post subject: Reply with quote

i haven't got a chance to work on the script, any new input on how to get my script working, i put the pix up hope that help
Back to top
View user's profile Send private message
TLM



Joined: 21 Aug 2006
Posts: 2926
Location: The Shell

PostPosted: Sun Mar 21, 2010 5:00 pm    Post subject: Reply with quote

What does the classNN change to when the sub window is behind others?
Did you try my function to bring Reprint Label to the front?
It should look something like this:
Code:
SelectSubWin("Reprint Label","Specimen **enter full name**") ; add the rest of the Specimen name.

SelectSubWin(wN,aN){
    WinGet, conList, ControlListHwnd, % aN
    Loop, Parse, conList, `n
    {
        WinGetTitle, cW, % "ahk_id " curHwnd := A_Loopfield
            if (cW = wN)
                    Break
    }
    WinActivate, % aN
    WinActivate % "ahk_id " curHwnd
}
This should only bring the window to the front.
You still have to add a controlclick to press the Reprint button.

Another approach that may be more reliable is to use WM_COMMAND data and use it with postmessage to Reprint (if there is one). Then you don't have worry about the sub window position.

Look here for a tutorial on how to get the WM_COMMAND for postmessage with Winspector: http://www.autohotkey.com/docs/misc/SendMessage.htm
_________________
paradigm.shift:=(•_•)┌П┐RTFM||^.*∞
Back to top
View user's profile Send private message
suoabb



Joined: 08 Dec 2009
Posts: 30

PostPosted: Mon Mar 22, 2010 12:04 pm    Post subject: Reply with quote

if there is another window open on top of the Reprint Label window and have 4 box you can input than the input box next to the CID: text will become Edit5. so it depend on how man window is on top of the reprint label window and how many editable box exist.

yes i manage to get the Reprint Label window to be on the top, but if that reprint label does not exist it kinda make the script act weird.
that is why i need to make it so if the Reprint Label does not exist to controlsend/click the tab to open it than run the rest of the script

if Reprint Label is active it works perfectly unless i get an error when i send the inputbox to Edit1 box. ControlClick/ControlSendRaw works.

i use ur script from that post i mention earlier, and it really helped me out alot.

i just need to set how the script act if the script i send create an error with the Specimen/Reprint Label window.
Back to top
View user's profile Send private message
TLM



Joined: 21 Aug 2006
Posts: 2926
Location: The Shell

PostPosted: Mon Mar 22, 2010 3:45 pm    Post subject: Re: controlsend/ loop script Reply with quote

If I'm reading you correct, you need to check if Reprint exists. If it does click Reprint.

Code:
F1::
winName = Reprint Label ;child win name inside specimen main window
appName = Specimen ;main window with multiple child windows
WinGet, conList, ControlListHwnd, % appName
Loop, Parse, conList, `n
{
   curHwnd := A_Loopfield
   WinGetTitle, curWin, ahk_id %curHwnd%
   CoordMode, Tooltip, Screen
   if (curWin = winName)
   {
   ; if you need to change the Reprint label Edit boxes.
   controlsettext, **control name for CID**, new text, ahk_id %curHwnd%
   controlsettext, **control name for Acc #:**, new text
   ; the same for all other Edit controls you want to change.

   ; sleep, 100 ; may not need this.

   ; Read whats in the Edit boxes for multi condition.
   ; controlgettext, eb1Txt, **control name for CID**
   ; controlgettext, eb2Txt, **control name for Acc #:**

   ; then press Reprint (button6) while its open.
   while (winexist("ahk_id " curHwnd))
      controlclick, button6, ahk_id %curHwnd%

   ; Or use multiple conditions in the expression:
   ; while (winexist("ahk_id " curHwnd) || (eb1Txt = "**new text**") || (eb2Txt = "**new text**")) ; and so on..
   ;       controlclick, button6, ahk_id %curHwnd%

   break
   }
}
WinSet, Top,, % "ahk_id " curHwnd

;is there a way to make it so that if the reprint label window is not active in specimen window than it allows me to send keystroke to open that window  under specimen window? i need it done in the background (NA style) or just msgbox that reprint label window is not open. i've tried but didn't work out.

Loop
{
IfWinNotExist Specimen
MsgBox, Specimen window not active
Else
IfWinExist Specimen
Inputbox,CID,Please enter CID to reprint,,,,100 ;i need this always on top
If ErrorLevel ;end loop also how can i make it so that if the value is empty(press enter without entering any numbers to inputbo), that it will also end the loop
{
   break
}
Else
DetectHiddenWindows, On
ControlSendRaw,Edit1,%CID%,Specimen Management Routing and Tracking
ControlClick,Button6,Specimen,,,,NA
;i need to add that if a window call SMART(an error message) come up than to activate that window and also end loop
;else continue loop
Winwait,Printer Select,,,,4
ControlClick,Button1,Printer Select,,,,NA
}
Return
For added strength use a more than one condition expression in while loop.

htms
_________________
paradigm.shift:=(•_•)┌П┐RTFM||^.*∞
Back to top
View user's profile Send private message
suoabb



Joined: 08 Dec 2009
Posts: 30

PostPosted: Thu Mar 25, 2010 3:21 am    Post subject: Reply with quote

thanks TLM for all the replys
i meant to put this new script up eairlier when i got it working, but been doing alot of double at work.
i been thinking of redoing my script and i got it to work by altering the script, so now i make it open Reprint Label window before the loop and set it to close if there is an error level, so that way i don't have to worry about the Reprint Label being active, i can open another one and than close it. i think that makes things alot simpler.

Code:

Home::
IfWinNotExist Specimen
MsgBox, SMART window not active, please run Specimen window
Else
{
WinMenuSelectItem, Specimen,,Utilities,Reprint Label...
{
SetTimer,CID,-50
Loop
{   
Inputbox,CID,Please enter CID to reprint,,,,100 ;will always stay on top on first loop than it won't stay always on top the 2nd/3rd/etc loop
If ErrorLevel
{
winName = Reprint Label
appName = Specimen

WinGet, conList, ControlListHwnd, % appName
Loop, Parse, conList, `n
{
    curHwnd := A_Loopfield
    WinGetTitle, curWin, ahk_id %curHwnd%
    CoordMode, Tooltip, Screen
        if (curWin = winName)
                Break
}
Winclose % "ahk_id " curHwnd
break
}
Else
ControlSendRaw,Edit1,%CID%,Specimen
ControlClick,Button6,Specimen,,,,NA
IfWinExist SMART
{
Winactivate
Winclose,Printer Select
winName = Reprint Label
appName = Specimen

WinGet, conList, ControlListHwnd, % appName
Loop, Parse, conList, `n
{
    curHwnd := A_Loopfield
    WinGetTitle, curWin, ahk_id %curHwnd%
    CoordMode, Tooltip, Screen
        if (curWin = winName)
                Break
}
Winclose % "ahk_id " curHwnd
Break
}
Else
Winwait,Printer Select,,,,4
ControlClick,Button1,Printer Select,,,,NA
Sleep,100
}
CID:
 WinSet, AlwaysOnTop, On, Please enter CID to reprint
Return
}
}
Return


this work fine, the only problem which i don't know how to fix is, the first time the CID input box appear, it is always on top, but on the second loop and so on, that input box is not always on top, can you help me modify this script?
so the CID inputbox is always on top.
also is it possible to move the Reprint Label to a certain spot on the screen so i can send a controlclick to a certain position all the time on the Reprint Label screen?
i am making another script exactly similiar to this one but it reprint the Accesion number (Edit2 box) and i think i have to click on the white screen below all the edit boxes on Reprint Label screen for it to work. otherwise i get errors and making the script delay(sleep) between entering next action doesn't seem to fix the error.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group