Autohotkey DynaRun

Autohotkey DynaRun

posted in productivity on

Run any Autohotkey script on the web with a single.. Autohotkey hotkey.

Some Autohotkey blog posts

Some blog posts that have Autohotkey scripts for you to test out right away!

The DynaRun script

Select an Autohotkey script and press Capslock + F5

lastDynaRun :=


CAPSLOCK & F5::
Clipboard =
Send, ^c
ClipWait, 3


dynaRunName = Dynarun
if (lastDynaRun) {
    Process, Exist, %lastDynaRun%
    if (ErrorLevel > 0) {
        MsgBox, 4, Existing DynaRun, Replace last DynaRun?`nYes: Replace instance.`nNo: New instance., 1
        IfMsgBox, No
        {
            Random, rnd, 1, 100
            dynaRunName .= rnd
        }
        else
        {
            Process, Close, %lastDynaRun%
        }
    }
}

lastDynaRun := DynaRun(clipboard, dynaRunName)
return


DynaRun(TempScript, pipename="")
{
   static _:="uint",@:="Ptr"
   If pipename =
      name := "AHK" A_TickCount
   Else
      name := pipename
   __PIPE_GA_ := DllCall("CreateNamedPipe","str","\\.\pipe\" name,_,2,_,0,_,255,_,0,_,0,@,0,@,0)
   __PIPE_    := DllCall("CreateNamedPipe","str","\\.\pipe\" name,_,2,_,0,_,255,_,0,_,0,@,0,@,0)
   if (__PIPE_=-1 or __PIPE_GA_=-1)
      Return 0
   Run, %A_AhkPath% "\\.\pipe\%name%",,UseErrorLevel HIDE, PID
   If ErrorLevel
      MsgBox, 262144, ERROR,% "Could not open file:`n" __AHK_EXE_ """\\.\pipe\" name """"
   DllCall("ConnectNamedPipe",@,__PIPE_GA_,@,0)
   DllCall("CloseHandle",@,__PIPE_GA_)
   DllCall("ConnectNamedPipe",@,__PIPE_,@,0)
   script := (A_IsUnicode ? chr(0xfeff) : (chr(239) . chr(187) . chr(191))) TempScript
   if !DllCall("WriteFile",@,__PIPE_,"str",script,_,(StrLen(script)+1)*(A_IsUnicode ? 2 : 1),_ "*",0,@,0)
        Return A_LastError,DllCall("CloseHandle",@,__PIPE_)
   DllCall("CloseHandle",@,__PIPE_)
   Return PID
}

Or download dyna-run-capslock-f5.ahk

Installing the script

  • Download and install Autohotkey (Pick Autohotkey 1.1)
  • Create a file with the extension ahk
  • Paste the Autohotkey code from above in the file
  • Double click your newly created file to activate the script
  • Select some Authotkey text and press Capslock + F5

To start with Windows

To start your Autohotkey script with Windows put a file shortcut in your startup folder.

To get to this directory:

  • Press Windows + E
  • Press Control + L
  • Type shell:startup
  • Press Enter

Usually something like:

C:\Users\your_user_name\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

With your_user_name: $env:USERNAME (PS1) or %USERNAME% (CMD)

Mega test script

MsgBox Will it work?

Stuff that came into being during the making of this post
Tags: autohotkey