Personally, I use to have an alternative way to open/launch files:
My AHK files are associated with Sublime Text. I.e. when I double-click or press the Enter key on some AHK file, it will not be launched - instead, it will be opened in the editor. Using my function, I can assign Ctrl-Enter to launch such files. Thus,
* Enter: open in Sublime Text
* Ctrl-Enter: launch it.
Very handy.
What I ask for is how to improve the function.
The problem is shown in the code itself: the excessive line that looks stupid and excessive:
Code: Select all
#SingleInstance, Force
SendMode, Input
CopyToPseudoClipboard(WaitingMethod := "ClipWait", WaitingDelayInMilliseconds := 1000) {
OriginalClipboard := ClipboardAll
Clipboard := ""
Send, ^c
; ClipWait is more reliable, but it waits for at least 500
; milliseconds. To wait for a shorter period of time (e.g., 250
; milliseconds), you will need to use Sleep.
If (WaitingMethod = "ClipWait") {
WaitingDelayInSeconds := WaitingDelayInMilliseconds * 1000
ClipWait, % WaitingDelayInSeconds
If (ErrorLevel != 0)
Return
} Else {
Sleep, % WaitingDelayInMilliseconds
}
PseudoClipboard := Clipboard
Clipboard := OriginalClipboard
Return PseudoClipboard
}
^Enter::
CopyToPseudoClipboard("ClipWait", 1000)
PseudoClipboard := CopyToPseudoClipboard("ClipWait", 1000) ; I don't like this line: it looks "duh" and excessive.
; I would like to remove it, but in such a case the script will not work.
If (RegExMatch(PseudoClipboard, "adoc$"))
Run, % """" . A_ProgramFiles . "\Google\Chrome\Application\chrome.exe" . """" . A_Space . """" . PseudoClipboard . """"
Else If (RegExMatch(PseudoClipboard, "ahk$"))
Run, % """" . A_AhkPath . """" . A_Space . """" . PseudoClipboard . """"
Return
Code: Select all
} Else {
Sleep, % WaitingDelayInMilliseconds
}
Global PseudoClipboard := Clipboard
Clipboard := OriginalClipboard
Return PseudoClipboard
Probably there exists a better way, what do you think?