Jump to content

AutoHotKey question


Cusem
 Share

Recommended Posts

I have been using AutoIT3 for about a year now and although I started as a complete n00b, now I'm able to create scripts that suit most of my needs. Since I did some Basic in my younger years and read a lot on this forum and the AutoIT helpfile, AutoIT was very pleasant to get used to.

At this moment I play a lot of poker and it seems that all poker tools are written in AutoHotKey. I would like to adjust these scripts to my needs, since there are often little things that I would do different. I also would like to implement certain features of AHK scripts in my own AutoIT scripts. The problem is, I don't understand AHK at all. I don't really want to start over completely learning AHK, since it took me quite some time to get used to AU3 and I don't want to switch to AHK.

AHK seems to get all info needed with its ControlGet command. I'm a bit of a n00b with the AutoIT3 counterpart of this command, but I just can't manage to get the same results when fiddling around in AutoIT. Maybe this is because of my OS is WinXP2 SP2 x64 and I read in the helpfile that the ControlListView+GetText command does not work on x64. However, these AHK tools are able to retrieve this information.

Since both scripting languages are alike, I was wondering, is there maybe a AHK to AU3 converter available? This would be very usefull as I can see how certain syntaxes are done in AHK while I can view the AU3 counterpart.

Or does anybody know of a good tutorial to AHK which is viewed of an AutoIT perspective (AHK functions explained their AutoIT counterparts)?

Right now I'm trying to convert the following AHK file in AU3, but I get stuck quite quickly (even though theres a quite clear explanation in the AHK file); I get stuck below the END OF AUTO EXECUTE SECTION comment.

;
; AutoHotkey Version: 1.x
; Language:    English
; Platform:    Win9x/NT
; Author:        A.N.Other <myemail@nowhere.com>
;
; Script Function:
;   Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;

#NoEnv; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input; Recommended for new scripts due to its superior speed and reliability.
; FTPWatch v0.01

; ====================================================================================================


===============

; This script will open upto 'NumTablesRequired'.
; FTP requires logging in to Observe tables so I don't recommend using multiple user/accounts areas.

;===================================================================================================


=================

; This is the number of tables you wish to mine (Full Tilt Poker allows 16 tables).
NumTablesRequired = 16;Change this number to define the maximum number of tables you will try to keep open.

; Change this number for the type of L/NL Limit you want to observe.  (2 for Heads up, 6 for 6 max, 9 for full ring).
NumSeats = 6 

;Change this number for the minimum amount of players seated you want to observe.
NumPlayers = 5

;Change this to Type of Table desired NL, Limit, or CAP NL
Limit = NL

;Change this to Stakes Desired Ex: $2/$4
Stakes = $0.50/$1
;===================================================================================================


=================

#Persistent
SetTitleMatchMode, 2
WinGet, lobby_id , ID, Full Tilt Poker

; Lets create our lock file, for the OnExit trap to see.
FileDelete, %A_UserName%.%A_ComputerName%.lock
FileAppend, %A_UserName%.%A_ComputerName% is locked, %A_UserName%.%A_ComputerName%.lock

; Lets add a OnExit event trap.
OnExit, ExitSub

; Lets start the minimizing windows (every 10 seconds).
;GoSub, MinimizeTables
SetTimer, MinimizeTables, 10000

; Lets start opening tables (190 seconds delay seems ok?  Need to make sure PT has imported before the table closes).
GoSub, OpenTables
SetTimer, OpenTables, 190000

return

;===================================================================================================


=================
; ----------------------------------------- end of auto-execute section --------------------------------------------
;===================================================================================================


=================

OpenTables:

;make a list of all the Full Tilt tables, excluding Lobby
  WinGet, id, List, Limit Hold'em, , Full Tilt Poker

;make a list of all the Full Tilt tables
  ControlGet, AllTablesAvail, List, , SysListView323, ahk_id%lobby_id%;used below to close closed tables (no longer in the list box)


; Lets see if we want to close any tables.
  Loop, %id%
  {
    StringTrimRight, Window, id%A_Index%, 0

  ; See if this window is open in another user area, if so lets close it.
    WinGetTitle, String, ahk_id%Window%
    StringSplit, StringArray, String, -
    StringTrimRight, StringArray1, StringArray1, 1
    if IsTableOpenInAnotherArea(StringArray1) = 1
    {
      WinClose, ahk_id%Window%
      WinWaitClose, ahk_id%Window%, , 3
    }
    Else
    {
      IfNotInString, AllTablesAvail, %StringArray1%
      {
        WinClose, ahk_id%Window%
        WinWaitClose, ahk_id%Window%, , 3
      }
    }
  }

; Lets see if open tables still qualify, if not close them.
  GoSub, IsTableLessNumPlayersSeated

; If we still have >= n tables open allready, lets not bother.
  WinGet, NumTables, List, Limit Hold'em, , Full Tilt Poker 
  If (NumTables >= NumTablesRequired)
    return

; Set the focus to the topmost row.
  ControlFocus, SysListView323, ahk_id%lobby_id%;set focus to the ListView
  ControlGet, count, List, Count, SysListView323, ahk_id%lobby_id%;used below to break if we reach the end of the list before we find n tables
  ControlGet, focused, List, Count Focused, SysListView323, ahk_id%lobby_id%;we want to select the topmost row, 

; Send %focused%/15 amount of PGUP keystrokes to get to the top of the list.

    focused /= 15

    Loop, %focused%
      ControlSend, SysListView323, {PgUp}, ahk_id%lobby_id%
    

; Open the tables.
    Loop
    {
    ; Save the index.
      ListIndex = %a_index%
      
;     loop
;      {
        
            ControlGet, Row, List, Focused, SysListView323, ahk_id%lobby_id%
              StringSplit, RowArray, Row, %A_Tab% ; Fields (columns) in each row are delimited by tabs (A_Tab).
              StringSplit, NumSeated, RowArray5, /
              RatioSeated := NumSeated1 / NumSeated2

;;becasue of the large number of tables there may be a lag
;     ;we need to verify the list has kept up with the script
       
;       TableName = %RowArray2%
;       sleep 300
        
;       If TableName = %RowArray2%
;       break
;       ListVars
;       Pause
;      }

      IfWinNotExist %RowArray2%
      {
        If IsTableOpenInAnotherArea(RowArray2) = 0
        {
    
;       IfNotInString, RowArray4, CAP NL;Had to keep this as CAP NL tables were randomly opening otherwise


           If RowArray4 = %Limit%
           {
             if RowArray3 = %Stakes%
         { 

        if NumSeated2 = %NumSeats%
        {
;           ListVars
;           Pause               

            IfGreaterOrEqual,  RatioSeated, % NumPlayers / NumSeats
                    {
                           ControlSend, SysListView323, {Enter}, ahk_id%lobby_id%
                           If ErrorLevel = 0
                        NumTables++
                    }
              
        }
         }
           }
        }
      }

    ControlSend, SysListView323, {DOWN}, ahk_id%lobby_id%;move to the next table
    If (NumTables >= NumTablesRequired OR ListIndex > count);if we reach 16 tables or the end of the list, break; 
      break
    }

; Sleep to make sure they open and then, update the table names.
;Sleep, 1000
  GoSub, UpdateTableNames

  return

;===================================================================================================


=================

UpdateTableNames:

; We don't want the other copies interfering while we do this...
  EnterCritcalSection()

; Read in everythig that was in the old table_list
  FileRead, OldList, table_list

; Delete the old copy of table_list (if it exists).
  FileDelete, table_list

; Save all the lines which are not our's back to the file.
  Loop, Parse, OldList, `r`n; Rows are delimited by linefeeds (`n).
  {
    if StrLen(A_LoopField)>0
    {
      IfNotInString, A_LoopField, %A_UserName%.%A_ComputerName%
        FileAppend , %A_LoopField%`r`n, table_list
    }
  }

  WinGet, id, List, Limit Hold'em, , Full Tilt Poker
  Loop, %id%
  {
    StringTrimRight, Window, id%A_Index%, 0
    WinGetTitle, String, ahk_id%Window%
    StringSplit, StringArray, String, -
    StringTrimRight, StringArray1, StringArray1, 1
    FileAppend , %A_UserName%.%A_ComputerName%:%StringArray1%`r`n, table_list
  }

; Other copies can run now if they need to.
  LeaveCriticalSection()

  return

;===================================================================================================


=================

IsTableOpenInAnotherArea(TableName)
{
; We don't want the other copies interfering while we do this...
  EnterCritcalSection()

; Read the current list of used tables.
  FileRead, CurrentTableList, table_list

  Loop, Parse, CurrentTableList, `r`n; Rows are delimited by linefeeds (`n).
  {
    if StrLen(A_LoopField)>0
    {
      IfNotInString, A_LoopField, %A_UserName%.%A_ComputerName%
      {
        IfInString, A_LoopField, %TableName%
        {

        ; Other copies can run now if they need to.
          LeaveCriticalSection()

          return 1; Found it.
        }
      }
    }
  }

; Other copies can run now if they need to.
  LeaveCriticalSection()

  return 0; Not found.
}


;===================================================================================================


=================

IsTableLessNumPlayersSeated:
{
;; Set the focus to the topmost row.
  ControlFocus, SysListView323, ahk_id%lobby_id%;set focus to the ListView
  ControlGet, count, List, Count, SysListView323, ahk_id%lobby_id%;used below to break if we reach the end of the list before we find n tables
  ControlGet, focused, List, Count Focused, SysListView323, ahk_id%lobby_id%;we want to select the topmost row, 

; If we have 0 tables open allready, lets not bother.
  WinGet, NumTables, List, Limit Hold'em, , Full Tilt Poker 
  If (NumTables = 0)
    return

;; Send %focused% / 15 amount of PGUP keystrokes to get to the top of the list.

  focused /= 15
  Loop, %focused%
  {
    ControlSend, SysListView323, {PgUp}, ahk_id%lobby_id%;move to the next table
  }
   Loop
     {
    ControlGet, Row, List, Focused, SysListView323, ahk_id%lobby_id%
    StringSplit, RowArray, Row, %A_Tab% ; Fields (columns) in each row are delimited by tabs (A_Tab)

    If RowArray4 = %Limit%
    {
             if RowArray3 = %Stakes%
         { 
        break
         }
    }

      ControlSend, SysListView323, {DOWN}, ahk_id%lobby_id%;move to the next table
      If (ListIndex > count);if we reach the end of the list, break; 
        break
    }
; Check NumPlayers
    Loop
    {

    ; Save the index.
      ListIndex = %a_index%

      ControlGet, Row, List, Focused, SysListView323, ahk_id%lobby_id%
      StringSplit, RowArray, Row, %A_Tab% ; Fields (columns) in each row are delimited by tabs (A_Tab).
      StringSplit, NumSeated, RowArray5, /
      RatioSeated := NumSeated1 / NumSeated2

      IfWinExist %RowArray2%
      {
        ifLess,  RatioSeated, % NumPlayers / NumSeats
        {
          WinClose, %RowArray2%
          WinWaitClose, %RowArray2%, , 3
        }
      }
      ControlSend, SysListView323, {DOWN}, ahk_id%lobby_id%;move to the next table
      If (ListIndex > count);if we reach 16 tables or the end of the list, break; 
        break
    }

; Sleep to make sure they close and then, update the table names.
;Sleep, 1000
  GoSub, UpdateTableNames

  return
}

;===================================================================================================


=================

EnterCritcalSection()
{
  Loop
  {
    IfNotExist, semaphore
      break
    Sleep, 1000; Lets wait and try again then.
  }
  FileAppend, semaphore in use, semaphore
  return
}

;===================================================================================================


=================

LeaveCriticalSection()
{
  FileDelete, semaphore
  return
}

;===================================================================================================


=================
;===================================================================================================


=================
; Minimized any Full Tilt tables it can see.
MinimizeTables:

;make a list of all the Full Tilt tables, excluding Lobby
  WinGet, id, List, Limit Hold'em, , Full Tilt Poker

; Lets see if we want to minimize or close any tables.
  Loop, %id%
  {
    StringTrimRight, Window, id%A_Index%, 0

  ; Lets make sure its minimized.
    WinMinimize, ahk_id%Window%

  }

  return

;===================================================================================================


=================

; This is used to remove the table list and the semaphore if we are the last to exit.
ExitSub:

; Lets delete our own lock.
  FileDelete, %A_UserName%.%A_ComputerName%.lock

; If we can't see any other locks left, lets delete the table list and the semiphore.
  IfNotExist, *.lock
  {
    FileDelete, table_list
    FileDelete, semaphore
  }

  ExitApp; The only way for an OnExit script to terminate itself is to use ExitApp in the OnExit subroutine.

;===================================================================================================


=================
;;;;;;;;;;;;;;;;; CODE ENDS HERE
Edited by Cusem
Link to comment
Share on other sites

Trying to convert AHK to AutoIt may prove to be more trouble than it's worth.

Creating the steps in AutoIt will be much easier if you just recreate the steps you do manually i.e. open FTP / click the buttons to log in / click the buttons to get to the list you want / double clicking on the item you want / loading the newly opened table into an array / rinse and repeat.

Let me know what the specifics you are interested in i.e. money/play money, game (holdem, omaha, stud...), stakes and so and I'll see if I can get you pointed in the right direction.

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...