6
votes

I am learning both autohotkey and python. I wrote this script in ahk (and it works!) that automatically joins tables (using tableninja) in the pokerstars client--

^q::
Loop
{
Send q
Sleep 500
Send {PgUp}
Sleep 500
Send w
Sleep 60000
}
return

I'd like to convert this into python--could you give me an idea as to which modules I can use to accomplish this?

What the python script needs to do is to (while looping) type in a letter (on a notepad that's already open), go down two lines, type in another letter, then wait one minute before starting over.

I am thinking--

import module to auto-type letters
import module that works as timer

def function
    type letter q
    enter
    enter

def function
    type letter w

def function
    sleep

while True
    function
    function
    function

I am teaching myself how to code. I haven't reached that part about python modules just yet. Thanks!

3
Is this just a learning exercise? As much as I love Python, AutoHotkey is better suited to this task in my opinion. Unless there's other functionality you're adding as well. If it's just these few lines I'd stick with AHK. - Gary Hughes
learning. i just want to see how this ahk script can be done using python. - Jim Syyap

3 Answers

8
votes

Assuming you work on windows(don't think AHK runs on anything else), you should check out sendkeys. It will make sending keystrokes a piece of cake. If you want somthing a little more robust, take a look at pywinauto

For the shortcut part, take a look at pyhook

7
votes

I suggest these modules:

  • SendKeysCtypes for any sending of keystrokes and sending shortcuts to a window. SendKeysCtypes is a new and more stable version of SendKeys. I have had issues with SendKeys in the past.

  • PYHK to deal with global hotkeys - receive hotkeys and trigger functions. PYHK is based on pyHook and makes hotkey registration very simple. I wrote it because I had the exact same idea as you - I wanted to to do AHK functionality in python.

  • win32gui for window handling such as moving resizing. I personally prefer win32gui for short, simple tasks. I use pywinauto for more complex tasks. An example would be if I had to access a menu within a program (like File-New).

  • mouse.py to control the mouse. This is the most robust way I have found so far. The version I use is an extension of a module I found here at stackoverflow - ctypes mouse_events.

I have personally done several programs for poker with python. I have released source code of my smaller programs. You can find them with source on my website schurpf.com/poker-software.

3
votes

there's also AutoPy, a cross-platform library for this purpose.