Re: A script you might like
Well, I’m still not sure why you use SetTitleMatchMode (I’m tired - getting late over here in Germany) but here goes anway:
;__________________________Table Navigator_____________________
; AutoHotkey Version: 1.0.41.02
; Platform: WinXP
; Author: Roland & SamIAm
;some of Sams functions (these have to be in the auto-execute section as I found out; so apparently they get called [img]/images/graemlins/crazy.gif[/img]. Getting late, like I said).
;FOLD = 1;
newButton("fold", 1, "AfxWnd42s14") ;(
newButton("checkFoldInTurn", 1, "AfxWnd42s20")
newButton("foldInTurn", 1, "AfxWnd42s19")
;CALL = 2;
newButton("call", 2, "Call (", 1)
newButton("check", 2, "AfxWnd42s15") ;(
newButton("cInTurn", 2, "AfxWnd42s21")
;RAISE = 3;
newButton("bet", 3, "Bet", 1)
newButton("raise", 3, "Raise ", 1)
newButton("r1InTurn", 3, "AfxWnd42s23")
;LEAVE = 4;
newButton("muckNow", 4, "Muck?", 2)
newButton("sitout", 4, "Sit Out")
newButton("muckInTurn", 4, "Muck Losing/Uncalled Hands")
;STAY = 5;
newButton("back", 5, "I am Back")
newButton("waitNow", 5, "AfxWnd42s16") ;(
newButton("waitInTurn", 5, "Wait for Big Blind")
;PLAY = 6;
newButton("post", 6, "Post", 1)
newButton("show", 6, "Show", 2)
newButton("autopost", 6, "Auto Post Blind")
SysGet, size_caption, 4
SysGet, size_boarder, 32
size_titlebar := size_caption + size_boarder ;I wanted the GUI to be the same height as the titlebar and this seems to do the trick
Gui, +alwaysontop +Lastfound +Owner
Gui, Color, 00008B ;a dark blue I quite like. Change it to whatever you want
WinSet, Transparent, 200 ;make the GUI slightly transparent - looks better that way
Gui, -Caption
Gosub, get_table_list ;get the table list without waiting for the timer. That way we can...
def_t = %table_1% ;... make table_1 the default table to have a starting point
SetTimer, get_table_list, 1000 ;update table_list every second
WinGetPos, x, y, , , ahk_id%def_t%
Gui, Show, w800 h%size_titlebar% x%x% y%y% NoActivate, table_navigator ;show the GUI on table_1
SetTimer, show_hide, 200
return
;_________end of auto-execute section___________
;_________subroutines:
get_table_list:
table_list := Update_tables() ; the function returns a comma seperated list of unique window IDs
Loop, Parse, table_list, `, ;assign these IDs to the variables "table_1", "table_2" etc.
{
table_%A_Index% = %A_LoopField%
}
return
show_hide: ;hide the GUI if a) def_t doesn't exist, b) def_t is minimized or c) the active window is maximized
IfWinExist, ahk_id%def_t%
{
WinGet, is_maximised_active, MinMax, A
WinGet, is_minimized_def_t, MinMax, ahk_id%def_t%
If (is_maximised_active = 1 or is_minimized_def_t = -1)
Gui, Hide
else
Gui, Show, NoActivate
}
else
Gui, Hide
return
;_________hotkeys:
down::
key = down
def_t := GetTarget(key) ;pass "key" to the GetTarget function which returns the new def_t
WinGetPos, px, py, , , ahk_id%def_t% ;move the GUI to the new de_t
Gui, Show, w%w% x%px% y%py% NoActivate
return
up::
key = up
def_t := GetTarget(key)
WinGetPos, px, py, , , ahk_id%def_t%
Gui, Show, w%w% x%px% y%py% NoActivate
return
right::
key = right
def_t := GetTarget(key)
WinGetPos, px, py, , , ahk_id%def_t%
Gui, Show, w%w% x%px% y%py% NoActivate
return
left::
key = left
def_t := GetTarget(key)
WinGetPos, px, py, , , ahk_id%def_t%
Gui, Show, w%w% x%px% y%py% NoActivate
return
<font color="red"> ;Sams hotkeys: </font>
!1::
clickVis(1)
return
!2::
clickVis(2)
return
!3::
clickVis(3)
return
!4::
clickVis(4)
return
!5::
clickVis(5)
return
!6::
clickVis(6)
return
!7::
debug()
return
;_________functions:
Update_tables() ;this function returns "table_list" and also operates on the GUI (which is why "size_titlebar" is made global):
{
global size_titlebar
WinGet, pid, PID, Welcome to the PartyPoker.com ;retrieves the process ID (using the window title of the lobby)
WinGet, id, list, Table ahk_pid%pid% ahk_class #32770, , Welcome to the PartyPoker.com Lobby, Side Bet ;make a list of windows IDs matching ahk_pid/class, excluding the lobby
Loop, %id%
{
StringTrimRight, this_id, id%a_index%, 0 ;look familiar? [img]/images/graemlins/smile.gif[/img]
WinGetPos, x, y, w, h, ahk_id %this_id%
w -= 50 ;this allows for slight overlap or slightly different table sizes
h -= 50
If (x < a_screenwidth/6 AND y < a_screenheight/6) ;determine the table number based on its position
table_1 = %this_id%
If (x < a_screenwidth/6 AND y > a_screenheight/6 AND y < 2*h)
table_2 = %this_id%
If (x < a_screenwidth/6 AND y >= 2*h)
table_3 = %this_id%
If (x > a_screenwidth/6 AND y < a_screenheight/6 AND x < 2*w AND y < 2*h)
table_4 = %this_id%
If (x > a_screenwidth/6 AND y > a_screenheight/6 AND x < 2*w AND y < 2*h)
table_5 = %this_id%
If (x > a_screenwidth/6 AND x < 2*w AND y >= 2*h)
table_6 = %this_id%
If (y < a_screenheight/6 AND x >= 2*w)
table_7 = %this_id%
If (y > a_screenheight/6 AND x >= 2*w AND y < 2*h)
table_8 = %this_id%
If (x > a_screenwidth/6 AND x >= 2*w AND y >= 2*h)
table_9 = %this_id%
}
table_list = %table_1%,%table_2%,%table_3%,%table_4%,%table_5%, %table_6%,%table_7%,%table_8%,%table_9%
w += 50 ;reset to the actual width
;modify the GUI according to the height of the titlebar, the width of the table(s)
;(this assumes all tables are roughly the same size) and round the edges because it looks better:
WinSet, Region, w%w% h%size_titlebar% 0-0 %w%-0 %w%-%size_titlebar% 0-%size_titlebar% R20-20, table_navigator
return, table_list ;return "table_list"
}
GetTarget(key) ;this function returns the new "def_t" when passed "key"
{
global def_t ;make these two variables global
global table_list
If key = down
new_order = 123456789 ;since this is the order the tables are in anyways, new_order equals the old order in this case
If key = up
new_order = 987654321 ;"up" is the opposite of "down" [img]/images/graemlins/smile.gif[/img] so we just reverse the order
If key = right
new_order = 147258369 ;the table to the right of table_1 is table_4 etc.
If key = left
new_order = 963852741 ;reverse the order for "right"
Loop, Parse, table_list, `, ;parse table_list, assigning each substring (ID) a new table number based on the new order
{
StringMid, new_number, new_order, %a_index%, 1
table_%new_number% = %a_loopfield%
}
Loop, 9
{
StringTrimRight, table, table_%a_index%, 0 ;acces the (new) array to find out which number the def_t is in the new order
If def_t = %table%
{
table_number = %a_index%
break
}
}
Loop, 9 ;this loop finds the number of the next table in the list (target)
{
table_number++ ;for instance: if the loop above determined that the def_t is table_5, this loop looks for table_6 first;
If table_%table_number% <> ;if "table_6" is empty, it looks for table_7 and so on
{
target = %table_number%
break
}
If table_number >= 9 ;if table_number reaches 9, tables 6 through 9 didn't exist, to continue the example above
table_number = 0 ;so we search for tables 1 through 4 (table_number is set to 1 at the beginning of the next loop iteration)
}
target := table_%target% ;once we've found "target", change it to be the ID of the table (using the array created by the first loop)
IfWinExist, ahk_id%target% ;only return a new de_t if it actually still exists; else, return the old def_t
{
def_t = %target%
}
Return, def_t ;return "def_t"
}
<font color="red"> ;the rest of Sams functions: </font>
debug()
{
local but, num, Output
but = 1
Loop
{
if(but > numButtons)
break
num = 1
Loop
{
if(num > numButtons%but%)
break
if(visible(but,num) = 1)
Output = % Output . names%but%x%num% . " is visible.`n"
num += 1
}
but += 1
}
MsgBox %Output%
}
clickVis(button)
{
local output, i, isVis, currString, currMatch
WinGetTitle, winTitle, <font color="red"> ahk_id%def_t%</font>
i = 1
Loop
{
if(i > numButtons%button%)
break
if (visible(button,i) = 1)
{
currMatch := matches%button%x%i%
SetTitleMatchMode, %currMatch%
currString := strings%button%x%i%
ControlClick, %currString%, %winTitle%
break
}
i += 1
}
}
visible(but, num)
{
local currentMatch, currentString
local output
currentMatch = % matches%but%x%num%
currentString = % strings%but%x%num%
SetTitleMatchMode % currentMatch
ControlGet, output, Visible, , %currentString%, %winTitle%
if output <> 1
{
output = 0
}
return output
}
newButton(name, button, string, match=3)
{
local buttonCount
numButtons += 1
numButtons%button% += 1
buttonCount := numButtons%button%
names%button%x%buttonCount% := name
matches%button%x%buttonCount% := match
strings%button%x%buttonCount% := string
}
;_______end of code_____
|