Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert ahk to python

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!

like image 849
Jim Syyap Avatar asked Jul 02 '11 09:07

Jim Syyap


People also ask

Is AHK a python?

AutoHotkey.py is a Python library that embeds a Python DLL into the AutoHotkey_L v1. 1 process. It lets you call AHK functions from the Python code and register Python functions to be called from AHK, e.g. hotkeys, timers, clipboard handlers.

How do I open an AHK file?

Run a ScriptDouble-click a script file (or shortcut to a script file) in Explorer. Call AutoHotkey.exe on the command line and pass the script's filename as a command-line parameter. After creating the default script, launch AutoHotkey via the shortcut in the Start menu to run it.

How do I compile an AHK file?

Right-click: Within an open Explorer window, right-click any . ahk file and select "Compile Script" (only available if the script compiler option was chosen when AutoHotkey was installed). This creates an EXE file of the same base filename as the script, which appears after a short time in the same directory.


2 Answers

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

like image 90
giodamelio Avatar answered Nov 11 '22 17:11

giodamelio


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.

like image 24
schurpf Avatar answered Nov 11 '22 18:11

schurpf