 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
DataLife
Joined: 27 Apr 2008 Posts: 232
|
Posted: Sat May 09, 2009 2:46 pm Post subject: Re: [VxE]'s Encryption With GUI |
|
|
| [VxE] wrote: | | My Encryption Function... | This is very cool. Can I have permission to use it in one of my scripts? I may modify it to encrypt and decrypt an ini file to prevent users from altering/viewing stuff they should not be messing with. _________________ Unless otherwise stated, all code is untested
(\__/) This is Bunny.
(='.'=) Copy and paste Bunny onto your signature.
(")_(") Help Bunny gain World Domination. |
|
| Back to top |
|
 |
DataLife
Joined: 27 Apr 2008 Posts: 232
|
Posted: Sat May 09, 2009 2:51 pm Post subject: Re: AutoExecute |
|
|
| [VxE] wrote: | | A more recent manifestation of one of my earlier scripts. This script attempts to run the contents of the clipboard as an AHK script with added safeguards and self-cleaning features. |
This works great!
I have been wanting a program like this. Normally I read thru the forums and copy the code in code boxes to the clipboard, then I paste it in my editor, save it as a new filename then run it. I forget to delete the temporary ahk file and I end up with a lot of useless junk.
When using your program, if I want to keep something I will just paste it the old fashion way.
thanks
DataLife
P.S. How did you come up with this idea? _________________ Unless otherwise stated, all code is untested
(\__/) This is Bunny.
(='.'=) Copy and paste Bunny onto your signature.
(")_(") Help Bunny gain World Domination. |
|
| Back to top |
|
 |
DataLife
Joined: 27 Apr 2008 Posts: 232
|
Posted: Sat May 09, 2009 11:59 pm Post subject: Re: Online Dictionary Easy Lookup Script |
|
|
| [VxE] wrote: | | Don't know what a word means? Just Control+Double-Click it (while this script is running) | This very cool, it is similar to IE8's Define with Google which only works in IE8. Your program works just about anywhere.
One thing, I changed the hotkey from ctrl double click to Alt double click because Ctrl and single click in this forum and in IE8 highlights the entire paragraph.
Ctrl single click to highlight entire paragraph seems to be new in IE8.
Very nice, I like it alot.
DataLife _________________ Unless otherwise stated, all code is untested
(\__/) This is Bunny.
(='.'=) Copy and paste Bunny onto your signature.
(")_(") Help Bunny gain World Domination. |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 2393
|
Posted: Sun May 10, 2009 12:48 pm Post subject: |
|
|
| DataLife wrote: | | Can I have permission to use it in one of my scripts? |
Yes, everyone has permission to use code found in any of my posts in any manner they see fit.
| DataLife wrote: | | P.S. How did you come up with this idea? |
When I was starting out with AHK, I made loads more errors than I do now. So I wrote a little script to make it faster and easier to test code, particularly small segments of code.
h2h
Reload with Parameters: Just like it says. Closes the relevant instance of a script and starts a new instance of the same script along with whatever parameters are passed to this function.
| Code: | Reload(param1="", param2="", param3="", param4="", param5="", param6="", param7="", param8="", param9="", param10="", param11="", param12="", param13="", param14="", param15="", param16="", param17="", param18="", param19="", param20="", param21="", param22="", param23="", param24="", param25="", param26="", param27="", param28="", param29="", param30="")
{ ; function by [VxE]. Exits this script and uses CMD.exe to start a new instance with the specified parameters.
Local p, Delay = 0.1
Loop 30
If (param%A_Index% = "")
Break
Else
{
; NOTE: passing an integer equal to the parameter's index is interpreted as indicating the variable named by that number
; as such, it is recommended that only numbers in float or hex format be passed as parameters in this function.
If (Param%A_Index% = A_Index . "")
Param%A_Index% := %A_Index%
StringReplace, param%A_Index%, param%A_Index%, ", "", all
p .= " """ . param%A_Index% . """"
}
If A_IsCompiled
Run CMD.exe /c ping -n %Delay% 127.0.0.1>nul & Start "AHK" "%A_ScriptFullPath%"%p%,, HIDE
; The 'ping' is simply to provide a slight delay to allow this instance to close before the new one starts.
Else
Run CMD.exe /c ping -n %Delay% 127.0.0.1>nul & Start "AHK" "%A_AhkPath%" "%A_ScriptFullPath%"%p%,, HIDE
Exitapp
} |
_________________ My Home Thread
Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags !
Last edited by [VxE] on Thu Feb 11, 2010 7:36 am; edited 2 times in total |
|
| Back to top |
|
 |
hugov
Joined: 27 May 2007 Posts: 2477
|
Posted: Mon Aug 10, 2009 10:29 am Post subject: Re: Unicode in gui controls |
|
|
| [VxE] wrote: | | FileReadU( filepath ) - Returns the text inside the designated .txt file. It can handle files that contain unicode characters by converting such characters into their html-type codes. |
Thanks for posting, I can use this from time to time. _________________ Tut 4 Newbies
TF : Text file & string lib, TF Forum |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 2393
|
Posted: Sun Aug 16, 2009 11:07 pm Post subject: Re: Unicode in gui controls |
|
|
| HugoV wrote: | | Thanks for posting, I can use this from time to time. | Enjoy! And feel free to tweak the resulting codes, since I'm sure there's a more intuitive/friendly way to deal with unicode characters. I only picked the HTML style for consistency and immediate accessibility via any web browser.
edit:] | Code: |
;<<<<<<<<<<<<<<< [VxE]'s Hyperactive Goto >>>>>>>>>>>>
;
; Discretely links itself to an editor window. When the user needs
; to quickly jump to a label, function, gui block, or a comment,
; HyGo displays a treeview, which the user can navigate, then double
; click on the desired item, and the script will make the editor window
; jump to the desired item.
;
; Note: "Edit1" MUST be the editor's primary control for its text.
; Flow Map:
; 1 set script settings
; 2 Initialize constants
; 3 build gui 1 ( the 'hot spot' )
; 4 Wait until an editor window is active
; 5 Position and then show gui 1
; 6 If the current editor window becomes inactive, hide gui 1 and goto step 4
; ---
; 7 A WM_MouseMove message triggers step 8
; 8 Build gui 2, then show and activate gui 2
; 9 wait until gui 2 is no longer active, then destroy gui 2
; ---
; 10 gui 2's treeview triggers step 11 when double-clicked
; 11 if the Treeview item has a line number remembered, scroll the editor to that line
Gosub, HyGo_Initialize_Script_Settings ; --- Step 1
Gosub, HyGo_Initialize_Constants ; --- Step 2
Gosub, HyGo_Build_Gui_1 ; --- Step 3
Loop
{
HyGo_Recycle := 1
HyGo_Active_Editor_Window := WinWaitActive( 9, "Editor_Window" ) ; --- Step 4
ControlGet, Edit, HWND,, Edit1
Gui, 1:Default
Gui, Show, % "Hide " HyGo_Gui_Docking( HyGo_Active_Editor_Window, 1 ) ; --- Step 5
DllCall("AnimateWindow", "UInt", 1Gui_Hwnd, "Int", 600, "UInt", 0x80000)
While HyGo_Recycle
Sleep 20
}
Return
HyGo_Initialize_Constants: ; --- Step 2
Gui_Name = Hyper Goto
Gui_Width = 220
Gui_Height = 0.86 Rel
Gui_Font = Lucidia Sans Unicode
Gui_Font_Size = 9
Gui_Title_Color = 80A040
Gui_Font_Color = E0E040
Gui_BGColor = Black
Editor_Window1 = Ahk_Class Notepad
Editor_Window2 = Ahk_Class tednpad
; Editor_Window3; Editor_Window4; Editor_Window5; Editor_Window6
; Editor_Window7; Editor_Window8; Editor_Window9
HyGo_Docking_Screen_Or_Window = Window
HyGo_Docking_Left_Center_Right = Left
HyGo_Docking_Top_Center_Bottom = Center
HyGo_Docking_Inside_Outside = Outside
Return
HyGo_Build_And_Show_Gui_2: ; --- Step 8
DllCall("AnimateWindow", "UInt", 1Gui_Hwnd, "Int", 50, "UInt", 0x90000)
Gosub, HyGo_Build_Gui_2
Gui, Show, % "Hide " HyGo_Gui_Docking( HyGo_Active_Editor_Window, 2 )
DllCall("AnimateWindow", "UInt", 2Gui_Hwnd, "Int", 300, "UInt", HyGo_Gui_Anim("Show") )
WinActivate
WinWaitActive
Gosub, HyGo_Expand_Treeview_To_Selection
WinWaitNotActive
DllCall("AnimateWindow", "UInt", 2Gui_Hwnd, "Int", 300, "UInt", HyGo_Gui_Anim("Hide") )
Gui, 2:Destroy ; --- Step 9
HyGo_Gui_2_Is_Shown := HyGo_Recycle := 0
Return
HyGo_Scroll_Editor_Window_To_The_Line: ; --- Step 11
IfNotEqual, A_GuiEvent, DoubleClick, Return
If ( zH := HyGo_Memory_%A_EventInfo% )
{
ControlSend,, {Left}{Right}, Ahk_ID %HyGo_Active_Editor_Window%
Edit_ScrollToLine( Edit, zH - 2, "Ahk_ID " HyGo_Active_Editor_Window )
}
Return
HyGo_Initialize_Script_Settings: ; --- Step 1
#Persistent
#SingleInstance, Force
SetWinDelay, -1
SetBatchLines, -1
HyGo_Gui_2_Is_Shown := 0
OnMessage(0x200, "WM_MOUSEMOVE")
Return
2GuiClose:
WinActivate, Ahk_ID %HyGo_Active_Editor_Window%
return
HyGo_Expand_Treeview_To_Selection:
If ( zW := InStr( HyGo_List_Of_Items "`n", "`n" . SelectedText . "`n" ) )
{
zH := InStr( SubStr( HyGo_List_Of_Items, 1, zW-1 ), "`n", 0, 0 )
zH := SubStr( HyGo_List_Of_Items, zH+1, zW - zH - 1 )
Tv_Modify( zH, "Vis" )
return
}
ControlGet, CurrentLine, CurrentLine,,, Ahk_ID %Edit%
If ( zW := HyGo_History_%CurrentLine% )
Tv_Modify( zW, "Vis" )
Return
HyGo_Build_Gui_1: ; --- Step 3
Gui, 1:Default
Gui, +AlwaysOnTop +LastFound +ToolWindow -Caption
1Gui_HWND := WinExist()
Gui, Color, %Gui_BGColor%
Gui, Font, % "S" Round( Gui_Font_Size * 1.7 ) " C" Gui_Title_Color, Comic Sans MS
Gui, Font,, %Gui_Font%
Gui, Margin, 0, 0
Gui, Add, Text, x3 y5 w0 h0 section, ; Section Anchor
If ( Gui_IsVertical := ( HyGo_Docking_Left_Center_Right != "Center" ) )
Loop, Parse, Gui_Name
If Asc(A_LoopField) > 64 && Asc(A_LoopField) < 91
Gui, Add, Text, xs, %A_LoopField%
Else Gui, Add, Text, % "xs+" Round(Gui_Font_Size/5), %A_LoopField%
Else Loop, Parse, Gui_Name
Gui, Add, text, % "ys x+" Round(Gui_Font_Size/5), %Gui_Name%
Gui, Margin, 3, 5
Gui, Show, +NoActivate Hide, HyGo Hotspot
WinGetPos,,, 1Gui_Width, 1Gui_Height
WinSet, Region, 0-0 W%1Gui_Width% H%1Gui_Height% R12-12
If HyGo_Docking_Left_Center_Right != Center
HyGo_Gui_Anim( (HyGo_Docking_Left_Center_Right = "Right")
= ( HyGo_Docking_Inside_Outside = "Inside") ? "Left" : "Right" )
If HyGo_Docking_Top_Center_Bottom != Center
HyGo_Gui_Anim( HyGo_Docking_Top_Center_Bottom = "Top" ? "Up" : "Down" )
If ( HyGo_Docking_Top_Center_Bottom = HyGo_Docking_Left_Center_Right )
HyGo_Gui_Anim("Center")
HyGo_Gui_Anim("Slide")
Return
HyGo_Build_Gui_2:
Gui, 3:+LastFound
Gui, 3:Margin, 1, 1
Gui, 3:Add, Text, % HyGo_Gui_Docking( HyGo_Active_Editor_Window, "" )
Gui, 3:Show, Hide
WinGetPos,,, zW, zH
2Gui_Width += zW := 2Gui_Width - zW
2Gui_Height += zH := 2Gui_Height - zH
Gui, 3:Destroy
Gui, 2:Default
Gui, +LastFound +Owner1
2Gui_Hwnd := WinExist()
Gui, Margin, 1, 1
Gui, Font, C%Gui_Font_Color% S%Gui_Font_Size%, Comic Sans MS
Gui, Font,, %Gui_Font%
Gui, Add, TreeView,
( LTrim Join`s
W%2Gui_Width%
H%2Gui_Height%
BackGround%Gui_BGColor%
C%Gui_Font_Color%
GHyGo_Scroll_Editor_Window_To_The_Line
)
2Gui_Width -= zW
2Gui_Height -= zH
ControlGetText, Ed_text,, Ahk_ID %Edit%
ControlGet, TotalLines, LineCount,,, Ahk_ID %Edit%
ControlGet, SelectedText, Selected,,, Ahk_ID %Edit%
Tv_Hotkeys := TV_Add( "Hotkeys" )
Tv_Functions := TV_Add( "Functions" )
Tv_Subroutines := TV_Add( "Subroutines" )
TV_Goto_Gosub := TV_Add( "Goto & Gosub" )
TV_Timers := TV_Add( "Timers" )
BlockComment := 0
Loop, Parse, HyGo_List_Of_Items, `n
{
If A_LoopField is INTEGER
VarSetCapacity( HyGo_Memory_%A_LoopField%, 0)
}
HyGo_List_Of_Items := ""
Loop, Parse, Ed_text, `n, `r
{
line = %A_LoopField%
If line = */
BlockComment := 0
If ( BlockComment += line = "/*" )
Continue
If InStr( line, ";" ) && Pos := RegexMatch( " " . line, "\s;" )
StringLeft, line, line, Pos - 1
line = %line%
If ( InStr( line, "Gosub" ) || InStr( line, "Goto" ) )
&& RegexMatch( line, "go(to|sub)[\s,]\s*\K.*$", zH )
{
If !InStr( HyGo_List_Of_Items "`n", "`nGo " zH "`n" )
{
StringReplace, zH, zH, %A_Space%, _
HyGo_%zH% := TV_Add( zH, TV_Goto_Gosub )
}
zW := HyGo_%zH%
zW := TV_Add( zH, zW )
HyGo_Memory_%zW% := A_Index
HyGo_History_%A_Index% := zW
HyGo_List_Of_Items .= "`n" zW "`n" zH
}
If InStr( line, "SetTimer" ) && RegexMatch( line, "SetTimer[\s,]\s*\K.*$", zH )
{
StringReplace, zH, zH, `,, %A_Space%every
If ErrorLevel
zH .= " every 250"
zH .= "ms"
zW := TV_Add( zH, TV_Timers )
HyGo_Memory_%zW% := A_Index
HyGo_History_%A_Index% := zW
HyGo_List_Of_Items .= "`n" zW "`n" zH
}
If InStr( line, ":" ) && 1 = RegexMatch( line, "[^\s,]+:$" )
{
zW := TV_Add( zH := SubStr( line, 1, -1 ), Tv_Subroutines )
HyGo_Memory_%zW% := A_Index
HyGo_History_%A_Index% := zW
HyGo_List_Of_Items .= "`n" zW "`n" zH
}
If InStr( line, "::" ) && 1 = RegexMatch( line, "[^\s]+( up)?::$" )
{
zW := TV_Add( zH := SubStr( line, 1, InStr( line, "::" ) - 1 ), Tv_Hotkeys )
HyGo_Memory_%zW% := A_Index
HyGo_History_%A_Index% := zW
HyGo_List_Of_Items .= "`n" zW "`n" zH
}
If InStr( line, "Hotkey" ) && 1 = RegexMatch( line, "Hotkey[\s\,]\s*(.*)\,(.*)[\,$](.*)", z )
If z2 NOT IN on,off,toggle,alttab
If z1 NOT IN ifwinactive,ifwinexist
If !InStr( HyGo_List_Of_Items "`n", "`n" z1 "::Goto " z2 "`n" )
{
zW := TV_Add( zH := z1 "::Goto " z2 , Tv_Hotkeys )
HyGo_Memory_%zW% := A_Index
HyGo_History_%A_Index% := zW
HyGo_List_Of_Items .= "`n" zW "`n" zH
}
If ( PendingFunction ) && line != ""
If InStr( line, "{" ) = 1
{
zW := TV_Add( PendingFunction, Tv_Functions )
HyGo_Memory_%zW% := zH
HyGo_History_%zH% := zW
HyGo_List_Of_Items .= "`n" zW "`n" PendingFunction
PendingFunction := ""
}
Else PendingFunction := ""
If InStr( line, "(" ) && !InStr( line, "If(" ) && !InStr( line, "while(" )
&& 1 = RegexMatch( line, "[^\s]+\(.*\)", zW )
If InStr( line, "{" ) > StrLen( zW )
{
zW := TV_Add( zH := SubStr( line, 1, InStr( line, "(" ) - 1 ), Tv_Functions )
HyGo_Memory_%zW% := A_Index
HyGo_History_%A_Index% := zW
HyGo_List_Of_Items .= "`n" zW "`n" zH
}
Else
PendingFunction := SubStr( line, 1, InStr( line, "(" ) - 1 ), zH := A_Index
If !Mod(A_Index-1, 17)
Tooltip % Round( 100 * A_Index / TotalLines, 2 ) "%", 19, 3
}
Tooltip
Tv_Modify( Tv_Hotkeys, "Sort" )
Tv_Modify( Tv_Functions, "Sort" )
Tv_Modify( Tv_Subroutines, "Sort" )
Tv_Modify( TV_Goto_Gosub, "Sort" )
Tv_Modify( TV_Timers, "Sort" )
Return
; Sets a timer, so as to start the subroutine in a new thread, and
; sets a flag, so as not to set the timer more than once per event.
WM_MOUSEMOVE(wparam, lparam, msg, hwnd)
{
Global HyGo_Gui_2_Is_Shown
If ( A_Gui = 1 && HyGo_Gui_2_Is_Shown = 0 )
{
SetTimer, HyGo_Build_And_Show_Gui_2, -10
HyGo_Gui_2_Is_Shown := 1
}
}
; Internal function for use with a DllCall to "AnimateWindow". Stores preferred modes
; and intelligently inverts the directions for showing and hiding. This makes it easy for
; a gui window to 'roll out' and 'roll in' in opposite directions (away from, then towards
; the same imaginary line or point ).
HyGo_Gui_Anim( Mode )
{
Static AnimCode:=0, UpDown:=0, LeftRight:=0, Center:=0
If Mode = Show
return 0x20000 + AnimCode + UpDown + LeftRight + Center
If Mode = Hide
return 0x10000 + AnimCode + (LeftRight>0) * (3-LeftRight)
+ (UpDown > 0) * (12-UpDown) + Center
If Mode = Slide
AnimCode ^= 0x40000
Else If Mode = Blend
AnimCode ^= 0x80000
Else If Mode = Center
Center ^= 16, LeftRight *= !Center, UpDown *= !Center
Else If Mode = Up
UpDown := 4
Else If Mode = Down
UpDown := 8
Else If Mode = Left
LeftRight := 2
Else If Mode = Right
LeftRight := 1
Return AnimCode + UpDown + LeftRight + Center
}
; Internal function for positioning guis relative to either the screen or a window
HyGo_Gui_Docking( HWND, GuiN )
{
Global HyGo_Docking_Screen_Or_Window
, HyGo_Docking_Left_Center_Right
, HyGo_Docking_Top_Center_Bottom
, HyGo_Docking_Inside_Outside
, Gui_Width, Gui_Height
, 1Gui_Width, 1Gui_Height
, 2Gui_Width, 2Gui_Height
WinGetPos, BoxLeft, BoxTop, BoxRight, BoxBottom, Ahk_ID %HWND%
If InStr( HyGo_Docking_Screen_Or_Window, "Screen" ) = 1
{
StringTrimLeft, MonCount, HyGo_Docking_Screen_Or_Window, 6
MonCount = %MonCount%
If MonCount is NOT INTEGER
{
SysGet, MonCount, 80
WinMidX := BoxLeft + BoxRight / 2
WinMidY := BoxTop + BoxBottom / 2
Loop, % MonCount
{
SysGet, Box, Monitor, %A_Index%
If ( BoxLeft <= WinMidX && WinMidX <= BoxRight )
&& ( BoxTop <= WinMidY && WinMidY <= BoxBottom )
Break
}
}
}
Else BoxRight += BoxLeft, BoxBottom += BoxTop
; Now, we have our box that shares one edge with our gui window
; we'll next figure out the X and Y of our gui's top left corner
; If the gui is to be docked inside, then the docking edge will be the
; same as the gui's edge, otherwise, they will be opposite
If HyGo_Docking_Inside_Outside NOT IN outside,inside
{
WinGet, MinMax, MinMax, Ahk_ID %HWND%
HyGo_Docking_Inside_Outside := MonCount || MinMax = 1 ? "Inside" : "Outside"
}
If !GuiN
{
GuiW := Gui_Width
GuiH := Gui_Height
If InStr( Gui_Width, "R" )
Loop, Parse, Gui_Width, %A_Tab% `,
If ( A_LoopField + 1 )
GuiW := Round( A_LoopField * ( BoxRight - BoxLeft ) )
If InStr( Gui_Height, "R" )
Loop, Parse, Gui_Height, %A_Tab% `,
If ( A_LoopField + 1 )
GuiH := Round( A_LoopField * ( BoxBottom - BoxTop ) )
return "W" (2Gui_Width := GuiW) " H" (2Gui_Height := GuiH)
}
If HyGo_Docking_Inside_Outside = Outside
{
If HyGo_Docking_Left_Center_Right = Right
GuiX := BoxRight
Else If HyGo_Docking_Left_Center_Right = Left
GuiX := BoxLeft - %GuiN%Gui_Width
Else GuiX := Round( BoxLeft / 2 + BoxRight / 2 - %GuiN%Gui_Width / 2 )
If HyGo_Docking_Top_Center_Bottom = Bottom
GuiY := BoxBottom
Else If HyGo_Docking_Top_Center_Bottom = Top
GuiY := BoxTop - %GuiN%Gui_Height
Else GuiY := Round( BoxTop / 2 + BoxBottom / 2 - %GuiN%Gui_Height / 2 )
} Else {
If HyGo_Docking_Left_Center_Right = Right
GuiX := BoxRight - %GuiN%Gui_Width
Else If HyGo_Docking_Left_Center_Right = Left
GuiX := BoxLeft
Else GuiX := Round( BoxLeft / 2 + BoxRight / 2 - %GuiN%Gui_Width / 2 )
If HyGo_Docking_Top_Center_Bottom = Bottom
GuiY := BoxBottom - %GuiN%Gui_Height
Else If HyGo_Docking_Top_Center_Bottom = Top
GuiY := BoxTop
Else GuiY := Round( BoxTop / 2 + BoxBottom / 2 - %GuiN%Gui_Height / 2 )
If ( HyGo_Docking_Left_Center_Right = "Left" ) && GuiN = 1
GuiX -= %GuiN%Gui_Width // 3
If ( HyGo_Docking_Left_Center_Right = "Right" ) && GuiN = 1
GuiX -= %GuiN%Gui_Width
If ( HyGo_Docking_Top_Center_Bottom = "Top" )
&& ( HyGo_Docking_Left_Center_Right != "Center" ) && GuiN = 1
GuiY += 53
}
return " X" GuiX " Y" GuiY
}
WinWaitActive( ArrayLength = 1, WinTitleArray="", WinTextArray="", ExTitleArray="", ExTextArray="" )
{
Local FoundWinHWND, Suffix:=1
While !FoundWinHWND := WinActive( %WinTitleArray%%Suffix%, %WinTextArray%%Suffix%
, %ExTitleArray%%Suffix%, %ExTextArray%%Suffix% )
{
Suffix := ArrayLength > 1 ? 1 + Mod( Suffix, ArrayLength ) : Suffix ? "" : 1
Sleep 20
}
return FoundWinHWND
}
; Excerpt from [VxE]'s Edit control manipulation library. This function causes
; the indicated edit control to scroll until the indicated line is the topmost visible
; line of the edit control. If LineNum is not a number, it will scroll to the caret's line
Edit_ScrollToLine( EditNNorHWND="Edit1", LineNum="Caret", Title="", Text="", ExTitle="", ExText="" )
{
If EditNNorHWND is NOT INTEGER
ControlGet, EditNNorHWND, HWND,, %EditNNorHWND%
, %Title%, %Text%, %ExTitle%, %ExText%
ExText := !Floor( LineNum += 1 )
SendMessage, 277, 6 + ExText, 0,, Ahk_ID %EditNNorHWND%
SendMessage, 182 + ExText, 0, !ExText * LineNum,, Ahk_ID %EditNNorHWND%
return LineNum
}
|
_________________ My Home Thread
Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags !
Last edited by [VxE] on Thu Feb 11, 2010 7:37 am; edited 1 time in total |
|
| Back to top |
|
 |
pajenn
Joined: 07 Feb 2009 Posts: 349
|
Posted: Mon Oct 19, 2009 8:35 pm Post subject: Re: Clipboard Execute |
|
|
VxE, I really like your ClipEx script, but I'm doing something wrong because half the time I get the following type of error message:
| Quote: | | The script file "R:\My Programs\AutoHotkey\_SCRIPTS\ClipEx1601.ahk" does not exist. Create it now? |
I have ClipEx.ahk in my _SCRIPTS folder with my AutoHotkey.ahk script.
| Code: | | #Include %A_ScriptDir%\ClipEx.ahk |
is the first line of AutoHotkey.ahk
The piece of code I tried to execute in this instance was
| Code: | StringLeft,A_ProgramFiles2,A_ScriptDir, % InStr(A_ScriptDir,"\",False,4)-1
MsgBox % A_ProgramFiles2 |
i.e. I wanted to check that my secondary program files folder specification was correct (makes it easier to transfer script to other drives/computers), and I didn't want to have to copy/paste it into a new temporary script, etc...
Any suggestions?
| [VxE] wrote: | A more recent manifestation of one of my earlier scripts. This script attempts to run the contents of the clipboard as an AHK script with added safeguards and self-cleaning features.
Update: 8-28-09. Major overhaul. The script is now optimized to be included (either by copy/paste or #Include) in any 'hotkeys & hotstrings' type script. Simply put the script's text (or #Include line) in the autoexecute section, and it will not interrupt the autoexecute sections of other functions in the same script. The default hotkey for this script is [win]+[tab].
Additional features:
- Any number of files may be included (via #Include) in the script generated by the ClipEx function. See the comments regarding the 'ClipEx_Includes' variable
- Certain keywords are under the 'Blacklist' variable, if any of those words are found on the clipboard, a confirmation dialogue will ask whether you wish to run the code anyways.
- The script file that is generated each time the function runs is deleted if it is no longer running.
- Multiple spawned scripts should be no problem... up to a couple hundred anyways.
- When executing code with a gui, the label "GuiClose" is added if it isn't already in the code. The label is followed by "Exitapp"
| Code: | ; ClipEx3
; Clipboard Execute, version 3
; ################### Easy Include #################
SetTimer, ClipEx_Initialize, -100 ; set the timer on our initialization.
Goto, ClipEx_Easy_Script_Inclusion ; proceed to the next autoexecute section.
; ################### ClipEx Settings ################
; The hotkey for the ClipEx function is Win + Tab
; Additional hotkeys may be bound with the ClipEx function by following the example on the next line
ClipEx_Initialize:
ClipEx_Lifespan = 60 ; seconds until the script terminates unconditionally
ClipEx_BeginKey = #Tab ; a hotkey to start the routine
ClipEx_CancelKey = Esc ; put a hotkey here to be a killswitch for the script
ClipEx_Blacklist = ; a list of keywords which will cause a confirmation message to show
; if the script contains any of them (even if they're in comments in the script)
( ltrim, join`n
regwrite
filedelete
A_Startup
shutdown
onexit
UrlDownloadToFile
)
ClipEx_Includes =
( ltrim c join`n
; list of files to be included at the bottom of the script. intended for
; testing of projects. if a directory is specified, every .ahk script in
; that directory (not sub-directories) will be included in the test script.
; Note: if an absolute path isn't specified, the script will look for them
; relative to the script's own folder, regardless of the current working dir.
; Only files that exist will be included.
C:\Documents and Settings\Administrator\My Documents\Arkham Tools\DeckEngine\Functions
)
; ################# ClipEx Initialization ###############
ClipEx_Template =
( ltrim join`r`n
SetTimer, ClipEx_Cleanup, -%ClipEx_LifeSpan%000
Hotkey, %ClipEx_CancelKey%, ClipEx_Cleanup, on
<<>>The Script's Text<<>>
ClipEx_Cleanup:
critical
Exitapp
; Included Scripts
)
ClipEx_w := A_WorkingDir
SetWorkingDir, %A_ScriptDir% ; set the working dir to this script dir
Loop, Parse, ClipEx_Includes, `n, `r %A_Tab%
If InStr( ClipEx_m := FileExist( A_LoopField ), "D" ) ; if the file is a directory
Loop, % A_LoopField . ( SubStr( A_LoopField, 0 ) = "\" ? "" : "\" ) . "*.ahk"
ClipEx_Template .= "`r`n#Include, " A_LoopFileLongPath
Else If (ClipEx_m)
ClipEx_Template .= "`r`n#Include, " A_LoopField
SetWorkingDir, %ClipEx_w% ; restore previous working dir
ClipEx_p := "`n"
Hotkey, %ClipEx_BeginKey%, ClipExSubroutine, on
return
; ##################### ClipEx Subroutine #############
ClipExSubroutine:
Thread, NoTimers ; cuz we don't need interruptions
ClipEx_ := ClipEx_Template
If InStr( Clipboard, "Gui" ) && !InStr( Clipboard, "GuiClose:" )
StringReplace, ClipEx_, ClipEx_, ClipEx_Cleanup, GuiClose, All
StringReplace, ClipEx_, ClipEx_, <<>>The Script's Text<<>>, %Clipboard%
ClipEx_fbl := "", ClipEx_m := 0
Loop, parse, ClipEx_blacklist, `n
If InStr(Clipboard, A_LoopField)
ClipEx_fbl .= Chr(160) . A_LoopField, ClipEx_m++
StringTrimLeft, ClipEx_fbl, ClipEx_fbl, 1
Loop, % ClipEx_m - 2
StringReplace, ClipEx_fbl, ClipEx_fbl, % Chr(160), % """, """
StringReplace, ClipEx_fbl, ClipEx_fbl, % Chr(160), " and "
If ClipEx_m
{
ClipEx_m := ClipEx_m = 1 ? "" : "s" ; gramMaR!
ClipEx_w := ClipEx_m = "" ? "was" : "were" ; what it is
MsgBox, 52, Security Warning !!,
( ltrim join`s
The word%ClipEx_m% "%ClipEx_fbl%" %ClipEx_w%
found in the clipboard.`nThis could cause
undesired or malicious effects if run.
`n`nDo you wish to continue ?
)
IfMsgBox, No ; the user decided not to run the code after all
return
}
Random,, % A_Now ^ A_TickCount
Loop, 9 ; try not to use a script name that's already in use
{
Random, ClipEx, 1000, 9999
ClipEx = ClipEx%ClipEx%.ahk
IfNotExist, %ClipEx%
Break
}
FileAppend, %ClipEx_%, %ClipEx%
Sleep 50
Run, %A_AhkPath% "%ClipEx%",,, ClipEx_m ; keep the PID of the spawned script
ClipEx_p .= ClipEx_m . "?" . ClipEx . "`n" ; append it to our list
SetTimer, ClipEx_check_existence, 200
return
ClipEx_check_existence: ; this is where we check each script
DetectHiddenWindows, on ; that we've run to see if it's still running
If ( ClipEx_p = "`n" )
SetTimer, ClipEx_check_existence, off
Else Loop, Parse, ClipEx_p, `n ; parse through the list
{
StringSplit, ClipEx_, A_LoopField, ?
If ClipEx_0 <> 2
continue
If !WinExist( "Ahk_PID " ClipEx_1 ) ; if the script's window can't be found
{
StringReplace, ClipEx_p, ClipEx_p, `n%A_LoopField%`n, `n
FileDelete, %ClipEx_2% ; delete it and remove it from our list
}
}
return
; ################### Easy Include, Part 2 ################
; This label makes it easy to merge this script into another script
; In the auto-execute section of this script, this label is called via
; Goto, allowing scripts pasted below the label to initialize properly.
ClipEx_Easy_Script_Inclusion: |
|
_________________ Hardware: 1.8 GHz laptop with 4 GB ram
Software: Windows XP/SP3, Rising Antivirus, Online Armor firewall, Dragon NaturallySpeaking Pro + Natlink (with Vocola/Unimacro) and AHK for macro support. |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 2393
|
Posted: Tue Oct 20, 2009 7:35 am Post subject: |
|
|
Yes, I know that error. I still get it occasionally too. I don't know exactly why it happens, but when I added the "Sleep 50" between the FileAppend and Run, it seemed to help. Perhaps if you increase the sleep time to 250, it will help. _________________ My Home Thread
Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags ! |
|
| Back to top |
|
 |
pajenn
Joined: 07 Feb 2009 Posts: 349
|
Posted: Tue Oct 20, 2009 9:29 am Post subject: |
|
|
| [VxE] wrote: | | Yes, I know that error. I still get it occasionally too. I don't know exactly why it happens, but when I added the "Sleep 50" between the FileAppend and Run, it seemed to help. Perhaps if you increase the sleep time to 250, it will help. |
Didn't work.
By the way, have you considered piping the clipboard content? Something like:
| Code: | #Tab::
Clipboard =
Send ^c ;copy selected code
ClipWait,1
script =
(
%Clipboard%
Esc::ExitApp ;esc to exit
)
RunScript(script) ;run selected code through a pipe
Return |
Requires: Lexikos' RunScript.ahk* and CreateNamedPipe.ahk functions in Lib folder. (HotkeyIt posted the functional form of RunScript, so I linked to it.) _________________ Hardware: 1.8 GHz laptop with 4 GB ram
Software: Windows XP/SP3, Rising Antivirus, Online Armor firewall, Dragon NaturallySpeaking Pro + Natlink (with Vocola/Unimacro) and AHK for macro support. |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 2393
|
Posted: Tue Oct 20, 2009 7:55 pm Post subject: |
|
|
I'm sorry the script is giving you so much trouble. Yes, i had thought about using Lexicos's pipes, and you are certainly welcome to implement that instead of a temporary script file. The reason I didn't go with pipes is because certain variables might be unreliable ( A_ScriptDir, for example ) and having a file makes debugging simpler if the script was generated artificially.
[unrelated edit:] | Code: | Monitor( which="", what="80", where="mouse" )
{ ; wrapper for sysget command, inclined towards monitor info
If what in Monitor,MonitorWorkArea,MonitorName
{
If where not between 1 and 15
{
If where is not number
{
Coordmode, mouse, screen
MouseGetPos, x, y
}
Else If WinExist("Ahk_ID " where )
{
WinGetPos, x, y, w, h
x += w//2
y += w//2
}
Sysget, where, 80
If where > 1
Loop, % where
{
Sysget, ov, Monitor, % where := A_Index
If ( ovleft <= x && x <= ovright )
&& ( ovtop <= y && y <= ovbottom )
Break
}
}
Sysget, ov, %what%, %where%
Return ov%which%
}
Sysget, ov, %what%
Return ov
} |
| Code: | ; [VxE]'s Marx Engine: Buttonless Mouse Gestures.
; for advanced users only... because I don't offer support for it.
Marx_Timeout = 300 ; milliseconds before Marx are reset
Marx_Distance = 10 ; pixel distance before Marx updated
Marx_Fields = 4 ; number of quadrants for Marx.
; The center of field 1 is directly to the right (+X axis)
; Other fields are numbered sequentially clockwise
#Persistent
SetTimer, MouseWatch, 10
OldX := OldY := 0
OldT := A_TickCount
MouseWatch:
Coordmode, Mouse, Screen
MouseGetPos, NewX, NewY
If Math_XY2Pol( rad, NewX - OldX, NewY - OldY) > Marx_Distance {
If (0+Pip) != Pip := 1 + Mod( Floor(( 3.14159265358979323846 + rad * Marx_Fields ) / 6.28318530717958647692), Marx_Fields )
Marx .= "_" . Pip
OldX := NewX
OldY := NewY
OldT := A_TickCount + Marx_Timeout
}
If ( A_TickCount > OldT )
{
OldT := A_TickCount + Marx_Timeout
If IsLabel( "Marx" Marx )
SetTimer, Marx%Marx%, -1
Else If IsLabel( "Marx" ( Marx := SubStr( Marx, 3 ) ) )
SetTimer, Marx%Marx%, -1
Marx := ""
}
return
; 2 3 4 1 2 is down left up right down, aka a CW circle starting at the right side
Marx_2_3_4_1_2:
Click L Down
Tooltip Ld
SetTimer, RemoveTooltip, -%Marx_Timeout%
Return
; 4 3 2 1 4 is up left down right up, aka a CCW circle starting at the right side
Marx_4_3_2_1_4:
Click L Up
Tooltip Lu
SetTimer, RemoveTooltip, -%Marx_Timeout%
return
; 1 3 1 3 is right left right left
Marx_1_3_1_3:
Click M
Tooltip M
SetTimer, RemoveTooltip, -%Marx_Timeout%
Return
Marx_2_4_2_4:
Click R
Tooltip R
SetTimer, RemoveTooltip, -%Marx_Timeout%
Return
; 2 1 4 3 2 is a CCW circle starting at the left
Marx_2_1_4_3_2:
Send {XButton1}
Tooltip X1
SetTimer, RemoveTooltip, -%Marx_Timeout%
Return
; 4 1 2 3 4 is a CW circle starting at the left
Marx_4_1_2_3_4:
Send {XButton2}
Tooltip X2
SetTimer, RemoveTooltip, -%Marx_Timeout%
Return
RemoveTooltip:
Tooltip
return
Math_XY2Pol( byref out_rads, X, Y ) {
; Function by [VxE]. Takes ( X, Y ) coord and converts to polar coordinates, in radians
If !X
out_rads := (3.14159265358979323846) * ( 1 + ( Y < 0 ) * 2 ) / 2 * ( Y != 0 )
Else
out_rads := ATan( Y / X ) + (3.14159265358979323846) * ( 2 - 2 * ( X > 0 && Y >= 0 ) - ( X < 0 ) )
Return Sqrt( X**2 + Y**2 )
} |
_________________ My Home Thread
Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags !
Last edited by [VxE] on Thu Feb 11, 2010 7:38 am; edited 5 times in total |
|
| Back to top |
|
 |
Win9x supporter Guest
|
Posted: Wed Oct 21, 2009 5:38 am Post subject: |
|
|
| [VxE] wrote: | | Yes, i had thought about using Lexicos's pipes, and you are certainly welcome to implement that instead of a temporary script file. The reason I didn't go with pipes is because certain variables might be unreliable ( A_ScriptDir, for example ) and having a file makes debugging simpler if the script was generated artificially. |
I, for one, am greatful you did not use named pipes because I (like some other ahk users) must assure that our scripts can run on Win9x machines (which do not support these pipes).
VxE, thx for your many useful scriipts (and tips/tricks that I find in your posts in Ask for Help ) |
|
| Back to top |
|
 |
luetkmeyer Guest
|
Posted: Thu Feb 25, 2010 2:56 pm Post subject: Re: Online Dictionary Easy Lookup Script |
|
|
| [VxE] wrote: | Don't know what a word means? Just Control+Double-Click it (while this script is running)
The variable at the top (page) contains the URL for the results page of a dictionary or search page, some other popular ones are listed in comments below. To use a different search site, simply go to that site, type in a unique word into the search field, click 'search', then get the URL from the results page and replace your unique word with []MySearchTarget[] and put that into the script.
| Code: | ; [VxE]'s Ctrl+DblClick word lookup script
page = http://dictionary.cambridge.org/results.asp?searchword=[]MySearchTarget[]&x=48&y=1
; page = http://www.merriam-webster.com/dictionary/[]MySearchTarget[]
; page = http://www.google.com/search?hl=en&q=[]MySearchTarget[]&btnG=Google+Search
; page = http://search.yahoo.com/search?p=[]MySearchTarget[]&fr=yfp-t-501&toggle=1&cop=mss&ei=UTF-8
; page = http://en.wikipedia.org/wiki/Special:Search?search=[]MySearchTarget[]&fulltext=Search
~^LButton::
MouseGetPos, px, py
pm := px . py
If ( A_PriorHotkey = A_ThisHotkey )
&& (A_TimeSincePriorHotkey < DllCall("GetDoubleClickTime"))
&& (om = pm) ; if the mouse moved, it wasn't a double-click
{
Sleep 150
sclip := clipboardall
Clipboard := ""
Send ^c
Clipwait, 1
StringReplace, specpage, page, []MySearchTarget[], %Clipboard%
Clipboard := sclip
Run %specpage% ; open page in default browser
}
Else
om := pm
return |
|
Great! |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|