I'm currently using the ansi version of Autohotkey_L but I'm trying to move to the unicode version by updating or dropping the scripts that don't work with it. Below is a script I use frequently to copy selected code to clipboard and run it as a separate script (i.e. for the convenient testing of small pieces of ahk code). The hotkey is (Win+Tab).
Code:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
/*
#c:: ;copies selected file paths from explorer to clipboard
Send ^c
Clipboard =
ClipWait,2
Clipboard := % Clipboard
SoundPlay *-1
return
*/
#Tab:: ;Run selected AHK code
If hClip := WinExist("ClipTest")
WinKill, ahk_id %hClip%
Clipboard =
Send ^c
ClipWait,1
;clip := % Clipboard
ClipContent =
(
%Clipboard%
Esc::ExitApp
)
RunScript(ClipContent,"ClipTest")
SetTimer,ClosePipe,-30000
Return
ClosePipe:
Critical
While, hClip := WinExist("ClipTest")
{
WinKill, ahk_id %hClip%
Sleep, 1000
}
Critical, Off
Return
;Original script by Lexikos: Lexikos as the main source: http://www.autohotkey.com/forum/viewtopic.php?t=25867
;The function version below is from a post by HotkeyIt: http://www.autohotkey.com/forum/viewtopic.php?p=263671#263671
RunScript(TempScript, name="")
{
pipe_name := name="" ? A_TickCount : name
; Before reading the file, AutoHotkey calls GetFileAttributes(). This causes
; the pipe to close, so we must create a second pipe for the actual file contents.
; Open them both before starting AutoHotkey, or the second attempt to open the
; "file" will be very likely to fail. The first created instance of the pipe
; seems to reliably be "opened" first. Otherwise, WriteFile would fail.
pipe_ga := CreateNamedPipe(pipe_name, 2)
pipe := CreateNamedPipe(pipe_name, 2)
if (pipe=-1 or pipe_ga=-1)
{
MsgBox CreateNamedPipe failed.
ExitApp
}
Run, %A_AhkPath% "\\.\pipe\%pipe_name%",,,PID
; Wait for AutoHotkey to connect to pipe_ga via GetFileAttributes().
DllCall("ConnectNamedPipe","uint",pipe_ga,"uint",0)
; This pipe is not needed, so close it now. (The pipe instance will not be fully
; destroyed until AutoHotkey also closes its handle.)
DllCall("CloseHandle","uint",pipe_ga)
; Wait for AutoHotkey to connect to open the "file".
DllCall("ConnectNamedPipe","uint",pipe,"uint",0)
; AutoHotkey reads the first 3 bytes to check for the UTF-8 BOM "?". If it is
; NOT present, AutoHotkey then attempts to "rewind", thus breaking the pipe.
Script:= chr(239) chr(187) chr(191) TempScript
if !DllCall("WriteFile","uint",pipe,"str",Script,"uint",StrLen(Script)+1,"uint*",0,"uint",0)
MsgBox WriteFile failed: %ErrorLevel%/%A_LastError%
DllCall("CloseHandle","uint",pipe)
Return PID
}
; by Lexikos: http://www.autohotkey.com/forum/viewtopic.php?t=25867
CreateNamedPipe(Name, OpenMode=3, PipeMode=0, MaxInstances=255)
{
return DllCall("CreateNamedPipe","str","\\.\pipe\" Name,"uint",OpenMode
,"uint",PipeMode,"uint",MaxInstances,"uint",0,"uint",0,"uint",0,"uint",0)
}
p.s. I tried to replace %clipboard% in ClipContent with the commented out "clip" variable (which is defined in a way that works for the commented out hotkey above it for something else, but when I run it like that I get a different error and the script crashes.
Any ideas how to make this work with AHK_L unicode?