no message

no message

;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;~ please use this ! as first line in every script before all includes! :)
isDevellopperMode=true ; enthllt auch update script.
; useful REGex:
;        ^[^\n\r:]*::            find hotkeys
;         ^((?!::).)*$\n              find every line is not a hotkey
;        ^[^;:\n]+:[ ]*$       find labels (you could export search results with jetbrains products and clean it with ^\s*.*\)\s* )
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

#Include init_global.init.inc.ahk
#InstallKeybdHook
DetectHiddenWindows,on
SetTitleMatchMode,2

CoordMode, Pixel , Screen
CoordMode, Caret , Screen

;~ #InputLevel 1

;~ keyState_Numpad := GetKeyState("NumpadAddOOOOO","P")
keyState_Numpad := GetKeyState("NumpadAdd","P")
;~ MsgBox,%keyState_Numpad% = keyState_Numpad (line:%A_LineNumber%) `n
if (keyState_Numpad <> "")
{
   isNumPadAvailable := true
   ;	The variable will be empty (blank) if the state of the key could not be determined.
   ;~ MsgBox,%isNumPadAvailable% = isNumPadAvailable (line:%A_LineNumber%) `n
}else  {
   isNumPadAvailable := false
   ;	The variable will be empty (blank) if the state of the key could not be determined.
   MsgBox,,,%isNumPadAvailable% = isNumPadAvailable (line:%A_LineNumber%) `n,3
}

#IfWinActive SciTE4AutoHotkey
; Refactoring Engine

#IfWinActive SciTE4AutoHotkey

Alt_UP:
   Alt & Up::
   Send,{AltUp}
   Last_A_This:=A_ThisFunc . A_ThisLabel . "`n actually not implemented `n "
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This) ;
   ;~ drawButtons("aw" , 150)  ; x b = ctrsl a = alt j = shift q=f6 w = up y =down `` = reset, didnt found a backspace fontKey
   DetectHiddenWindows,on
   IfWinNotExist,SL5_phpGeneratedRunOnChanged.ahk.ahk
      run,SL5_phpGeneratedRunOnChanged.ahk.ahk
   Send,{Blind}
   markerXXXXstring :="xxxxxxxx" . "xxxxxxxx"
   Send,{Right} `; %markerXXXXstring%{space}
   drawButtons("aw" , 150) ; w = up
   ;Get the filename
   oSciTE := GetSciTEInstance()
   if(!oSciTE)
   {
      Send,^z{AltUp}
      return
   }
   oSciTE_CurrentFile := oSciTE.CurrentFile
   ; To fetch only the bare filename from the above:
   SplitPath, oSciTE_CurrentFile , filename
   doSaveFirst := isFileOpendInSciteUnsaved(filename)
   phpFile = Reformatting_Autohotkey_Source.php
   argv = --source1="%oSciTE_CurrentFile%" --A_ThisLabel="%A_ThisLabel%"
   runPHP_link := getRunPHP_link(phpFile , argv)
   if(doSaveFirst)
      saveWait(A_ScriptDir)
   Suspend,on
   Send,^z ; delte marker
   run, % runPHP_link ,,Hide
   if(!doSaveFirst)
      Sleep,250
   runPHP_link_runP = %runPHP_link% = runPHP_link (line:%A_LineNumber%) `n
   Suspend,off
   Send,{Blind}
return

#IfWinActive SciTE4AutoHotkey
Alt_Down:
   Alt & Down::
   Send,{AltUp}
   Last_A_This:=A_ThisFunc . A_ThisLabel . "`n actually not implemented `n "
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This) ;
   DetectHiddenWindows,on
   IfWinNotExist,SL5_phpGeneratedRunOnChanged.ahk.ahk
      run,SL5_phpGeneratedRunOnChanged.ahk.ahk
   Send,{Blind}
   markerXXXXstring :="xxxxxxxx" . "xxxxxxxx"
   Send,{Right} `; %markerXXXXstring%{space}
   drawButtons("ay" , 150)
   ;   ;Get the filename
   oSciTE := GetSciTEInstance()
   if(!oSciTE)
   {
      Send,^z{AltUp}
      return
   }
   ; oSciTE_CurrentFile := oSciTE.CurrentFile
   ; To fetch only the bare filename from the above:
   SplitPath, oSciTE_CurrentFile , filename
   doSaveFirst := isFileOpendInSciteUnsaved(filename)
   phpFile = Reformatting_Autohotkey_Source.php
   argv = --source1="%oSciTE_CurrentFile%" --A_ThisLabel="%A_ThisLabel%"
   runPHP_link := getRunPHP_link(phpFile , argv)
   if(doSaveFirst)
      saveWait(A_ScriptDir) ;
   Suspend,on
   Send,^z ; delte marker
   run, % runPHP_link ,,Hide
   if(!doSaveFirst)
      Sleep,250
   runPHP_link_runP = %runPHP_link% = runPHP_link (line:%A_LineNumber%) `n
   Suspend,off
   Send,{Blind}
return

;~ Rename, Shift+F6, Rename the selected file, class, field, method, etc.
#IfWinActive SciTE4AutoHotkey
+f6::

/*
it replaces names in namespace and sub namespaces.
it depends if your cursor is inside {

} or outside {

}.
means it's different if you replace variable names inside function body or inside function signature. that gives you the ability to replace calling names also if you want.
v1
funZ(v1){
   v1
}
*/

Last_A_This:=A_ThisFunc . A_ThisLabel
a_LineInfo := A_LineNumber . " - " . A_ScriptName . " - " . Last_A_This
ToolTip1sec(a_LineInfo)
drawButtons("jq" , 150)  ; j = shift q=f6

rename_Shift_F6 := "not fully implemented jet. 04.07.2015 11:57`n "
rename_Shift_F6 .= "Rename, Shift+F6, Rename field, method, file, class,  etc."
doSelectLine:=false
symbolName := copyLineOrWord2clipBoard(doSelectLine)
symbolName := RegExReplace(symbolName,"\W+","")
Send,{Blind}
markerXXXXstring :="xxxxxxxx" . "xxxxxxxx"
Send,{Right} `; %markerXXXXstring%{space}
;~ MsgBox,%c% = c (line:%A_LineNumber%) `n %rename_Shift_F6% = rename_Shift_F6 (line:%A_LineNumber%) `n

inputH := 200
timeoutSec := ""
SetTitleMatchMode,3
msg=Rename %symbolName% ?

SetTitleMatchMode,2
WinGetPos,x,y,w,h,SciTE4AutoHotkey
InputBox, symbolName , %msg%,%msg% , , 200 , %inputH%  , % ( x + w / 2 - 50 ) , % ( y + h / 2 - 50 ) , , %timeoutSec%  , %symbolName%
if ErrorLevel = 1
{
   Send,^z
   return
}
msg=New Name for %symbolName% ?
; InputBox, OutputVar [, Title, Prompt, HIDE, Width, Height, X, Y, Font, Timeout, Default]
;~ SetTitleMatchMode,2
;~ WinGetPos,x,y,w,h,SciTE4AutoHotkey
;~ InputBox, symbolName , %msg%,%msg% , , 200 , %inputH%  , % ( x + w / 2 - 50 ) , % ( y + h / 2 - 50 ) , , %timeoutSec%  , %symbolName%

SetTitleMatchMode,2
WinGetPos,x,y,w,h,SciTE4AutoHotkey

InputBox, symbolNameNew , %msg%,%msg% , , 200 , %inputH%  , % ( x + w / 2 - 50 ) , % ( y + h / 2 - 50 ) , , %timeoutSec%  , %symbolName%
WinSet, AlwaysOnTop, On, %msg%
if ErrorLevel = 1
{
   Send,^z
   return
}

;Get the filename
oSciTE := GetSciTEInstance()
oSciTE_CurrentFile := oSciTE.CurrentFile
; To fetch only the bare filename from the above:
SplitPath, oSciTE_CurrentFile , filename
doSaveFirst := isFileOpendInSciteUnsaved(filename)
phpFile = Reformatting_Autohotkey_Source.php
argv = --source1="%oSciTE_CurrentFile%"

argv = %argv% --renameSymbol="%symbolName%" --renameSymbol_To="%symbolNameNew%"
;~ Clipboard=%argv%
runPHP_link := getRunPHP_link(phpFile , argv)

if(doSaveFirst)
   saveWait(A_ScriptDir)
run, % runPHP_link ,,Hide
if(!doSaveFirst)
   Sleep,250
secWait:=1
;~ secWait:=""
MsgBox,,SL5 Source Reformatting finished and saved,SL5 Source Reformatting finished `n  file saved `n  backup saved`n `n %runPHP_link% = runPHP_link (line:%A_LineNumber%) `n ,%secWait%
Suspend,off
return

MsgBox,%runPHP_link% = runPHP_link (line:%A_LineNumber%) `n
return

Ctrl_Alt_L:
   Strg_Alt_L:
   Ctrl & l::
   if( !GetKeyState("alt", "P") ){
      return
   }
   Last_A_This:=A_ThisFunc . A_ThisLabel
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   drawButtons("baL" , 150)  ; b = ctrsl a = alt j = shift q=f6
   strg_alt_l()
return

ExtractMethod:
   Ctrl_Alt_M:
   Strg_Alt_M:
   Ctrl & m::
   Last_A_This:=A_ThisFunc . A_ThisLabel
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   if( !GetKeyState("alt", "P") ){
      Suspend,on
      send,^
      Suspend,off
      return
   }
   ;~ jkj
   ;~ MsgBox,15-06-12_22-08
   drawButtons("baM" , 150)  ; b = ctrsl a = alt j = shift q=f6

   ClipboardBackup := Clipboard
   Clipboard:=""
   loopCounter:=0
   c:=copySelection2clipBoard()
   ;~ c=%Clipboard%
   defaultInput:=""
   cMethodBody := ""
   line:=""
   lineNotEmpty:=""
   Loop , Parse , c, `n
   {
      line := A_LoopField
      if(!defaultInput)
         defaultInput:=RTrim(RegExReplace(line,"i).*?(\w+).*?","m$1") , "`s`n`t`r")
      ;~ MsgBox, %A_LoopField%
      line := RegExReplace(line,"^[\s\n\t\r]+","")
      if(StrLen(line))
         lineNotEmpty := line
      cMethodBody .= "   "  .  line . "`n"
   }
   ;
   returnValue :=RegExReplace( lineNotEmpty ,"i)^[`a.]*?([a-z]+)[^w]*$","$1")
   ;~ MsgBox,'%returnValue%' = returnValue `n
   ;~ Reload
   cMethodBody := RegExReplace(cMethodBody,"i)[\s\n\t\r]+$","")
   inputH := 200

   SetTitleMatchMode,2
   WinGetPos,x,y,w,h,SciTE4AutoHotkey

   timeoutSec := ""

   SetTitleMatchMode,3
   ;~ msg= Extract Clipboard as Method?
   msg:="Extract as Method: Method Name?"

   ; InputBox, OutputVar [, Title, Prompt, HIDE, Width, Height, X, Y, Font, Timeout, Default]

   InputBox, methodName , %msg% , %msg% , , 200 , %inputH%  , % ( x + w / 2 - 50 ) , % ( y + h / 2 - 50 ) , , %timeoutSec%  , %defaultInput%
   WinSet, AlwaysOnTop, On, %msg%
   if ErrorLevel = 1
return
if( methodName == "")
   return
WinWaitNotActive, %msg%
send,{esc} ; go out of search text box or so
Sleep,10
markerXXXXstring :="xxxxxxxx" . "xxxxxxxx"
Send,{BackSpace} `; %markerXXXXstring%
;~ mName=%defaultInput%
;~ i Case-insensitive matching, which treats the letters A through Z as identical to their lowercase counterparts.
;~ `a In v1.0.46.06+, `a recognizes any type of newline, namely `r, `n, `r`n, `v/VT/vertical tab/chr(0xB), `f/FF/formfeed/chr(0xC), and NEL/next-line/chr(0x85). In v1.0.47.05+, newlines can be restricted to only CR, LF, and CRLF by instead specifying (*ANYCRLF) in uppercase at the beginning of the pattern (after the options); e.g. im)(*ANYCRLF)^abc$.
defaultInput := LTrim( RegExReplace( RegExReplace( cMethodBody , "i)[^w]*?([a-z_0.9]+)[^w]*?" , ", $1" ) ,"im)[\s\n\t\r]+" , " "),"`n,`s")  ; ugly buti dont have tim :-D ;)
;~ MsgBox,%defaultInput%
;~ Reload
msg=Method Parameters of '%methodName%' ?

InputBox, methodParameters , %msg%,%msg% , , 555 , %inputH%  , % ( x + w / 2 - 50 ) , % ( y + h / 2 - 50 ) , , %timeoutSec%  , %defaultInput%
WinSet, AlwaysOnTop, On, %msg%
if ErrorLevel = 1
return
WinWaitNotActive, %msg%
Send,{Blind}
;~ Send,{Home}{enter}{up}%mName%
;
methodSignature := methodName . "(" . methodParameters . ")"
Suspend,on
Send,`n%methodSignature%`n
Sleep,100
c1=`n%methodSignature%{`n
c3= `n   return %returnValue% `n}
c := c1 . cMethodBody . c3
;~ StringReplace,c,c,`n`n,`n
Clipboard := c
Send,{CtrlDown}{End}{CtrlUp}
SetKeyDelay,50,50
Sleep,200
Send,^v
Send,^f
Send,%markerXXXXstring%{enter}{del}{esc}
Send,{Space}
;~ Send,{Blind}
Suspend,off
;~ MsgBox,new function is inside your clipboard. please paste it.
Clipboard := ClipboardBackup
send,{Blind}
return
;~ d_12356 := 12356
;~ 2, 2, 2,
; change commas
; different stiles

alt & c::
Last_A_This:=A_ThisFunc . A_ThisLabel
ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
doSelectLine := false
if( GetKeyState("Ctrl", "P") )
{
   ; thats bullshit. it shuld never happen. to go in here.
   ; lets better make an normal copy then?
   Suspend,on
   send,^c{Blind}
   Suspend,off
   return
}
if( GetKeyState("shift", "P") ) {
   Shift_Alt_C:
   drawButtons("jaC" , 150)  ; b = ctrsl a = alt j = shift q=f6
   doSelectLine:=true
   c := copyLineOrWord2clipBoard(doSelectLine)
}else  {
   Alt_C:
   drawButtons("aC" , 150)  ; b = ctrsl a = alt j = shift q=f6
   doSelectLine:=false
   ;~ ; normal copy. dont change it
   Suspend,on
   c := copySelection2clipBoard()
   if(!c)
   {
      Suspend,off
      return
   }
   ; 1,  2:5:5: 5
   ;~ Send,^c
}
Suspend,On
c := trim(c)
ClipboardBackup:= Clipboard
if(!doSelectLine)
{
   timeoutSec:=0
   inputH:=150
   msg= wiche delimiter would you replace? alle kind of delimiters is default. please insert a regular expression`n or Esc for cancel this refactoring
   delimiterOld := "[^\w]"

   SetTitleMatchMode,2
   WinGetPos,x,y,w,h,SciTE4AutoHotkey

   InputBox,delimiterOld,%msg%,%msg% , , 400 , %inputH%  , % ( x + w / 2 - 50 ) , % ( y + h / 2 - 50 ) , , %timeoutSec%  , %delimiterOld%
   WinSet, AlwaysOnTop, On, %msg%
   if ErrorLevel = 1
   return
   ; newline then its easy to change it later with additional shift without selecting it
   ;~ Send,`n
   msg= choose delimiter you like for your selection`n or Esc for cancel this refactoring
   if(RegExMatch(c, "," )){
      defaultInput := ":"
   }else                    if(RegExMatch(c, ":" ))                   {
      defaultInput := " "
   }else  {
      defaultInput := ","
   }

   SetTitleMatchMode,2
   WinGetPos,x,y,w,h,SciTE4AutoHotkey

   InputBox,delimiter,%msg%,%msg% , , 400 , %inputH%  , % ( x + w / 2 - 50 ) , % ( y + h / 2 - 50 ) , , %timeoutSec%  , %defaultInput%
   WinSet, AlwaysOnTop, On, %msg%
   if ErrorLevel = 1
   return
   ;  l l l ll k k jku i o 1uio 2uio 3
   ;~  , 4,5 6  ,1,23 ,1,2,3 ,1,2,3 ,1,2 ,3  ,1 2 3 1  2  3
   ;~ Clipboard := SubStr(  RegExReplace(c , "i)(\s*?[a-z0-9]+?)[^\w]?" , "$1" . delimiter . "")   , 1 , -1) ; works
   Clipboard := RegExReplace(c , "i)(\s*?[a-z0-9]+?)" . delimiterOld , "$1" . delimiter . "")
   ; 1, 2, 3
}
if(doSelectLine){
   ; RegExMatch() returns the position
   if(RegExMatch(c, "," )){
      Clipboard := RegExReplace(c , "," , ":")
   }else                    if(RegExMatch(c, ":" ))                   {
      Clipboard := RegExReplace(c , "`:" , ",")   ; this the beep ? [:]
      ToolTip3sec(A_LineNumber)
   }else  {
      ;~ if(RegExMatch(c, RegExMatch(c, "\s" ) )){
      Clipboard := RegExReplace(c , "([^,])\s(\s*)" , "$1,$2")
   }
}
; i: i: i:
;, :,  , :, :,  ,  , :,  , 4, :,  , 4, :,  , 4, :,  , 4, :,
;: i: i:
;~ MsgBox,%Clipboard% = Clipboard
;~ Reload
;~ 1, 2, 3, 5, 6,
if(Clipboard == ClipboardBackup)
{
   ;~ ToolTip,-----------
   ;~ Sleep,2000
   c2:=""
   strLen_c := StrLen(c)
   Loop, %strLen_c%
   c2 .= SubStr(c,A_Index,1) . ", "
   Clipboard := c2
}
; i:   i:   i:
;, :,  , :, :,  ,  , :,  , 4, :,  , 4, :,  , 4, :,  , 4, :,
;: i: i:
;~ MsgBox,%Clipboard% = Clipboard
;~ Reload
Send,{CtrlDown}v{CtrlUp}
Clipboard := ClipboardBackup
; newline then its easy to change it later with additional shift without selecting it
;~ ToolTip3sec("press Shift+Alt+c if you want change comma style for this line.`npress backspace if you bring your code back to last line.")
;~ Send,{CtrlDown}v{CtrlUp}{home}{Space}{Shift Down}{home}{Shift up}{BackSpace} ; jumps into new line and waits for backspace
Suspend,off
Send,{Blind}
;~ Now when you are coding you can quickly wrap commay with a quick cmd+shift+c for totals line or selection and the selection will be wrapped with quotes.  if you type it additional with shift line is wraped. try it :)
return
;~ bugs if you us the follwoing with shift alt c
;~ 0: 1: 2: 3: 4: 5: 6:
;~ a: b: c:^^^^

Surrounding_with_Quotes:
   Ctrl_J:
   Strg_J:
   Ctrl & q::
   Ctrl & j::
   Last_A_This:=A_ThisFunc . A_ThisLabel
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)

   doSelectLine := false
   if( GetKeyState("shift", "P") )
   {
      drawButtons("bjJ" , 150)  ; b = ctrsl a = alt j = shift q=f6
      doSelectLine := true
      ;~ ToolTip,'%doSelectLine%' = doSelectLine `n
   }
   else
      drawButtons("bJ" , 150)  ; b = ctrsl a = alt j = shift q=f6

   ;   uuu
   c := copyLineOrWord2clipBoard(doSelectLine)
   Suspend,On
   ;~ lk
   ; it toggles beetwn ( " and empty  and much more. try ;) . if you press shift it sorrounds the lline. default is the actually word
   if(doSelectLine)
   {
      c := trim(c)
      az_wd := ".*"
   }
   else
      az_wd := "[\w\d_]+"
   az_wd1 = "%az_wd%"
   az_wd2 = `%%az_wd%`%
   az_wd3 = \(%az_wd%\)
   az_wd4 = \{%az_wd%\}
   ;~ oiuoi lkjl oi o
   if(RegExMatch(c,az_wd1)){
      ; " c " => c
      Clipboard := RegExReplace(c,"""","")   . " "
   }else                    if(RegExMatch(c,az_wd2))                   {
      ;~ Clipboard := RegExReplace(c,"%","""")   . " "
      ; % => "
      Clipboard := RegExReplace(c,"%","""")   . " "
   }else  {
      if(doSelectLine){
         if(RegExMatch(c,az_wd4)){
            ; { c } => c
            Clipboard := RegExReplace(c,"\{(.*)\}","""$1""")   . " "
         }else                    if(RegExMatch(c,az_wd3))                   {
            Clipboard := RegExReplace(c,"\((.*)\)","{$1}")   . " "
            ; ( c ) => { c }
         }else  {
            ; c => ( c )
            Clipboard := "(" . c . ")" . " "
            ;~ Clipboard := RegExReplace(c,"""(.*)""","($1)")   . " "  lkjlkj
         }
      }else  {
         ; c => % c %
         Clipboard := RegExReplace(c,"([^\s]+)$","%$1%") . " "
      }
   }
   if(doSelectLine)
      Send,{CtrlDown}v{CtrlUp}{home}{Space}{Shift Down}{home}{Shift up}{BackSpace} ; jumps into new line and waits for backspace
   else
      Send,{CtrlDown}v{CtrlUp}
   Suspend,off
   ;~ Now when you are coding you can quickly wrap text in quotes with a quick cmd+j and the selection will be wrapped with quotes.  if you type it additional with shift line is wraped. try it :)
   send,{CtrlUp}  {Blind}
return

;  ;

;~ RegExReplacelll(A_LineNumber, "keys_SL5_AHK_Refactor_engine.ahk",Last_A_This)
Ctrl_Space:
   ^ & Space::
   ;~ MsgBox,lllkk
   Last_A_This:=A_ThisFunc . A_ThisLabel
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   drawButtons("bk" , 150)  ; b = ctrsl a = alt j = shift q=f6
   ;~ lll(A_LineNumber, "keys_SL5_AHK_Refactor_engine.ahk",Last_A_This)
   Suspend,on
   Send,^i
   Suspend,off
   Send,{CtrlUp}{Space}{Blind}
return

Tab:
   Tab::
   ; usaly i dont use tabs inside text. onliy for block indent
   Last_A_This:=A_ThisFunc . A_ThisLabel
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   drawButtons("v" , 150)  ; b = ctrsl a = alt j = shift q=f6 v = tab
   send,{Home}
   Suspend,on
   ;~ send,{Space4}{Space}{Space}
   send,{Tab}{down}
   Suspend,off
return

Circumflex:
   #IfWinActive SciTE4AutoHotkey
   ;~ i dont know why but this days ^ key not work in scite. so try a dirty bugFix
   ^::
   Last_A_This:=A_ThisFunc . A_ThisLabel . not_implemented_jet
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   If ( GetKeyState("shift", "P") || GetKeyState("alt", "P")  || GetKeyState("tab", "P") )
return
Suspend,on
SendRaw,^
Send,{Space}
Suspend,off
return
; ^ ui ^^^ ^{Space}^^^^press

Alt_F7:
   alt & f7::
   not_implemented_jet := not implemented jet
   ; todo create function for word selection
   Last_A_This:=A_ThisFunc . A_ThisLabel . not_implemented_jet
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
return

tillagoto_properties:
   ;~ TillaGoto tillagoto.properties s
   ;~ same as strg+b in jetbrains
   ;~ # Specify the hotkey you want to use to go to a function/label on whose name the
   ;~ # caret is located. Similar to the middleclicking feature.
   ;~ tillagoto.hk.goto.def=+Enter
   ; this worked: open it with notepad, save it to desktop, copy it back, and click yes to do it as administrator.
return

Strg_B:
   Ctrl_B:
   ^b::
   Last_A_This:=A_ThisFunc . A_ThisLabel
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   drawButtons("bB" , 150)  ; b = ctrsl a = alt j = shift q=f6

   showUsageInfoBox()
   ; this worked: open it with notepad, save it to desktop, copy it back, and click yes to do it as administrator.
   ;~ http://www.autohotkey.com/board/topic/38186-tillagoto-go-to-functions-labels-hks-in-your-script/page-10#entry704036
   ;~ MsgBox,15-06-10_12-51
   ;~ Suspend,on
   ; not use tillagoto.hk.goto.def=+Enter
   ;~ SendEvent,{ShiftDown}{Enter}{ShiftUp} ; dont work
   ;~ Suspend,off
return

#IfWinActive SciTE4AutoHotkey
Strg_S:
   Ctrl_S:
   ^s::
   Last_A_This:=A_ThisFunc . A_ThisLabel
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   strg_alt_l()
   ;~ drawButtons("bS" , 150)  ; b = ctrsl a = alt j = shift q=f6
return

Ctrl_F:
   ^f::
   ;~ ctr alt i
   Suspend,on
   Send,{Blind}
   Send,{CtrlDown}{AltDown}i{AltUp}{CtrlUp}
   Send,{Blind}
   Last_A_This:=A_ThisFunc . A_ThisLabel . " p"
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   drawButtons("bF" , 150)  ; b = ctrsl a = alt j = shift q=f6
   ;~ lll(A_LineNumber, "keys_SL5_AHK_Refactor_engine.ahk",Last_A_This)
   Suspend,Off
   send,{CtrlDown{{CtrlUP}{Blind}
return

Ctrl_Enter:
   ^ & enter::
   Ctrl & Enter::
   Last_A_This:=A_ThisFunc . A_ThisLabel . " p"
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   drawButtons("be" , 150)  ; b = ctrsl a = alt j = shift q=f6
   ;  ; Send,{Blind}
   Send,{End}{ShiftDown}{Home}
   ClipboardB:=Clipboard
   Loop,15
   {
      Send,^c
      Sleep,10
      if(ClipboardB != Clipboard)
         break
      Sleep,10
   }
   codeLine=%Clipboard% ;
   ;~ codeLine := RegExReplace(codeLine, "\s*(:?=)\s*", " $1 ", 1)  ;
   deli1 := StrSplit(codeLine, "(")
   deli1close := StrSplit(codeLine, ")")
   deli1diff := deli1.MaxIndex() - deli1close.MaxIndex()
   deli4open := StrSplit(codeLine, "{","")
   deli4close := StrSplit( codeLine, "}","")
   deli4diff := deli4open.MaxIndex() - deli4close.MaxIndex()
   deli2open := StrSplit( codeLine, "[","")
   deli2close := StrSplit( codeLine, "]","")
   deli2diff := deli2open.MaxIndex() - deli2close.MaxIndex()
   deli3open := StrSplit(" " . codeLine, """","")
   deli3diff := deli3open.MaxIndex() - 1
   ;~ MsgBox,  % deli3open.MaxIndex()
   ;~ du = (["ja"])
   add:=""
   if(deli3diff > 0 && Mod(deli3diff, 2) != 0 )
      Loop,%deli3diff%
   add .= """"
   if(deli2diff > 0)
      Loop,%deli2diff%
   add .= "]"
   if(deli1diff > 0)
      Loop,%deli1diff%
   add .= ")"
   if(deli4diff > 0)
      Loop,%deli4diff%
   add .= "{return}{tab}{}}"
   add .= "{Space}`;{Space}"
   ;~ MsgBox, %count_deli% := count_deli `n
   ;~ return ;  { k
   ;
   ;
   Send,{Blind}
   Suspend,on
   send,{Right}
   ;~ Sourceline=%Clipboard% = Clipboard `n
   ;~ varName:=SubStr(Clipboard,1,20)
   ;~ varName:=RegExReplace(varName,"[^\w_]+","_")
   strLen_add := StrLen(RegExReplace(add,"{[^}]+}","_" )) ;
   if(debug65)
      lll(A_LineNumber, "keys_SL5_AHK_Refactor_engine.ahk",Last_A_This . " " . %codeLine%)
   if(deli4diff > 0)
      strLen_add += 1
   Send,%add%{left %strLen_add%}
   if(debug65)
      lll(A_LineNumber, "keys_SL5_AHK_Refactor_engine.ahk",Last_A_This . " " . %codeLine%)
   Suspend,off
return

Ctrl_V:
   Ctrl_Alt_V:
   Str_Alt_V:
   Strg_Alt_V:
   Ctrl & v::
   Last_A_This:=A_ThisFunc . A_ThisLabel . not_implemented_jet
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   ;~ ju_hu = ju hu lkjllkjllkjlstrg alt v strg alt v strg alt v strg alt v strg alt v
   ; its writes a variable = expression ; input is the complete line. so pls use for each variable a exclusive line
   If (GetKeyState("Alt", "p"))
   {
      ctrl_alt_v()
      return
   }

   Ctrl_Shift_V:
   Strg_Shift_V:
   Last_A_This:=A_ThisFunc . A_ThisLabel
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)

   If (GetKeyState("Shift", "p")) {
      drawButtons("bjV" , 150)  ; b = ctrsl a = alt j = shift q=f6
      runCopyQ_Ctrl_Shift_v()
   }
   Send,^v
   Suspend,off
   lll(A_LineNumber, "keys_SL5_AHK_Refactor_engine.ahk",Last_A_This)
return

getInputBoxOnTop( title, prompt, timeout, default)
getInputBoxOnTop( title, prompt, timeout, default){
   MsgBox, not yet implemented 15-06-12_15-06
   ;~ InputBox, value , %title% , %prompt% , , width, height, x, y, font, %timeout% , %default%
   return value
}

;
; CCCCClipboard ClipboardClipboard Clipboard
; Clipboard Clipboard Clipboard Clipboard
#IfWinActive SciTE4AutoHotkey
Ctrl_Shift_Z:
   +^z::
   Last_A_This:=A_ThisFunc . A_ThisLabel
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   drawButtons("bjZ" , 150)  ; b = ctrsl a = alt j = shift q=f6
   Suspend,on
   send,^y ; redo
   Suspend,off
return

Ctrl_Shift_up:
   +^up::
   Last_A_This:=A_ThisFunc . A_ThisLabel
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   drawButtons("bjw" , 150)  ; b = ctrsl a = alt j = shift q=f6 w = up
   Suspend,on
   send,^t{up}
   Suspend,off
return

Ctrl_Shift_down:
   +^Down::
   Last_A_This:=A_ThisFunc . A_ThisLabel
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   drawButtons("bjy" , 150)  ; b = ctrsl a = alt j = shift q=f6 w = up y =down
   ;~ If (GetKeyState("Shift", "p")) {
   ;  if u want trigger ^z and you missed. its creates lots of confusion. and i nealy never use this funktion. so turn it off.
   Suspend,on
   send,{Down}
   ;~ {Home}
   Send,^t
   ;~ ^t{Down}
   Suspend,off
   Last_A_This:=A_ThisFunc . A_ThisLabel
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
return
;test

t_deactivated:
   ^t::
   ;  if u want trigger ^z and you missed. its creates lots of confusion. and i nealy never use this funktion. so turn it off.
   Last_A_This:=A_ThisFunc . A_ThisLabel
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
return

Ctrl_R_replace_text_dialog:
   ^r::
   Last_A_This:=A_ThisFunc . A_ThisLabel
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   drawButtons("bR" , 150)  ; b = ctrsl a = alt j = shift q=f6 w = up y =down
   Suspend,on
   Send,{Blind}
   ControlSend,,^h,SciTE4AutoHotkey  ; thats replacement dialog
   Suspend,Off
return

;~ BTW there is a great shortcut implemented in scite: SHIFT + %
;~ thats the standard editor for autohotkey. i want shortcats like i use it in phpstorm
Ctrl_Y_deleteLine_moveDown:
   Strg_Y:
   ^y::
   Last_A_This:=A_ThisFunc . A_ThisLabel
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   drawButtons("bY" , 150)  ; b = ctrsl a = alt j = shift q=f6 w = up y =down
   Suspend,on
   Sleep,100
   Loop,15
   {
      If ( !GetKeyState("Ctrl", "P") )
      {
         ;~ Suspend,off
         ;~ return
         break
      }
      Send,{CtrlUp}
      ; {Blind}
      Sleep,100
   }
   If ( GetKeyState("Ctrl", "P") )
   {
      Suspend,off
      return
      ;~ break
   }
   ; do it only it
   ;~ ControlSend,,{Home}{Shift}{End}{ShiftUp},SciTE4AutoHotkey
   ControlSend,,{Home}{ShiftDown}{End}{ShiftUp},SciTE4AutoHotkey
   ControlSend,,{Del}{BackSpace}{Right},SciTE4AutoHotkey
   Suspend,Off
   lll(A_LineNumber, "keys_SL5_AHK_Refactor_engine.ahk",Last_A_This)
return

Ctrl_BackSpace_synonym2_Ctrl_Shift_BackSpace:
   ^BackSpace:: ; works but we dont need so many shortcuts n15-05-12_15-53
   ;~ !BackSpace:: ; works but we dont need so many shortcuts n15-05-12_15-53
   +BackSpace:: ; works
   Last_A_This:=A_ThisFunc . A_ThisLabel
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   drawButtons("b`` " , 150)  ; x b = ctrsl a = alt j = shift q=f6 w = up y =down `` = reset, didnt found a backspace fontKey
   setCaret2lastEditPosition() ;
return

;~ !	Alt
;~ ^	Control
;~ +	Shift

Ctrl_Shift_BackSpace:
   +^BackSpace::
   If (GetKeyState("Shift", "p")) {
      ;~ GetKeyState() function returns true (1) for "on" and false (0) for "off").
      ;~ P: holding down. You can force the hooks to be installed by adding the #InstallKeybdHook and/or #InstallMouseHook directives to the script.
      Last_A_This:=A_ThisFunc . A_ThisLabel
      ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
      drawButtons("bj`` " , 150)  ; x b = ctrsl a = alt j = shift q=f6 w = up y =down `` = reset, didnt found a backspace fontKey

      Sleep,10
      KeyWait, Shift,L
      Sleep,10
      ;~ MsgBox,this shortcut is buggy. pls use shift + backspace or ctrl + backspace
      setCaret2lastEditPosition()
   }
return

#IfWinActive,
;~ Allgemeine Programmierhilfe
;~ weil man ja sonst eh den Zahlenblock verwendet.
7::tp41fn(isNumPadAvailable,A_ComputerName, "7", "{")
0::tp41fn(isNumPadAvailable,A_ComputerName, "0", "}")
8::tp41fn(isNumPadAvailable,A_ComputerName, "8", "[")
9::tp41fn(isNumPadAvailable,A_ComputerName, "9", "]")
;~ !$%6{[]}
1::tp41fn(isNumPadAvailable,A_ComputerName, "1", "!")
2::
doubleQuote="
tp41fn(isNumPadAvailable,A_ComputerName, "2", doubleQuote) ;"1
return
3::tp41fn(isNumPadAvailable,A_ComputerName, "3", "")
4::tp41fn(isNumPadAvailable,A_ComputerName, "4", "$")
5::tp41fn(isNumPadAvailable,A_ComputerName, "5", "%")
6::tp41fn(isNumPadAvailable,A_ComputerName, "6", "&")
SetTitleMatchMode,2
#IfWinActive, SciTE4AutoHotkey
; thats the standard editor for autohotkey. i want shortcats like i use it in phpstorm
;~ StrgY:78987877
;~ asdkf
;~ asfdzyzyzy

NumpadAdd_send_plus:
   ; for some unkonow reasons i need to do this :D
   NumpadAdd::
   ;~ MsgBox,asdftesttest++++++++
   Suspend,on
   ControlSendRaw,,+,SciTE4AutoHotkey
   Suspend,Off
return
;~ #IfWinActive SciTE4AutoHotkey
; thats the standard editor for autohotkey. i want shortcats like i use it in phpstorm
; comment
; ctrl shift b

NumpadDiv:
   ^NumpadDiv::
   Last_A_This:=A_ThisFunc . A_ThisLabel
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   ;Send,{CtrlDown}{ShiftDown}b{ShiftUp}{CtrlUp
   Send,^q{Down}
return

SetTitleMatchMode,2
#IfWinActive, SciTE4AutoHotkey
; eventually you need to push ; STRG+SHIFT+%/5  means 3 keys . dont know whey but its sometimes needet. so whey dont use it anytime

Ctrl_Shif_5_keyKeyNewline:
   Shift_5:
   ; %test% %test% := test `n %test% := test `n
   ^%::
   +%::
   Last_A_This:=A_ThisFunc . A_ThisLabel
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   drawButtons("j%" , 150)  ; x b = ctrsl a = alt j = shift q=f6 w = up y =down `` = reset, didnt found a backspace fontKey
   ;~ MsgBox,StrLen(clipboard)
   if(StrLen(clipboard) < 100 )    {
      ; !!!!!! warning \w in autohotkey also includes numbers !!!
      c = %clipboard%
      cAdd :=  "(line:%A_LineNumber%)" ;
      ;~ lenc:=StrLen(c), %cAdd% = cAdd (line:%A_LineNumber%) `n %
      leftSteps:=StrLen(c) + StrLen(cAdd) + 7
      ;~ %kk% = kk `n ttt%ttt% = ttt `n  , %cAdd% = cAdd "(line:3845)" `n %
      ; %h% = h %cAdd% `n , %cAdd% = cAdd "(line:)" `n %
      m := RegExReplace(c,"i)\b([a-z]+[\w\d_]*)\b",", %$1% = $1 " . cAdd . " ``n ") ; %key%= value
      ;%Clipboard% = Clipboard `n   ff
      ;~ MsgBox,%c% %m%
      ;~ return
      ;~ m := RegExReplace(c,"\b([a-z]+[\w\d_]*)\b",", '%$1%' = $1 ``n ") ; '%key%' = value
      ;~ m := RegExReplace(c,"(\w[\w\d_]*)[^\w\d_]*?",", '%$1%' = $1 ``n ")
      m := trim(SubStr(m,2,StrLen(m) - 1))  .  " "
      ;~ Suspend,on
      ;~ MsgBox,'%m%' = m `n
      Send,% convert123To_NumPad123(m)
      SetKeyDelay,20,22
      Send,{ShiftDown}{Left %leftSteps%}{ShiftUp}
      ; CCcCCcCCc
      ; asldf lkj lk lkj  '%asldf%' = asldf `n  , '%lkj%' = lkj `n  , '%lk%' = lk `n  , '%lkj%' = lkj `n %leftSteps% = leftSteps `n  %uuu%
   }
   ;      kkk%lenc% = lenc `n %iiiiiiii% = iiiiiiii `n
return

copySelection2clipBoard(){
   ;~ WinGetActiveTitle,at
   Clipboard:=""
   a_TimeIdleStart := A_TimeIdle
   loopCounter:=0
   while(!clipboard && loopCounter < 100){
      ;~ IfWinNotActive,%at%
      ;~ return
      ; be sure that cursor not aut of the carret this shortime
      if(a_TimeIdleStart > A_TimeIdle)
         return
      Send,^c
      ;:1:2: 3
      loopCounter += 1
      Sleep,1
   }
   c=%Clipboard%
   Suspend,Off
   if(!c){
      return false
   }
   return c
}

copyLineOrWord2clipBoard(doSelectLine){
   Suspend,on
   if(doSelectLine){
      Send,{Home}{ShiftDown}
      Send,{ShiftDown}{End}
   }else  {
      Send,^{Left 3}{ShiftDown}
      Send,{ShiftDown}^{Right 3}
   }
   Send,{ShiftUp}
   c:=copySelection2clipBoard()
   return c
}
; lk luuu:u:u0
ctrl_alt_v(){
   WinGetActiveTitle,activeTitle
   WinSet, AlwaysOnTop, Off, %activeTitle%
   Last_A_This:=A_ThisFunc . A_ThisLabel . " p"
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   Suspend,on
   doSelectLine:=true
   copyLineOrWord2clipBoard(doSelectLine)
   Send,{Blind}
   send,{Left}
   ; bug
   ;~ E:\temp\2015-06-10 09_31_37-Aufnahme luft....png
   ;~ e_temp____ := E:\te"mp\2015-06-10 09_31_37-Aufnahme luft....p
   ;~ clipboard clipboard
   varFIRST=%Clipboard%
   varName:=SubStr(Trim(varFIRST),1,20)
   ;,uuu,3076
   ;  lkolk()
   ;~ MsgBox,1
   ;~ }else
      ;~ MsgBox,2
   ;~ return
   varName:=RegExReplace(varName,"[^\w\d_]+","_")
   varName := Trim(varName,"_")
   varName := RegExReplace(varName,"^.*?(\w+[\w_\d]*).*?","$1")
   varName := RegExReplace(varName,"^\w*?Get(\w+)","$1")
   ; WinGetActiveTitle ==> activeTitle := WinGetActiveTitle
   varName1 := SubStr(varName,1,1)
   ;~ varFIRST1 := SubStr(varFIRST,1,1)
   StringLower,varName1,varName1
   varName:= varName1 . SubStr(varName,2)
   strLen_varName := StrLen(varName)
   Send,{Blind}
   ;~ Send,%varName% :={Space}{home}{Right %strLen_varName_%}
   ;~ %lkj% = lkj
   ;~ lkj
   ;~ %lkj% := =lkj=
   inputH := 200
   timeoutSec := 6

   SetTitleMatchMode,3
   noInputs:=false
   ;~ ein_bisschen_text = %ein bisschen text%
   ;~ 1+2+3*4
   ;~ isProbablyFuntionCallInside := RegExMatch(varFIRST,"i)[a-z_]+\([^)]*\)")
   isDigitFirst := RegExMatch(varFIRST,"^\d+")
   if( isDigitFirst ||  InStr(varFIRST," .")   ||  InStr(varFIRST," +")  ||  InStr(varFIRST,":=") || StrLen(varFIRST) > Round(StrLen(varName) * 1.2) ){
      isValueProbablyNotString := true
      ;~ %A_LineNumber% = A_LineNumber `n
   }else if (RegExMatch(varFIRST , "i)[a-z_]+\([^)]*\)"))
   isValueProbablyNotString := true
   ;  ;
   ;~ isProbablyFuntionCallInside := RegExMatch(varFIRST,"i)[a-z_]+\([^)]*\)")
   if(isValueProbablyNotString)
   {
      varFIRST1 := RegExReplace(varFIRST,"^`a*(.).*?$","$1")
      if(varFIRST1 == "%")
         isValueProbablyNotString := false
      ;~ MsgBox,%varFIRST1% = varFIRST1 (line:%A_LineNumber%) `n
      ;~ return
   }

   if(isValueProbablyNotString)
      defaultInput := ":="
   ;~ MsgBox,%varName% := varName `n 15-06-12_16-20
   ;~ %_% := _]%
   ;~ %5_6% := 5_6
   else{
      defaultInput := "="
   }
   msg= Delimiter ? `n`nPress Shift+Enter for use intelligent defaults.

   SetTitleMatchMode,2
   WinGetPos,x,y,w,h,SciTE4AutoHotkey

   InputBox,delimiter,%msg%,%msg% , , 200 , %inputH%  , % ( x + w / 2 - 50 ) , % ( y + h / 2 - 50 ) , , %timeoutSec%  , %defaultInput%
   WinSet, AlwaysOnTop, On, %msg%
   if ErrorLevel = 1
   noDel:=true
   If ( GetKeyState("shift", "P") ) {
      m=pressed shift+enter lets use defaults
      ;~ MsgBox, ,% m,% m,1
      noInputs:=true
   }
   ; Qoutes of Key
   if(delimiter == ":=")
   {
      ;~ if(isValueProbablyNotString)
         defaultInput := ""
      ;~ MsgBox,%defaultInput%  15-06-12_16-36
   } else if(delimiter == ":")
      defaultInput := ""
   else if(delimiter == "=")
      defaultInput := ""
   else if(delimiter == ",")
      defaultInput := """"
   else
      defaultInput := ""
   ;~ ein_bisschen_text := ein bisschen text
   ;~ test = %test%
   ;~ d_1_2_1_2222 := d_1_2 := 1+2222
   ;~ MsgBox,%delimiter% := delimiter `n %delimiter% := delimiter `n %noInputs% := noInputs `n
   ;~ Reload
   ;~ Qoutes of Key?
   if(noInputs)
   {
      ToolTip1sec("noInputs 15-06-12_17-20")
      firstQoute:=defaultInput
      ;~ MsgBox,15-06-12_17-20
   }else  {
      msg= Qoutes of Key?
      InputBox,firstQoute,%msg%,%msg% , , 200 , %inputH%  , 330 , 200, , %timeoutSec%  , %defaultInput%
      WinSet, AlwaysOnTop, On, %msg%
      if ErrorLevel = 1
      noKey:=true
   }
   ; value qoutes
   if(firstQoute == "%")
      defaultInput := ""
   else if(firstQoute == """")
      defaultInput := """"
   else{
      if(delimiter == ":=")
      {
         ;~ calculation ? not a sting?
         ;~ isValueProbablyNotString
         ;~ A_TimeIdle kkk
         varName_1_3 := SubStr(varName,1,2)
         StringLower, varName_1_3lo ,varName_1_3
         ;~ MsgBox,%subStr_varName_1_3% = subStr_varName_1_3 `n
         ;~ return
         if(!isValueProbablyNotString && varName_1_3lo == "a_")
            isValueProbablyNotString:=true
         if(isValueProbablyNotString)
            defaultInput := ""
         else
            defaultInput := """"
      } else if(delimiter == ":")
         defaultInput := """"
      else if(delimiter == "=") {
         ;~ isDigitFirst
         ;~ isValueProbablyNotString := true
         isCorrectForVarName := RegExMatch(trim(varFIRST),"^\w+[\w_\d]+$")
         if(isDigitFirst || !isCorrectForVarName )
            defaultInput := ""
         else
            defaultInput := "%"
         ;~ ein_bischen = ein bischen
      }
      else if(delimiter == ",")
         defaultInput := """"
      else
         defaultInput := ""
   }
   ;~ 1_2_3 1+2+3
   if(noInputs)
      secQoute:=defaultInput
   else {
      msg= Qoutes of Value?

      SetTitleMatchMode,2
      WinGetPos,x,y,w,h,SciTE4AutoHotkey

      ;~ InputBox,secQoute,%msg%,%msg% , , 200 , 100 , % ( x + w / 2 - 50 ) , % ( y + h / 2 - 50 ) , , %timeoutSec%  , %defaultInput%
      WinSet, AlwaysOnTop, On, %msg%
      if ErrorLevel = 1
      noVal:=true
   }
   if(noKey &&  noDel &&  noVal )
   {
      ToolTip3sec(A_LineNumber . ": InputDialogs canceld (15-06-12_14-36)" )
      return
   }
   Send,{Blind}
   WinActivate,%activeTitle%
   WinWaitActive,%activeTitle%,,1
   IfWinNotActive,%activeTitle%
      return
   Send,{home}{ShiftDown}{End}
   if(isDigitFirst && firstQoute == "")
      varName :=  "d_" . varName
   part1=%firstQoute%%varName%%firstQoute%
   if(delimiter==":=")
      value:=varFIRST
   else
      value:=varFIRST
   valueOriginal := value
   valueEncode := RegExReplace(value, "([!+^#{}]+)", "{$1}")
   valueDiffLen := StrLen(valueEncode) - StrLen(valueOriginal)
   part2=%delimiter% %secQoute%%valueEncode%%secQoute%
   strLen_walk_left := StrLen(part2) - valueDiffLen ;
   part1:=convert123To_NumPad123(part1)
   part2:=convert123To_NumPad123(part2)
   ;1+2lll(A_LineNumber, "keys_SL5_AHK_Refactor_engine.ahk",Last_A_This)Ll@ewqerwqe@@
   WinActivate,%activeTitle%
   WinWaitActive,%activeTitle%,,1
   IfWinNotActive,%activeTitle%
      return
   Send, %part1% %part2%
   ;~ %_% := +%
   ;~ %{numpad}_{numpad}% := {numpad}+{numpad}%
   Send,{Blind}
   Sleep,10
   WinActivate,%activeTitle%
   WinWaitActive,%activeTitle%,,1
   IfWinNotActive,%activeTitle%
      return
   Send,{end}{ShiftDown}{Left %strLen_walk_left%}{ShiftUp}
   Send,{Blind}
   ;~ Send,{home}{Right %strLen_varName%}
   ;~ Sleep,20
   ;~ asdfs
   Suspend,off
   Sleep,1000
   return
   ;~ so_ein_tag := so ein tagzy
   ;~ aaaa := aaaa
   ;~ huhu := huhu
   return ;~ huhu := huhu
}
return  ; probably redundant. its more secure if we do that.
;~ #Include functions.inc.ahk
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;~ subroutinen beispielsweise msen ans Dateiende
#Include functions_dateiende.inc.ahk
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

#Include UPDATEDSCRIPT_global.inc.ahk
showUsageInfoBox(){
   if(true)
      msgBox_Something_wro = Something wrong :( `n  please do the following: `n open tillagoto.properties and set `n `n tillagoto.enable=0  `n`n then Reload SL5_AHK_Refactor_engine_v0.5.ahk `n `n BTW its recomandet to use SciTE4AHK300601_Portable (easyier to change properties files) `n  (line:%A_LineNumber%) `n
   ;~ MsgBox,%msgBox_Something_wro%
   MsgBox , , % msgBox_Something_wro , % msgBox_Something_wro , 3

   run,SL5_AHK_Refactor_engine_v0.5.ahk
   ;~ Reload
}
tp41fn(isNumPadAvailable,ComputerName, key1, key2)
{
   ; test retest5
   ; Computer mit SN Taste haben keinen zahlen Block.
   ; daher wre es unsinnig den Anwender dazu zu ntigen den zahlen Block zu verwenden.
   Last_A_This:=A_ThisFunc . A_ThisLabel . "`n" . " isNumPadAvailable = '" . isNumPadAvailable . "'"
   ToolTip3sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   if(!isNumPadAvailable || ComputerName = "IBM-DE212688" )
      s:=key1
   else
      s:=key2
   ;~ SendPlay,%s% ; dont work anymore n15-05-08_15-12
   Suspend,on
   global a_doublequote
   doubleQuote="
   if(Trim(s) == doubleQuote)
      SendRaw,"
   else
      SendRaw,%s%
   ;~  !"$%6{66%6
   Suspend,off
   return
}
getRunPHP_link(phpFile , argv){
   ;~ argv = --source1="%oSciTE_CurrentFile%"
   path= %A_ScriptDir%\phpdesktop-msie-1.14-php-5.4.33
   phpCgiExe = %path%\php\php-cgi.exe
   ; E:\fre\private\HtmlDevelop\AutoHotKey\SL5_AHK_Refactor_engine_gitHub\phpdesktop-msie-1.14-php-5.4.33\www\SL5_preg_contentFinder\examples\AutoHotKey\Reformatting_Autohotkey_Source.php
   script = %path%\www\SL5_preg_contentFinder\examples\AutoHotKey\%phpFile%
   oSciTE := GetSciTEInstance()
   oSciTE_CurrentFile := oSciTE.CurrentFile
   ;
   target := phpCgiExe . " " . script . " " . argv
   return target
}
saveWait(fileAdress){
   Suspend,on
   Send,{blind}  ;
   Sleep,10

   Send,^s ; save script first ;
   FileGetTime, modiTime1, fileAdress ; Retrieves the modification time by default.
   Loop,8
   {
      Sleep,100
      FileGetTime, modiTime2, fileAdress  ; Retrieves the modification time by default.
      if(modiTime1 != modiTime2)
         break
   }
   Send,{CtrlUp}{AltUp}
   Suspend,off
   Sleep,20
   return true
}
isFileOpendInSciteUnsaved(filename){
   SetTitleMatchMode,2
   doSaveFirst := false ; initialisation
   IfWinNotExist,%filename% - SciTE4AutoHotkey
   {
      doSaveFirst := true
      IfWinNotExist,%filename% * SciTE4AutoHotkey
         MsgBox,oops   NotExist %filename% * SciTE4AutoHotkey
   }
   return doSaveFirst
}

setCaret2lastEditPosition(){
   Last_A_This:=A_ThisFunc . A_ThisLabel
   ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   Suspend,on
   Send,{Blind}
   ;~ Sleep,10
   ;~ Send,{Blind}
   If (!GetKeyState("z", "P") && !GetKeyState("y", "P")) {
      ; do it only its not pressed
      ;~ SetKeyDelay,0
      Suspend,on
      SetKeyDelay,40
      ControlSend,,{CtrlDown}zy{CtrlUp},SciTE4AutoHotkey
      ControlSend,,{up 6}{Down 12}{up 6},SciTE4AutoHotkey
      Suspend,off
   }
   ;~ MsgBox,lh
   Suspend,Off
   send,{Blind}
   return
}

GetSciTEInstance()
{
   Last_A_This:=A_ThisFunc . A_ThisLabel
   if(false)
      ToolTip1sec(A_LineNumber . " " . A_ScriptName . " " . Last_A_This)
   ; lll(A_LineNumber, "SL5_AHK_Refactor_engine_v0.5.ahk",Last_A_This)
   olderr := ComObjError()
   ComObjError(false)
   scite := ComObjActive("{D7334085-22FB-416E-B398-B5038A5A0784}")
   ComObjError(olderr)
   oSciTE := IsObject(scite) ? scite : ""
   if !oSciTE
   {
      MsgBox, 16, % Last_A_This, Cannot find SciTE!
      ExitApp
   }
   ;
   return oSciTE
}
strg_alt_l(){
   ;Get the filename
   oSciTE := GetSciTEInstance()
   oSciTE_CurrentFile := oSciTE.CurrentFile
   ; To fetch only the bare filename from the above:
   SplitPath, oSciTE_CurrentFile , filename
   doSaveFirst := isFileOpendInSciteUnsaved(filename)
   phpFile = Reformatting_Autohotkey_Source.php
   argv = --source1="%oSciTE_CurrentFile%"
   target := getRunPHP_link(phpFile , argv)
   ;~ MsgBox,%target% = target (line:%A_LineNumber%) `n
   ;~ return
   ;~ works ??

   if(doSaveFirst)
      saveWait(A_ScriptDir)
   run, % target ,,Hide
   if(!doSaveFirst)
      Sleep,250
   MsgBox,,SL5 Source Reformatting finished and saved,SL5 Source Reformatting finished `n  file saved `n  backup saved,1
   ;~ MsgBox,%target% = target (line:%A_LineNumber%) `n
   Suspend,off
   return
}


General plugin: show help of run and key actions

General:
    Gen_Save_Win := []
    vim.SetAction("<down>", "向下移动")
    vim.SetAction("<up>", "向上移动")
    vim.SetAction("<left>", "向左移动")
    vim.SetAction("<right>", "向右移动")
    vim.SetAction("<home>", "home键")
    vim.SetAction("<end>", "end键")
    vim.SetAction("<Gen_InsertMode>", "插入模式")
    vim.SetAction("<Gen_NormalMode>", "浏览模式")
    vim.SetAction("<Gen_Toggle>", "启用/禁用vim热键(General插件)")
    vim.SetAction("<Reload>", "重新加载")
    vim.SetAction("<WindowMoveDown>", "窗口移动到下方")
    vim.SetAction("<WindowMoveUp>", "窗口移动到上方")
    vim.SetAction("<WindowMoveLeft>", "窗口移动到左侧")
    vim.SetAction("<WindowMoveRight>", "窗口移动到右侧")
    vim.SetAction("<WindowMoveCenter>", "窗口移动到中间")
    vim.SetAction("<WindowMax>", "最大化窗口")
    vim.SetAction("<WindowMin>", "最小化窗口")
    vim.SetAction("<WindowRestore>", "还原当前窗口")
    vim.SetAction("<FullScreen>", "全屏当前程序")
    vim.SetAction("<NextTab>", "下一个标签")
    vim.SetAction("<PrevTab>", "前一个标签")
    vim.SetAction("<CloseTab>", "关闭当前标签")
    vim.SetAction("<NewTab>", "新建标签")
    vim.SetAction("<ActivateTab1>", "激活第一个标签")
    vim.SetAction("<ActivateTab2>", "激活第二个标签")
    vim.SetAction("<ActivateTab3>", "激活第三个标签")
    vim.SetAction("<ActivateTab4>", "激活第四个标签")
    vim.SetAction("<ActivateTab5>", "激活第五个标签")
    vim.SetAction("<ActivateTab6>", "激活第六个标签")
    vim.SetAction("<ActivateTab7>", "激活第七个标签")
    vim.SetAction("<ActivateTab8>", "激活第八个标签")
    vim.SetAction("<ActivateTab9>", "激活第九个标签")
    vim.SetAction("<ActivateTab0>", "激活最后一个标签")
    vim.SetAction("<pgup>", "上一页")
    vim.SetAction("<pgdn>", "下一页")
    vim.SetAction("<enter>", "回车键")
    vim.SetAction("<Pass>", "屏蔽按键")
    vim.SetAction("<Media_Next>", "播放下一首")
    vim.SetAction("<Media_Prev>", "播放上一首")
    vim.SetAction("<Media_Play_Pause>", "播放/停止")
    vim.SetAction("<Media_Stop>", "停止播放")
    vim.SetAction("<RemoveToolTip>", "清除屏幕的ToolTip")
    vim.SetAction("<ShowHelp>", "显示所有按键帮助信息")
    vim.SetAction("<ToggleCapsLock>", "切换大小写")
    vim.SetAction("<MouseUp>", "向上移动鼠标")
    vim.SetAction("<MouseDown>", "向下移动鼠标")
    vim.SetAction("<MouseLeft>", "向左移动鼠标")
    vim.SetAction("<MouseRight>", "向右移动鼠标")
    vim.SetAction("<SearchInWeb>", "在网络搜索剪切板内容")
    vim.SetAction("<GKey>", "GKey全局快捷操作")

    vim.SetWin("General", "General")
    vim.SetMode("insert", "General")
    vim.map("<Esc>", "<Gen_NormalMode>", "General")
    vim.SetMode("normal", "General")
    vim.map("i", "<Gen_InsertMode>", "General")
    vim.map("0", "<0>", "General")
    vim.map("1", "<1>", "General")
    vim.map("2", "<2>", "General")
    vim.map("3", "<3>", "General")
    vim.map("4", "<4>", "General")
    vim.map("5", "<5>", "General")
    vim.map("6", "<6>", "General")
    vim.map("7", "<7>", "General")
    vim.map("8", "<8>", "General")
    vim.map("9", "<9>", "General")
    vim.map("k", "<up>", "General")
    vim.map("j", "<down>", "General")
    vim.map("k", "<up>", "General")
    vim.map("h", "<left>", "General")
    vim.map("l", "<right>", "General")
    vim.map("zj", "<WindowMoveDown>", "General")
    vim.map("zk", "<WindowMoveUp>", "General")
    vim.map("zh", "<WindowMoveLeft>", "General")
    vim.map("zl", "<WindowMoveRight>", "General")
    vim.map("zc", "<WindowMoveCenter>", "General")
    vim.map("zf", "<fullscreen>", "General")
    vim.map("zm", "<WindowMax>", "General")
    vim.map("zn", "<WindowMin>", "General")
    vim.map("zr", "<WindowRestore>", "General")
    vim.map("t", "<NewTab>", "General")
    vim.map("x", "<CloseTab>", "General")
    vim.map("gn", "<NextTab>", "General")
    vim.map("gp", "<PrevTab>", "General")
    vim.map("g1", "<ActivateTab1>", "General")
    vim.map("g2", "<ActivateTab2>", "General")
    vim.map("g3", "<ActivateTab3>", "General")
    vim.map("g4", "<ActivateTab4>", "General")
    vim.map("g5", "<ActivateTab5>", "General")
    vim.map("g6", "<ActivateTab6>", "General")
    vim.map("g7", "<ActivateTab7>", "General")
    vim.map("g8", "<ActivateTab8>", "General")
    vim.map("g9", "<ActivateTab9>", "General")
    vim.map("g0", "<ActivateTab0>", "General")
    vim.BeforeActionDo("Gen_Before", "General")
return

Gen_Before()
{
    Global vim
    WinGet, MenuID, ID, AHK_CLASS #32768
    If MenuID
        return True
}

<Gen_InsertMode>:
    vim.SetMode("Insert", vim.CheckWin())
    Tooltip, Insert模式, , , 19
    Settimer, cancelTooltip, 1200
return
<Gen_NormalMode>:
    vim.SetMode("Normal", vim.CheckWin())
    Tooltip, Normal模式, , , 19
    Settimer, cancelTooltip, 1200
return
<Gen_Toggle>:
    Gen_Toggle()
return
Gen_Toggle()
{
    Global vim, Gen_Save_Win
    WinGetClass, c, A
    WinGet, f, ProcessPath, ahk_class %c%
    WinName:=vim.CheckWin()
    If not Gen_Save_Win[c]
    {
        If Strlen(winName) And IsObject(vim.GetWin(winName))
        {
            MsgBox, , VimDesktop, 当前窗口 [ %winName% ] 已经拥有Vim模式`n不允许替换为通用(General)模式！
            return
        }
    }
    winObj := vim.GetWin(c)
    If not Isobject(winObj)
    {
        vim.copy("General", c, c, f)
        Gen_Save_Win[c] := True
        Tooltip, 复制VIMD热键到当前窗口成功, , , 19
    }
    Else
    {
        if vim.Toggle(c)
            Tooltip, 激活当前窗口的VIMD热键, , , 19
        else
            Tooltip, 取消当前窗口的VIMD热键, , , 19
    }
    Settimer, cancelTooltip, 1200
}
cancelTooltip:
    Tooltip, , , , 19
return
<reload>:
    reload
return
<Exit>:
    ExitApp
return
<down>:
    send, {down}
return
<up>:
    send, {up}
return
<left>:
    send, {left}
return
<right>:
    send, {right}
return
<home>:
    send, {home}
return
<end>:
    send, {end}
return
<pgup>:
    send, {pgup}
return
<pgdn>:
    send, {pgdn}
return
<enter>:
    send {enter}
return
<Media_Next>:
    send {Media_Next}
return
<Media_Prev>:
    send {Media_Prev}
return
<Media_Stop>:
    send {Media_Stop}
return
<Media_Play_Pause>:
    send {Media_Play_Pause}
return

<WindowMoveDown>:
    WindowPadMove("0, +1, 1.0, 0.5")
Return
<WindowMoveUp>:
    WindowPadMove("0, -1, 1.0, 0.5")
Return
<WindowMoveLeft>:
    WindowPadMove("-1, 0, 0.5, 1.0")
Return
<WindowMoveRight>:
    WindowPadMove("+1, 0, 0.5, 1.0")
Return
<WindowMoveCenter>:
    WindowPadMove("0, 0, 0.5, 0.7")
return
<WindowMax>:
    WinMaximize, A
return
<WindowMin>:
    WinMinimize, A
return
<WindowRestore>:
    WinRestore, A
return

; 全屏当前程序
<FullScreen>:
    FullScreen()
return
FullScreen() {
    WinGet, windowID, ID, A
    WindowState := FullScreenID[windowID]
    If Strlen(windowState) = 0
        WindowState := 0
    If WindowState
    {
        WinSet, Style, ^0xC40000, ahk_id %WindowID%
        Loop, Parse, windowState, `,
        {
            If A_Index = 2
                WinPosX := A_LoopField
            If A_Index = 3
                WinPosY := A_LoopField
            If A_Index = 4
                WindowWidth := A_LoopField
            If A_Index = 5
                WindowHeight := A_LoopField
        }
        WinMove, ahk_id %WindowID%, , WinPosX, WinPosY, WindowWidth, WindowHeight
        WindowState := 0
    }
    Else
    {
        WinGetPos, WinPosX, WinPosY, WindowWidth, WindowHeight, ahk_id %WindowID%
        WinSet, Style, ^0xC40000, ahk_id %WindowID%
        WinMove, ahk_id %WindowID%, , 0, 0, A_ScreenWidth, A_ScreenHeight
        WindowState := 1 ", " WinPosX ", " WinPosY ", " WindowWidth ", " WindowHeight
        ;Msgbox 再按一下刚刚的热键退出全屏
    }
    FullScreenID[windowID] := WindowState
}

;====================================================================================
;
; WindowPad.ahk
; Version: 0.4
; Last Updated: 11/5/2009
;
; This file contains functions which are useful for manipulating and moving windows.
; This is a stripped down version of WindowPad v.1.56 by Lexikos.
; Downloaded from http://www.autohotkey.com/forum/topic21703.html
;

WindowPadMove(P)
{
    StringSplit, P, P, `, , %A_Space%%A_Tab%
    ; Params: 1:dirX, 2:dirY, 3:widthFactor, 4:heightFactor, 5:window

    if P1 =
        P1 = R
    if P2 =
        P2 = R

    WindowPad_WinExist(P5)

    if !WinExist()
        return

    ; Determine width/height factors.
    if (P1 or P2) {
        ; to a side
        widthFactor := P3+0 ? P3 : (P1 ? 0.5 : 1.0)
        heightFactor := P4+0 ? P4 : (P2 ? 0.5 : 1.0)
    } else {
        ; to center
        widthFactor  := P3+0 ? P3 : 1.0
        heightFactor := P4+0 ? P4 : 1.0
    }

    ; Move the window!
    MoveWindowInDirection(P1, P2, widthFactor, heightFactor)
}

MaximizeToggle(P)
{
    WindowPad_WinExist(P)

    WinGet, state, MinMax
    if state
        WinRestore
    else
        WinMaximize
}

; Does the grunt work of the script.
MoveWindowInDirection(sideX, sideY, widthFactor, heightFactor)
{
    WinGetPos, x, y, w, h

    hwnd:=WinExist()
    if (can_restore := GetWindowProperty(hwnd, "wpHasRestorePos"))
    {   ; Window has restore info. Check if it is where we last put it.
        last_x := GetWindowProperty(hwnd, "wpLastX")
        last_y := GetWindowProperty(hwnd, "wpLastY")
        last_w := GetWindowProperty(hwnd, "wpLastW")
        last_h := GetWindowProperty(hwnd, "wpLastH")
    }
    if (can_restore && last_x = x && last_y = y && last_w = w && last_h = h)
    {   ; Window is where we last put it. Check if user wants to restore.
        if SubStr(sideX, 1, 1) = "R"
        {   ; Restore on X-axis.
            restore_x := GetWindowProperty(hwnd, "wpRestoreX")
            restore_w := GetWindowProperty(hwnd, "wpRestoreW")
            StringTrimLeft, sideX, sideX, 1
        }
        if SubStr(sideY, 1, 1) = "R"
        {   ; Restore on Y-axis.
            restore_y := GetWindowProperty(hwnd, "wpRestoreY")
            restore_h := GetWindowProperty(hwnd, "wpRestoreH")
            StringTrimLeft, sideY, sideY, 1
        }
        if (restore_x != "" || restore_y != "")
        {   ; If already at the "restored" size and position, do the normal thing instead.
            if ((restore_x = x || restore_x = "") && (restore_y = y || restore_y = "")
                && (restore_w = w || restore_w = "") && (restore_h = h || restore_h = ""))
            {
                restore_x =
                restore_y =
                restore_w =
                restore_h =
            }
        }
    }
    else
    {   ; Next time user requests the window be "restored" use this position and size.
        SetWindowProperty(hwnd, "wpHasRestorePos", true)
        SetWindowProperty(hwnd, "wpRestoreX", x)
        SetWindowProperty(hwnd, "wpRestoreY", y)
        SetWindowProperty(hwnd, "wpRestoreW", w)
        SetWindowProperty(hwnd, "wpRestoreH", h)

        if SubStr(sideX, 1, 1) = "R"
            StringTrimLeft, sideX, sideX, 1
        if SubStr(sideY, 1, 1) = "R"
            StringTrimLeft, sideY, sideY, 1
    }

    ; If no direction specified, restore or only switch monitors.
    if (sideX+0 = "" && restore_x = "")
        restore_x := x, restore_w := w
    if (sideY+0 = "" && restore_y = "")
        restore_y := y, restore_h := h

    ; Determine which monitor contains the center of the window.
    m := GetMonitorAt(x+w/2, y+h/2)

    ; Get work area of active monitor.
    gosub CalcMonitorStats
    ; Calculate possible new position for window.
    gosub CalcNewSizeAndPosition

    ; If the window is already there,
    if (newx ", " newy ", " neww ", " newh) = (x ", " y ", " w ", " h)
    {   ; ..move to the next monitor along instead.

        if (sideX or sideY)
        {   ; Move in the direction of sideX or sideY.
            SysGet, monB, Monitor, %m% ; get bounds of entire monitor (vs. work area)
            x := (sideX=0) ? (x+w/2) : (sideX>0 ? monBRight : monBLeft) + sideX
            y := (sideY=0) ? (y+h/2) : (sideY>0 ? monBBottom : monBTop) + sideY
            newm := GetMonitorAt(x, y, m)
        }
        else
        {   ; Move to center (Numpad5)
            newm := m+1
            SysGet, mon, MonitorCount
            if (newm > mon)
                newm := 1
        }

        if (newm != m)
        {
            m := newm
            ; Move to opposite side of monitor (left of a monitor is another monitor's right edge)
            sideX *= -1
            sideY *= -1
            ; Get new monitor's work area.
            gosub CalcMonitorStats
        }
        else
        {
            ; No monitor to move to, alternate size of window instead.
            if sideX
                widthFactor /= 2
            else if sideY
                heightFactor /= 2
            else
                widthFactor *= 1.5
            gosub CalcNewSizeAndPosition
        }

        ; Calculate new position for window.
        gosub CalcNewSizeAndPosition
    }

    ; Restore before resizing...
    WinGet, state, MinMax
    if state
        WinRestore

    WinDelay := A_WinDelay
    SetWinDelay, 0

    ; Move the window!
    WinMove, , , newx, newy, neww, newh

    ; For console windows and other windows which have size restrictions, check
    ; that the window was actually resized. If not, reposition based on actual size.
    WinGetPos, newx, newy, realw, realh
    if (neww != realw || newh != realh)
    {
        neww := realw
        newh := realh
        gosub CalcNewPosition
        if ((newm = "" || newm = m) && (newx ", " newy ", " realw ", " realh)=(x ", " y ", " w ", " h))
        {
            if sideX
                neww //= 2
            else if sideY
                newh //= 2
            else
                neww := Round(neww*1.5)
            ; Size first, since the window size will probably be restricted in some way.
            WinMove, , , , , neww, newh
            WinGetPos, , , neww, newh
            gosub CalcNewPosition
        }
        WinMove, , , newx, newy
    }

    ; Explorer uses WM_EXITSIZEMOVE to detect when a user finishes moving a window
    ; in order to save the position for next time. May also be used by other apps.
    PostMessage, 0x232

    SetWinDelay, WinDelay

    ; Remember where we put it, to detect if the user moves it.
    SetWindowProperty(hwnd, "wpLastX", newx)
    SetWindowProperty(hwnd, "wpLastY", newy)
    SetWindowProperty(hwnd, "wpLastW", neww)
    SetWindowProperty(hwnd, "wpLastH", newh)
    return

CalcNewSizeAndPosition:
    ; Calculate new size.
    if (IsResizable()) {
        neww := restore_w != "" ? restore_w : Round(monWidth * widthFactor)
        newh := restore_h != "" ? restore_h : Round(monHeight * heightFactor)
    } else {
        neww := w
        newh := h
    }
CalcNewPosition:
    ; Calculate new position.
    newx := restore_x != "" ? restore_x : Round(monLeft + (sideX+1) * (monWidth  - neww)/2)
    newy := restore_y != "" ? restore_y : Round(monTop  + (sideY+1) * (monHeight - newh)/2)
    return

CalcMonitorStats:
    ; Get work area (excludes taskbar-reserved space.)
    SysGet, mon, MonitorWorkArea, %m%
    monWidth  := monRight - monLeft
    monHeight := monBottom - monTop
    return
}

; Get/set window property. type should be int, uint or float.
GetWindowProperty(hwnd, property_name, type="int") {
    return DllCall("GetProp", "uint", hwnd, "str", property_name, type)
}
SetWindowProperty(hwnd, property_name, data, type="int") {
    return DllCall("SetProp", "uint", hwnd, "str", property_name, type, data)
}

; Get the index of the monitor containing the specified x and y co-ordinates.
GetMonitorAt(x, y, default=1)
{
    SysGet, m, MonitorCount
    ; Iterate through all monitors.
    Loop, %m%
    {
        ; Check if the window is on this monitor.
        SysGet, Mon, Monitor, %A_Index%
        if (x >= MonLeft && x <= MonRight && y >= MonTop && y <= MonBottom)
            return A_Index
    }

    return default
}

IsResizable()
{
    WinGetClass, Class
    if Class = Chrome_XPFrame
        return true
    if Class = ConsoleWindowClass
        return false
    WinGet, Style, Style
    return (Style & 0x40000) ; WS_SIZEBOX
}

WindowPad_WinExist(WinTitle)
{
    if WinTitle = P
        return WinPreviouslyActive()
    if WinTitle = M
    {
        MouseGetPos, , , win
        return WinExist("ahk_id " win)
    }
    return WinExist(WinTitle!="" ? WinTitle : "A")
}

; Note: This may not work properly with always-on-top windows. (Needs testing)
WinPreviouslyActive()
{
    active := WinActive("A")
    WinGet, win, List

    ; Find the active window.
    ; (Might not be win1 if there are always-on-top windows?)
    Loop, %win%
        if (win%A_Index% = active)
        {
            if (A_Index < win)
                N := A_Index+1

            ; hack for PSPad: +1 seems to get the document (child!) window, so do +2
            ifWinActive, ahk_class TfPSPad
                N += 1

            break
        }

    ; Use WinExist to set Last Found Window (for consistency with WinActive())
    return WinExist("ahk_id " . win%N%)
}

;
; Switch without moving/resizing (relative to screen)
;
WindowScreenMove(P)
{
    SetWinDelay, 0

    StringSplit, P, P, `, , %A_Space%%A_Tab%
    ; 1:Next|Prev|Num, 2:Window

    WindowPad_WinExist(P2)

    WinGet, state, MinMax
    if state = 1
        WinRestore

    WinGetPos, x, y, w, h

    ; Determine which monitor contains the center of the window.
    ms := GetMonitorAt(x+w/2, y+h/2)

    SysGet, mc, MonitorCount

    ; Determine which monitor to move to.
    if P1 in , N, Next
    {
        md := ms+1
        if (md > mc)
            md := 1
    }
    else if P1 in P, Prev, Previous
    {
        md := ms-1
        if (md < 1)
            md := mc
    }
    else if P1 is integer
        md := P1

    if (md=ms or (md+0)="" or md<1 or md>mc)
        return

    ; Get source and destination work areas (excludes taskbar-reserved space.)
    SysGet, ms, MonitorWorkArea, %ms%
    SysGet, md, MonitorWorkArea, %md%
    msw := msRight - msLeft, msh := msBottom - msTop
    mdw := mdRight - mdLeft, mdh := mdBottom - mdTop

    ; Calculate new size.
    if (IsResizable()) {
        w := Round(w*(mdw/msw))
        h := Round(h*(mdh/msh))
    }

    ; Move window, using resolution difference to scale co-ordinates.
    WinMove, , , mdLeft + (x-msLeft)*(mdw/msw), mdTop + (y-msTop)*(mdh/msh), w, h

    if state = 1
        WinMaximize
}

;
; "Gather" windows on a specific screen.
;
GatherWindows(md=1)
{
    global ProcessGatherExcludeList

    SetWinDelay, 0

    ; List all visible windows.
    WinGet, win, List

    ; Copy bounds of all monitors to an array.
    SysGet, mc, MonitorCount
    Loop, %mc%
        SysGet, mon%A_Index%, MonitorWorkArea, %A_Index%

    if md = M
    {
        ; Special exception for 'M', since the desktop window
        ; spreads across all screens.
        CoordMode, Mouse, Screen
        MouseGetPos, x, y
        md := GetMonitorAt(x, y, 0)
    }
    else if md is not integer
    {
        ; Support A, P and WinTitle.
        ; (Gather at screen containing specified window.)
        WindowPad_WinExist(md)
        WinGetPos, x, y, w, h
        md := GetMonitorAt(x+w/2, y+h/2, 0)
    }
    if (md<1 or md>mc)
        return

    ; Destination monitor
    mdx := mon%md%Left
    mdy := mon%md%Top
    mdw := mon%md%Right - mdx
    mdh := mon%md%Bottom - mdy

    Loop, %win%
    {
        ; If this window matches the GatherExclude group, don't touch it.
        if (WinExist("ahk_group GatherExclude ahk_id " . win%A_Index%))
            continue

        ; Set Last Found Window.
        if (!WinExist("ahk_id " . win%A_Index%))
            continue

        WinGet, procname, ProcessName
        ; Check process (program) exclusion list.
        if procname in %ProcessGatherExcludeList%
            continue

        WinGetPos, x, y, w, h

        ; Determine which monitor this window is on.
        xc := x+w/2, yc := y+h/2
        ms := 0
        Loop, %mc%
            if (xc >= mon%A_Index%Left && xc <= mon%A_Index%Right
                && yc >= mon%A_Index%Top && yc <= mon%A_Index%Bottom)
            {
                ms := A_Index
                break
            }
        ; If already on destination monitor, skip this window.
        if (ms = md)
            continue

        WinGet, state, MinMax
        if (state = 1) {
            WinRestore
            WinGetPos, x, y, w, h
        }

        if ms
        {
            ; Source monitor
            msx := mon%ms%Left
            msy := mon%ms%Top
            msw := mon%ms%Right - msx
            msh := mon%ms%Bottom - msy

            ; If the window is resizable, scale it by the monitors' resolution difference.
            if (IsResizable()) {
                w *= (mdw/msw)
                h *= (mdh/msh)
            }

            ; Move window, using resolution difference to scale co-ordinates.
            WinMove, , , mdx + (x-msx)*(mdw/msw), mdy + (y-msy)*(mdh/msh), w, h
        }
        else
        {
            ; Window not on any monitor, move it to center.
            WinMove, , , mdx + (mdw-w)/2, mdy + (mdh-h)/2
        }

        if state = 1
            WinMaximize
    }
}

GetLastMinimizedWindow()
{
    WinGet, w, List

    Loop %w%
    {
        wi := w%A_Index%
        WinGet, m, MinMax, ahk_id %wi%
        if m = -1 ; minimized
        {
            lastFound := wi
            break
        }
    }

    return "ahk_id " . (lastFound ? lastFound : 0)
}

;================================== 功能代码 :由北风一叶提供
;下一个标签
<NextTab>:
    send ^{tab}
return

;上一个标签
<PrevTab>:
    send ^+{tab}
return

;关闭当前标签
<CloseTab>:
    send ^{w}
return

;新建标签
<NewTab>:
    send ^{t}
return

;激活第一个标签
<ActivateTab1>:
    send ^{1}
return

;激活第二个标签
<ActivateTab2>:
    send ^{2}
return

;激活第三个标签
<ActivateTab3>:
    send ^{3}
return

;激活第四个标签
<ActivateTab4>:
    send ^{4}
return

;激活第五个标签
<ActivateTab5>:
    send ^{5}
return

;激活第六个标签
<ActivateTab6>:
    send ^{6}
return

;激活第七个标签
<ActivateTab7>:
    send ^{7}
return

;激活第八个标签
<ActivateTab8>:
    send ^{8}
return

;激活第九个标签
<ActivateTab9>:
    send ^{8}^{tab}
return

;激活最后一个标签
<ActivateTab0>:
    send ^{9}
return

;清除 ToolTip 计时器
<RemoveToolTip>:
    Global showToolTipStatus

    SetTimer, <RemoveToolTip>, Off
    ToolTip
    showToolTipStatus := false
return

;进入、退出模式时显示提示
DisplayMode(ahk_class_name, mode_name)
{
    Global vim
    Global showToolTipStatus

    ToolTip, 进入 %mode_name% 模式
    showToolTipStatus := true

    SetTimer, <RemoveToolTip>, 500
}

ShowHelp()
{
    Global vim

    modeObj := vim.GetMode(vim.LastFoundWin)

    np := "help`n"
    np .= "=====================`n"

    for i, k in modeObj.keymapList
    {
        if (i >= 0 && i <= 9)
        {
            Continue
        }

        act := vim.GetAction(modeObj.GetKeyMap(i))
        if (act.Comment <> "VIMD命令执行")
        {
            np .= i "`t" act.Comment "`n"
        }
        else
        {
            Global arr_vimd
            np .= i "`t" arr_vimd[i] "`n"
        }
    }

    MouseGetPos, posx, posy, A
    posx += 40
    posy += 40
    Tooltip, %np%, %posx%, %posy%
}

<ShowHelp>:
    Global showToolTipStatus

    if (!showToolTipStatus)
    {
        ShowHelp()
    }
    else
    {
        ToolTip
    }

    showToolTipStatus := !showToolTipStatus
return

<GKey>:
    Run, %A_ScriptDir%\tools\GKey.ahk
return

<ToggleCapsLock>:
    GetKeyState, CapsLockState, CapsLock, T
    if CapsLockState = D
        SetCapsLockState, AlwaysOff
    else
        SetCapsLockState, AlwaysOn
return

<MouseUp>:
    MouseMove, 0, -10, 0, R
return

<MouseDown>:
    MouseMove, 0, 10, 0, R
return

<MouseLeft>:
    MouseMove, -10, 0, 0, R
return

<MouseRight>:
    MouseMove, 10, 0, 0, R
return

<SearchInWeb>:
    Run, https://www.baidu.com/s?wd=%clipboard%
return

General:
    Gen_Save_Win := []
    vim.SetAction("<down>", "向下移动")
    vim.SetAction("<up>", "向上移动")
    vim.SetAction("<left>", "向左移动")
    vim.SetAction("<right>", "向右移动")
    vim.SetAction("<home>", "home键")
    vim.SetAction("<end>", "end键")
    vim.SetAction("<Gen_InsertMode>", "插入模式")
    vim.SetAction("<Gen_NormalMode>", "浏览模式")
    vim.SetAction("<Gen_Toggle>", "启用/禁用vim热键(General插件)")
    vim.SetAction("<Reload>", "重新加载")
    vim.SetAction("<WindowMoveDown>", "窗口移动到下方")
    vim.SetAction("<WindowMoveUp>", "窗口移动到上方")
    vim.SetAction("<WindowMoveLeft>", "窗口移动到左侧")
    vim.SetAction("<WindowMoveRight>", "窗口移动到右侧")
    vim.SetAction("<WindowMoveCenter>", "窗口移动到中间")
    vim.SetAction("<WindowMax>", "最大化窗口")
    vim.SetAction("<WindowMin>", "最小化窗口")
    vim.SetAction("<WindowRestore>", "还原当前窗口")
    vim.SetAction("<FullScreen>", "全屏当前程序")
    vim.SetAction("<NextTab>", "下一个标签")
    vim.SetAction("<PrevTab>", "前一个标签")
    vim.SetAction("<CloseTab>", "关闭当前标签")
    vim.SetAction("<NewTab>", "新建标签")
    vim.SetAction("<ActivateTab1>", "激活第一个标签")
    vim.SetAction("<ActivateTab2>", "激活第二个标签")
    vim.SetAction("<ActivateTab3>", "激活第三个标签")
    vim.SetAction("<ActivateTab4>", "激活第四个标签")
    vim.SetAction("<ActivateTab5>", "激活第五个标签")
    vim.SetAction("<ActivateTab6>", "激活第六个标签")
    vim.SetAction("<ActivateTab7>", "激活第七个标签")
    vim.SetAction("<ActivateTab8>", "激活第八个标签")
    vim.SetAction("<ActivateTab9>", "激活第九个标签")
    vim.SetAction("<ActivateTab0>", "激活最后一个标签")
    vim.SetAction("<pgup>", "上一页")
    vim.SetAction("<pgdn>", "下一页")
    vim.SetAction("<enter>", "回车键")
    vim.SetAction("<Pass>", "屏蔽按键")
    vim.SetAction("<Media_Next>", "播放下一首")
    vim.SetAction("<Media_Prev>", "播放上一首")
    vim.SetAction("<Media_Play_Pause>", "播放/停止")
    vim.SetAction("<Media_Stop>", "停止播放")
    vim.SetAction("<RemoveToolTip>", "清除屏幕的ToolTip")
    vim.SetAction("<ShowHelp>", "显示所有按键帮助信息")
    vim.SetAction("<ToggleCapsLock>", "切换大小写")
    vim.SetAction("<MouseUp>", "向上移动鼠标")
    vim.SetAction("<MouseDown>", "向下移动鼠标")
    vim.SetAction("<MouseLeft>", "向左移动鼠标")
    vim.SetAction("<MouseRight>", "向右移动鼠标")
    vim.SetAction("<SearchInWeb>", "在网络搜索剪切板内容")
    vim.SetAction("<GKey>", "GKey全局快捷操作")

    vim.SetWin("General", "General")
    vim.SetMode("insert", "General")
    vim.map("<Esc>", "<Gen_NormalMode>", "General")
    vim.SetMode("normal", "General")
    vim.map("i", "<Gen_InsertMode>", "General")
    vim.map("0", "<0>", "General")
    vim.map("1", "<1>", "General")
    vim.map("2", "<2>", "General")
    vim.map("3", "<3>", "General")
    vim.map("4", "<4>", "General")
    vim.map("5", "<5>", "General")
    vim.map("6", "<6>", "General")
    vim.map("7", "<7>", "General")
    vim.map("8", "<8>", "General")
    vim.map("9", "<9>", "General")
    vim.map("k", "<up>", "General")
    vim.map("j", "<down>", "General")
    vim.map("k", "<up>", "General")
    vim.map("h", "<left>", "General")
    vim.map("l", "<right>", "General")
    vim.map("zj", "<WindowMoveDown>", "General")
    vim.map("zk", "<WindowMoveUp>", "General")
    vim.map("zh", "<WindowMoveLeft>", "General")
    vim.map("zl", "<WindowMoveRight>", "General")
    vim.map("zc", "<WindowMoveCenter>", "General")
    vim.map("zf", "<fullscreen>", "General")
    vim.map("zm", "<WindowMax>", "General")
    vim.map("zn", "<WindowMin>", "General")
    vim.map("zr", "<WindowRestore>", "General")
    vim.map("t", "<NewTab>", "General")
    vim.map("x", "<CloseTab>", "General")
    vim.map("gn", "<NextTab>", "General")
    vim.map("gp", "<PrevTab>", "General")
    vim.map("g1", "<ActivateTab1>", "General")
    vim.map("g2", "<ActivateTab2>", "General")
    vim.map("g3", "<ActivateTab3>", "General")
    vim.map("g4", "<ActivateTab4>", "General")
    vim.map("g5", "<ActivateTab5>", "General")
    vim.map("g6", "<ActivateTab6>", "General")
    vim.map("g7", "<ActivateTab7>", "General")
    vim.map("g8", "<ActivateTab8>", "General")
    vim.map("g9", "<ActivateTab9>", "General")
    vim.map("g0", "<ActivateTab0>", "General")
    vim.BeforeActionDo("Gen_Before", "General")
return

Gen_Before()
{
    Global vim
    WinGet, MenuID, ID, AHK_CLASS #32768
    If MenuID
        return True
}

<Gen_InsertMode>:
    vim.SetMode("Insert", vim.CheckWin())
    Tooltip, Insert模式, , , 19
    Settimer, cancelTooltip, 1200
return
<Gen_NormalMode>:
    vim.SetMode("Normal", vim.CheckWin())
    Tooltip, Normal模式, , , 19
    Settimer, cancelTooltip, 1200
return
<Gen_Toggle>:
    Gen_Toggle()
return
Gen_Toggle()
{
    Global vim, Gen_Save_Win
    WinGetClass, c, A
    WinGet, f, ProcessPath, ahk_class %c%
    WinName:=vim.CheckWin()
    If not Gen_Save_Win[c]
    {
        If Strlen(winName) And IsObject(vim.GetWin(winName))
        {
            MsgBox, , VimDesktop, 当前窗口 [ %winName% ] 已经拥有Vim模式`n不允许替换为通用(General)模式！
            return
        }
    }
    winObj := vim.GetWin(c)
    If not Isobject(winObj)
    {
        vim.copy("General", c, c, f)
        Gen_Save_Win[c] := True
        Tooltip, 复制VIMD热键到当前窗口成功, , , 19
    }
    Else
    {
        if vim.Toggle(c)
            Tooltip, 激活当前窗口的VIMD热键, , , 19
        else
            Tooltip, 取消当前窗口的VIMD热键, , , 19
    }
    Settimer, cancelTooltip, 1200
}
cancelTooltip:
    Tooltip, , , , 19
return
<reload>:
    reload
return
<Exit>:
    ExitApp
return
<down>:
    send, {down}
return
<up>:
    send, {up}
return
<left>:
    send, {left}
return
<right>:
    send, {right}
return
<home>:
    send, {home}
return
<end>:
    send, {end}
return
<pgup>:
    send, {pgup}
return
<pgdn>:
    send, {pgdn}
return
<enter>:
    send {enter}
return
<Media_Next>:
    send {Media_Next}
return
<Media_Prev>:
    send {Media_Prev}
return
<Media_Stop>:
    send {Media_Stop}
return
<Media_Play_Pause>:
    send {Media_Play_Pause}
return

<WindowMoveDown>:
    WindowPadMove("0, +1, 1.0, 0.5")
Return
<WindowMoveUp>:
    WindowPadMove("0, -1, 1.0, 0.5")
Return
<WindowMoveLeft>:
    WindowPadMove("-1, 0, 0.5, 1.0")
Return
<WindowMoveRight>:
    WindowPadMove("+1, 0, 0.5, 1.0")
Return
<WindowMoveCenter>:
    WindowPadMove("0, 0, 0.5, 0.7")
return
<WindowMax>:
    WinMaximize, A
return
<WindowMin>:
    WinMinimize, A
return
<WindowRestore>:
    WinRestore, A
return

; 全屏当前程序
<FullScreen>:
    FullScreen()
return
FullScreen() {
    WinGet, windowID, ID, A
    WindowState := FullScreenID[windowID]
    If Strlen(windowState) = 0
        WindowState := 0
    If WindowState
    {
        WinSet, Style, ^0xC40000, ahk_id %WindowID%
        Loop, Parse, windowState, `,
        {
            If A_Index = 2
                WinPosX := A_LoopField
            If A_Index = 3
                WinPosY := A_LoopField
            If A_Index = 4
                WindowWidth := A_LoopField
            If A_Index = 5
                WindowHeight := A_LoopField
        }
        WinMove, ahk_id %WindowID%, , WinPosX, WinPosY, WindowWidth, WindowHeight
        WindowState := 0
    }
    Else
    {
        WinGetPos, WinPosX, WinPosY, WindowWidth, WindowHeight, ahk_id %WindowID%
        WinSet, Style, ^0xC40000, ahk_id %WindowID%
        WinMove, ahk_id %WindowID%, , 0, 0, A_ScreenWidth, A_ScreenHeight
        WindowState := 1 ", " WinPosX ", " WinPosY ", " WindowWidth ", " WindowHeight
        ;Msgbox 再按一下刚刚的热键退出全屏
    }
    FullScreenID[windowID] := WindowState
}

;====================================================================================
;
; WindowPad.ahk
; Version: 0.4
; Last Updated: 11/5/2009
;
; This file contains functions which are useful for manipulating and moving windows.
; This is a stripped down version of WindowPad v.1.56 by Lexikos.
; Downloaded from http://www.autohotkey.com/forum/topic21703.html
;

WindowPadMove(P)
{
    StringSplit, P, P, `, , %A_Space%%A_Tab%
    ; Params: 1:dirX, 2:dirY, 3:widthFactor, 4:heightFactor, 5:window

    if P1 =
        P1 = R
    if P2 =
        P2 = R

    WindowPad_WinExist(P5)

    if !WinExist()
        return

    ; Determine width/height factors.
    if (P1 or P2) {
        ; to a side
        widthFactor := P3+0 ? P3 : (P1 ? 0.5 : 1.0)
        heightFactor := P4+0 ? P4 : (P2 ? 0.5 : 1.0)
    } else {
        ; to center
        widthFactor  := P3+0 ? P3 : 1.0
        heightFactor := P4+0 ? P4 : 1.0
    }

    ; Move the window!
    MoveWindowInDirection(P1, P2, widthFactor, heightFactor)
}

MaximizeToggle(P)
{
    WindowPad_WinExist(P)

    WinGet, state, MinMax
    if state
        WinRestore
    else
        WinMaximize
}

; Does the grunt work of the script.
MoveWindowInDirection(sideX, sideY, widthFactor, heightFactor)
{
    WinGetPos, x, y, w, h

    hwnd:=WinExist()
    if (can_restore := GetWindowProperty(hwnd, "wpHasRestorePos"))
    {   ; Window has restore info. Check if it is where we last put it.
        last_x := GetWindowProperty(hwnd, "wpLastX")
        last_y := GetWindowProperty(hwnd, "wpLastY")
        last_w := GetWindowProperty(hwnd, "wpLastW")
        last_h := GetWindowProperty(hwnd, "wpLastH")
    }
    if (can_restore && last_x = x && last_y = y && last_w = w && last_h = h)
    {   ; Window is where we last put it. Check if user wants to restore.
        if SubStr(sideX, 1, 1) = "R"
        {   ; Restore on X-axis.
            restore_x := GetWindowProperty(hwnd, "wpRestoreX")
            restore_w := GetWindowProperty(hwnd, "wpRestoreW")
            StringTrimLeft, sideX, sideX, 1
        }
        if SubStr(sideY, 1, 1) = "R"
        {   ; Restore on Y-axis.
            restore_y := GetWindowProperty(hwnd, "wpRestoreY")
            restore_h := GetWindowProperty(hwnd, "wpRestoreH")
            StringTrimLeft, sideY, sideY, 1
        }
        if (restore_x != "" || restore_y != "")
        {   ; If already at the "restored" size and position, do the normal thing instead.
            if ((restore_x = x || restore_x = "") && (restore_y = y || restore_y = "")
                && (restore_w = w || restore_w = "") && (restore_h = h || restore_h = ""))
            {
                restore_x =
                restore_y =
                restore_w =
                restore_h =
            }
        }
    }
    else
    {   ; Next time user requests the window be "restored" use this position and size.
        SetWindowProperty(hwnd, "wpHasRestorePos", true)
        SetWindowProperty(hwnd, "wpRestoreX", x)
        SetWindowProperty(hwnd, "wpRestoreY", y)
        SetWindowProperty(hwnd, "wpRestoreW", w)
        SetWindowProperty(hwnd, "wpRestoreH", h)

        if SubStr(sideX, 1, 1) = "R"
            StringTrimLeft, sideX, sideX, 1
        if SubStr(sideY, 1, 1) = "R"
            StringTrimLeft, sideY, sideY, 1
    }

    ; If no direction specified, restore or only switch monitors.
    if (sideX+0 = "" && restore_x = "")
        restore_x := x, restore_w := w
    if (sideY+0 = "" && restore_y = "")
        restore_y := y, restore_h := h

    ; Determine which monitor contains the center of the window.
    m := GetMonitorAt(x+w/2, y+h/2)

    ; Get work area of active monitor.
    gosub CalcMonitorStats
    ; Calculate possible new position for window.
    gosub CalcNewSizeAndPosition

    ; If the window is already there,
    if (newx ", " newy ", " neww ", " newh) = (x ", " y ", " w ", " h)
    {   ; ..move to the next monitor along instead.

        if (sideX or sideY)
        {   ; Move in the direction of sideX or sideY.
            SysGet, monB, Monitor, %m% ; get bounds of entire monitor (vs. work area)
            x := (sideX=0) ? (x+w/2) : (sideX>0 ? monBRight : monBLeft) + sideX
            y := (sideY=0) ? (y+h/2) : (sideY>0 ? monBBottom : monBTop) + sideY
            newm := GetMonitorAt(x, y, m)
        }
        else
        {   ; Move to center (Numpad5)
            newm := m+1
            SysGet, mon, MonitorCount
            if (newm > mon)
                newm := 1
        }

        if (newm != m)
        {
            m := newm
            ; Move to opposite side of monitor (left of a monitor is another monitor's right edge)
            sideX *= -1
            sideY *= -1
            ; Get new monitor's work area.
            gosub CalcMonitorStats
        }
        else
        {
            ; No monitor to move to, alternate size of window instead.
            if sideX
                widthFactor /= 2
            else if sideY
                heightFactor /= 2
            else
                widthFactor *= 1.5
            gosub CalcNewSizeAndPosition
        }

        ; Calculate new position for window.
        gosub CalcNewSizeAndPosition
    }

    ; Restore before resizing...
    WinGet, state, MinMax
    if state
        WinRestore

    WinDelay := A_WinDelay
    SetWinDelay, 0

    ; Move the window!
    WinMove, , , newx, newy, neww, newh

    ; For console windows and other windows which have size restrictions, check
    ; that the window was actually resized. If not, reposition based on actual size.
    WinGetPos, newx, newy, realw, realh
    if (neww != realw || newh != realh)
    {
        neww := realw
        newh := realh
        gosub CalcNewPosition
        if ((newm = "" || newm = m) && (newx ", " newy ", " realw ", " realh)=(x ", " y ", " w ", " h))
        {
            if sideX
                neww //= 2
            else if sideY
                newh //= 2
            else
                neww := Round(neww*1.5)
            ; Size first, since the window size will probably be restricted in some way.
            WinMove, , , , , neww, newh
            WinGetPos, , , neww, newh
            gosub CalcNewPosition
        }
        WinMove, , , newx, newy
    }

    ; Explorer uses WM_EXITSIZEMOVE to detect when a user finishes moving a window
    ; in order to save the position for next time. May also be used by other apps.
    PostMessage, 0x232

    SetWinDelay, WinDelay

    ; Remember where we put it, to detect if the user moves it.
    SetWindowProperty(hwnd, "wpLastX", newx)
    SetWindowProperty(hwnd, "wpLastY", newy)
    SetWindowProperty(hwnd, "wpLastW", neww)
    SetWindowProperty(hwnd, "wpLastH", newh)
    return

CalcNewSizeAndPosition:
    ; Calculate new size.
    if (IsResizable()) {
        neww := restore_w != "" ? restore_w : Round(monWidth * widthFactor)
        newh := restore_h != "" ? restore_h : Round(monHeight * heightFactor)
    } else {
        neww := w
        newh := h
    }
CalcNewPosition:
    ; Calculate new position.
    newx := restore_x != "" ? restore_x : Round(monLeft + (sideX+1) * (monWidth  - neww)/2)
    newy := restore_y != "" ? restore_y : Round(monTop  + (sideY+1) * (monHeight - newh)/2)
    return

CalcMonitorStats:
    ; Get work area (excludes taskbar-reserved space.)
    SysGet, mon, MonitorWorkArea, %m%
    monWidth  := monRight - monLeft
    monHeight := monBottom - monTop
    return
}

; Get/set window property. type should be int, uint or float.
GetWindowProperty(hwnd, property_name, type="int") {
    return DllCall("GetProp", "uint", hwnd, "str", property_name, type)
}
SetWindowProperty(hwnd, property_name, data, type="int") {
    return DllCall("SetProp", "uint", hwnd, "str", property_name, type, data)
}

; Get the index of the monitor containing the specified x and y co-ordinates.
GetMonitorAt(x, y, default=1)
{
    SysGet, m, MonitorCount
    ; Iterate through all monitors.
    Loop, %m%
    {
        ; Check if the window is on this monitor.
        SysGet, Mon, Monitor, %A_Index%
        if (x >= MonLeft && x <= MonRight && y >= MonTop && y <= MonBottom)
            return A_Index
    }

    return default
}

IsResizable()
{
    WinGetClass, Class
    if Class = Chrome_XPFrame
        return true
    if Class = ConsoleWindowClass
        return false
    WinGet, Style, Style
    return (Style & 0x40000) ; WS_SIZEBOX
}

WindowPad_WinExist(WinTitle)
{
    if WinTitle = P
        return WinPreviouslyActive()
    if WinTitle = M
    {
        MouseGetPos, , , win
        return WinExist("ahk_id " win)
    }
    return WinExist(WinTitle!="" ? WinTitle : "A")
}

; Note: This may not work properly with always-on-top windows. (Needs testing)
WinPreviouslyActive()
{
    active := WinActive("A")
    WinGet, win, List

    ; Find the active window.
    ; (Might not be win1 if there are always-on-top windows?)
    Loop, %win%
        if (win%A_Index% = active)
        {
            if (A_Index < win)
                N := A_Index+1

            ; hack for PSPad: +1 seems to get the document (child!) window, so do +2
            ifWinActive, ahk_class TfPSPad
                N += 1

            break
        }

    ; Use WinExist to set Last Found Window (for consistency with WinActive())
    return WinExist("ahk_id " . win%N%)
}

;
; Switch without moving/resizing (relative to screen)
;
WindowScreenMove(P)
{
    SetWinDelay, 0

    StringSplit, P, P, `, , %A_Space%%A_Tab%
    ; 1:Next|Prev|Num, 2:Window

    WindowPad_WinExist(P2)

    WinGet, state, MinMax
    if state = 1
        WinRestore

    WinGetPos, x, y, w, h

    ; Determine which monitor contains the center of the window.
    ms := GetMonitorAt(x+w/2, y+h/2)

    SysGet, mc, MonitorCount

    ; Determine which monitor to move to.
    if P1 in , N, Next
    {
        md := ms+1
        if (md > mc)
            md := 1
    }
    else if P1 in P, Prev, Previous
    {
        md := ms-1
        if (md < 1)
            md := mc
    }
    else if P1 is integer
        md := P1

    if (md=ms or (md+0)="" or md<1 or md>mc)
        return

    ; Get source and destination work areas (excludes taskbar-reserved space.)
    SysGet, ms, MonitorWorkArea, %ms%
    SysGet, md, MonitorWorkArea, %md%
    msw := msRight - msLeft, msh := msBottom - msTop
    mdw := mdRight - mdLeft, mdh := mdBottom - mdTop

    ; Calculate new size.
    if (IsResizable()) {
        w := Round(w*(mdw/msw))
        h := Round(h*(mdh/msh))
    }

    ; Move window, using resolution difference to scale co-ordinates.
    WinMove, , , mdLeft + (x-msLeft)*(mdw/msw), mdTop + (y-msTop)*(mdh/msh), w, h

    if state = 1
        WinMaximize
}

;
; "Gather" windows on a specific screen.
;
GatherWindows(md=1)
{
    global ProcessGatherExcludeList

    SetWinDelay, 0

    ; List all visible windows.
    WinGet, win, List

    ; Copy bounds of all monitors to an array.
    SysGet, mc, MonitorCount
    Loop, %mc%
        SysGet, mon%A_Index%, MonitorWorkArea, %A_Index%

    if md = M
    {
        ; Special exception for 'M', since the desktop window
        ; spreads across all screens.
        CoordMode, Mouse, Screen
        MouseGetPos, x, y
        md := GetMonitorAt(x, y, 0)
    }
    else if md is not integer
    {
        ; Support A, P and WinTitle.
        ; (Gather at screen containing specified window.)
        WindowPad_WinExist(md)
        WinGetPos, x, y, w, h
        md := GetMonitorAt(x+w/2, y+h/2, 0)
    }
    if (md<1 or md>mc)
        return

    ; Destination monitor
    mdx := mon%md%Left
    mdy := mon%md%Top
    mdw := mon%md%Right - mdx
    mdh := mon%md%Bottom - mdy

    Loop, %win%
    {
        ; If this window matches the GatherExclude group, don't touch it.
        if (WinExist("ahk_group GatherExclude ahk_id " . win%A_Index%))
            continue

        ; Set Last Found Window.
        if (!WinExist("ahk_id " . win%A_Index%))
            continue

        WinGet, procname, ProcessName
        ; Check process (program) exclusion list.
        if procname in %ProcessGatherExcludeList%
            continue

        WinGetPos, x, y, w, h

        ; Determine which monitor this window is on.
        xc := x+w/2, yc := y+h/2
        ms := 0
        Loop, %mc%
            if (xc >= mon%A_Index%Left && xc <= mon%A_Index%Right
                && yc >= mon%A_Index%Top && yc <= mon%A_Index%Bottom)
            {
                ms := A_Index
                break
            }
        ; If already on destination monitor, skip this window.
        if (ms = md)
            continue

        WinGet, state, MinMax
        if (state = 1) {
            WinRestore
            WinGetPos, x, y, w, h
        }

        if ms
        {
            ; Source monitor
            msx := mon%ms%Left
            msy := mon%ms%Top
            msw := mon%ms%Right - msx
            msh := mon%ms%Bottom - msy

            ; If the window is resizable, scale it by the monitors' resolution difference.
            if (IsResizable()) {
                w *= (mdw/msw)
                h *= (mdh/msh)
            }

            ; Move window, using resolution difference to scale co-ordinates.
            WinMove, , , mdx + (x-msx)*(mdw/msw), mdy + (y-msy)*(mdh/msh), w, h
        }
        else
        {
            ; Window not on any monitor, move it to center.
            WinMove, , , mdx + (mdw-w)/2, mdy + (mdh-h)/2
        }

        if state = 1
            WinMaximize
    }
}

GetLastMinimizedWindow()
{
    WinGet, w, List

    Loop %w%
    {
        wi := w%A_Index%
        WinGet, m, MinMax, ahk_id %wi%
        if m = -1 ; minimized
        {
            lastFound := wi
            break
        }
    }

    return "ahk_id " . (lastFound ? lastFound : 0)
}

;================================== 功能代码 :由北风一叶提供
;下一个标签
<NextTab>:
    send ^{tab}
return

;上一个标签
<PrevTab>:
    send ^+{tab}
return

;关闭当前标签
<CloseTab>:
    send ^{w}
return

;新建标签
<NewTab>:
    send ^{t}
return

;激活第一个标签
<ActivateTab1>:
    send ^{1}
return

;激活第二个标签
<ActivateTab2>:
    send ^{2}
return

;激活第三个标签
<ActivateTab3>:
    send ^{3}
return

;激活第四个标签
<ActivateTab4>:
    send ^{4}
return

;激活第五个标签
<ActivateTab5>:
    send ^{5}
return

;激活第六个标签
<ActivateTab6>:
    send ^{6}
return

;激活第七个标签
<ActivateTab7>:
    send ^{7}
return

;激活第八个标签
<ActivateTab8>:
    send ^{8}
return

;激活第九个标签
<ActivateTab9>:
    send ^{8}^{tab}
return

;激活最后一个标签
<ActivateTab0>:
    send ^{9}
return

;清除 ToolTip 计时器
<RemoveToolTip>:
    Global showToolTipStatus

    SetTimer, <RemoveToolTip>, Off
    ToolTip
    showToolTipStatus := false
return

;进入、退出模式时显示提示
DisplayMode(ahk_class_name, mode_name)
{
    Global vim
    Global showToolTipStatus

    ToolTip, 进入 %mode_name% 模式
    showToolTipStatus := true

    SetTimer, <RemoveToolTip>, 500
}

ShowHelp()
{
    Global vim

    modeObj := vim.GetMode(vim.LastFoundWin)

    np := "help`n"
    np .= "=====================`n"

    for i, k in modeObj.keymapList
    {
        if (i >= 0 && i <= 9)
        {
            Continue
        }

        act := vim.GetAction(modeObj.GetKeyMap(i))
        np .= i "`t" act.Comment "`n"
    }

    MouseGetPos, posx, posy, A
    posx += 40
    posy += 40
    Tooltip, %np%, %posx%, %posy%
}

<ShowHelp>:
    Global showToolTipStatus

    if (!showToolTipStatus)
    {
        ShowHelp()
    }
    else
    {
        ToolTip
    }

    showToolTipStatus := !showToolTipStatus
return

<GKey>:
    Run, %A_ScriptDir%\tools\GKey.ahk
return

<ToggleCapsLock>:
    GetKeyState, CapsLockState, CapsLock, T
    if CapsLockState = D
        SetCapsLockState, AlwaysOff
    else
        SetCapsLockState, AlwaysOn
return

<MouseUp>:
    MouseMove, 0, -10, 0, R
return

<MouseDown>:
    MouseMove, 0, 10, 0, R
return

<MouseLeft>:
    MouseMove, -10, 0, 0, R
return

<MouseRight>:
    MouseMove, 10, 0, 0, R
return

<SearchInWeb>:
    Run, https://www.baidu.com/s?wd=%clipboard%
return