views:

15

answers:

0

I'm trying to rewrite the following autohotkey script in Python:

  Gui +LastFound
  DllCall( "RegisterShellHookWindow", UInt,WinExist() )
  MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
  OnMessage( MsgNum, "ShellMessage" )
  LastActiveWindowID := WinActive("A")

  Return ;                                          // End of Auto-Execute Section //

  ShellMessage( wParam, lParam )  {
    Global LastActiveWindowID
    If ( wParam = 4 And WinExist( "ahk_id " lParam ) ) { ; HSHELL_WINDOWACTIVATED = 4
         ;FileDelete Logme.txt
         WinGetTitle, title, ahk_id %lParam%
         FileAppend %LastActiveWindowID% %title% %lParam%`n, Logme.txt
         LastActiveWindowID := lParam
    }
  }

I'm pretty sure this is possible somehow using ctypes and win32gui Python extensions, but I'm not having any luck finding useful examples to this end. I'm trying to create a log file that marks every window change.

Thanks!