6

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!

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Jim Syyap
  • 1,625
  • 7
  • 20
  • 23
  • 2
    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 Jul 04 '11 at 16:29
  • learning. i just want to see how this ahk script can be done using python. – Jim Syyap Jul 05 '11 at 07:11

3 Answers3

8

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

giodamelio
  • 5,465
  • 14
  • 44
  • 72
7

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.

schurpf
  • 609
  • 7
  • 7
  • link to [SendKeysCtypes](http://pywinauto.blogspot.com/2010/04/sendkeysctypes-release-for-some-value.html) – schurpf Jan 19 '12 at 10:15
3

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

eadmaster
  • 1,347
  • 13
  • 23