#1
|
|||
|
|||
simple ahk help
Can someone tell me what's the matter w/the code below? It's part of an ahk script, I made a desktop link and 50-75% of the time when I first click it gets hung up; after I kill ahk and double-click the desktop icon a second time it works fine.
Of the 50-75% of the time it fails initially, it's usually hung up closing the default pt db (not always); but what I don't get is that when it fails, I kill ahk and the second time I double-click this script icon it *always* runs to completion correctly (I added the "sleeps" hoping it was just overrunning itself or something - didn't do any good). <font class="small">Code:</font><hr /><pre> ;; pokertracker SetTitleMatchMode, 1 Process, Exist, ptrack2.exe if %ErrorLevel% = 0 { Run, "C:\Documents and Settings\mike\Desktop\Poker Tracker.lnk",max openDb :=1 startImport := 0 closeDb := 0 } if openDb = 1 { WinWait, Poker Tracker (Version WinActivate, Poker Tracker (Version WinMenuSelectItem, Poker Tracker, , File, Open A Database... ;WinWait, Poker Tracker (Version Send {TAB} Send {TAB} Send {Down} Send {Down} Send {Space} Send {Enter} closeDb := 1 } sleep, 500 if closeDb = 1 { WinWait, Poker Tracker (Version WinActivate, Poker Tracker (Version WinMenuSelectItem, Poker Tracker, , File, Close A Database... ;WinWait, Poker Tracker (Version Send {TAB} Send {TAB} Send {Space} Send {Enter} Send {Enter} startImport := 1 } sleep, 500 if startImport = 1 { WinWait, Poker Tracker (Version WinActivate, Poker Tracker (Version WinMenuSelectItem, Poker Tracker, , File, Auto-Import Hand Histories ;WinWait, Poker Tracker (Versio Send {TAB} Send {TAB} Send {TAB} Send {TAB} Send {Space} WinWait, Poker Tracker (Version, Stop Timer } sleep, 500 WinMinimize, Poker Tracker (Version</pre><hr /> |
#2
|
|||
|
|||
Re: simple ahk help
just a quick guess.. after doing the menu item in the first one, add a winwait for the "open a database" dialog
|
#3
|
|||
|
|||
Re: simple ahk help
illunious' idea sounds like a good one. I can't test it as I only have one database right now.
That being said, I'm not really sure why you have structured your program the way you have. If you run your script and PT is open, it will just minimize PT. If PT isn't open, the script will open it, and then always run the next three blocks within the if statement. This is because when PT is not open you set openDb to 1. Then you check to see if openDb is equal to 1 (which it is). So you run through the block that opens a database. This block ends by setting closeDb to 1. You then check to see if closeDb is 1, and it is. So you enter the block that closes a database. This block ends by setting startImport to 1. You then check to see if startImport is 1, and it is. So you enter the block that starts an import. If you actually do want to do each of the 3 blocks every time when PT is not open when the script is executed you can just use the following. (I cleaned up a few other things, too. I prefer ControlClick type interaction with windows as opposed to Sending keyboard events. But that is only because it sometimes makes the code more readable for people that don't know what the control is active after 2 tabs.) <font class="small">Code:</font><hr /><pre>;; pokertracker ;1 is the default of TitleMatchMode, so you do not need to set it. Process, Exist, ptrack2.exe if ErrorLevel = 0 { Run, "C:\Documents and Settings\mike\Desktop\Poker Tracker.lnk",max WinWait, Poker Tracker (Version WinActivate, Poker Tracker (Version WinMenuSelectItem, Poker Tracker, , File, Open A Database... Send, {TAB 2}{Down 2}{Space}{Enter} sleep, 500 ;Repeated WinWait, WinActivate can be left out because you are not likely to deactivate PT in the 1/2 second sleep time. ;If you think you will, look into BlockInput WinMenuSelectItem, Poker Tracker, , File, Close A Database... Send, {TAB 2}{Space}{Enter 2} sleep, 500 WinMenuSelectItem, Poker Tracker, , File, Auto-Import Hand Histories Send, {TAB 4}{Space} WinWait, Poker Tracker (Version, Stop Timer } sleep, 500 WinMinimize, Poker Tracker (Version</pre><hr /> |
#4
|
|||
|
|||
Re: simple ahk help
Excellent! illunious' idea does seem to be what was missing but I wanted to thank you for the code cleanup. I learned alot about ahk just looking over your changes/explanations. Thanks both...
Mike |
|
|