Add About box with version numbers

Add About box with version numbers

; JKLmouse for AutoHotkey by Michael Geary
; http://www.jklmouse.com/ - documentation
; http://unlicense.org/ - public domain statement

#SingleInstance force

version := "0.2x"

; Use either the embedded icon in a compiled .exe,
; or a separate .ico file when running the .ahk script.
iconPath := RegExReplace( A_ScriptFullPath, "i).ahk$", ".ico" )

keyMap := ""

keyMaps :=
(join
{
	Arrows: "Up~Up Down~Down Left~Left Right~Right",
	NumPad: "7~UpLeft 8~Up 9~UpRight 4~Left 5~Down 6~Right 1~DownLeft 2~Down 3~DownRight",
	IJKL: "U~UpLeft I~Up O~UpRight J~Left K~Down L~Right M~DownLeft ,~Down .~DownRight",
	HJKL: "H~Left J~Down K~Up L~Right",
	ESDF: "W~UpLeft E~Up R~UpRight S~Left D~Down F~Right X~DownLeft C~Down V~DownRight",
	WASD: "Q~UpLeft W~Up E~UpRight A~Left S~Down D~Right Z~DownLeft X~Down C~DownRight"
}
)

; Set up the tray icon and menu
Menu, Tray, Icon, %iconPath%
Menu, Tray, Tip, JKLmouse
Menu, Tray, Add
Menu, Tray, Add, Left Hand: ESDF, MenuESDF
Menu, Tray, Add, Left Hand: WASD, MenuWASD
Menu, Tray, Add
Menu, Tray, Add, Right Hand: IJKL, MenuIJKL
Menu, Tray, Add, Right Hand: HJKL, MenuHJKL
Menu, Tray, Add
Menu, Tray, Add, About JKLmouse, MenuAbout
Menu, Tray, Add, JKLmouse Website, MenuWebsite

Menu, Tray, Check, Left Hand: ESDF
Menu, Tray, Check, Right Hand: IJKL

; Display tray balloon
; TODO: more useful content?
; TODO: display this only during an install
TrayTip JKLmouse, The Automatic Keyboard Mouse

; Remove forced delay between triggered mouse events.
; TODO: experiment with this when accelerated
SetMouseDelay, -1

; Hotkey repeat count for acceleration
repeat := 0

SetKeyMap( "Arrows", "NumPad", "IJKL", "ESDF" )
;SetKeyMap( "Arrows", "NumPad", "HJKL", "WASD" )

;MsgBox % keyMap

SetAllKeys( true )

return

SetKeyMap( keys* ) {
	global keyMap, keyMaps
    for index, value in keys
        keyMap .= keyMaps[value] . " "
    return SubStr( str, 1, -StrLen(sep) )
}

SetAllKeys( on ) {
	; Each of these modifier keys enables the same set of JKLmouse hotkeys
	SetKeys( on, "CapsLock" )
	SetKeys( on, "~LButton" )
	SetKeys( on, "~RButton" )
	SetKeys( on, "~MButton" )
	SetKeys( on, "~XButton1" )
	SetKeys( on, "~XButton2" )
}

; Set up or remove all the hotkeys for a specific modifier key
SetKeys( on, mod ) {
	global keyMap
	Loop, Parse, keyMap, %A_Space%
	{
		StringSplit map, A_LoopField, ~
		SetKey( on, mod, map1, "Mouse" . map2 )
	}
}

; Set up or remove one hotkey by combining the modifier and key names.
; Take the specified action on key down,
; and always stop acceleration on key up.
SetKey( on, mod, key, action ) {
	keydown = %mod% & %key%
	if( on ) {
		Hotkey %keydown%, %action%
		Hotkey %keydown% UP, StopAcceleration
	}
	else {
		Hotkey %keydown%, Off
		Hotkey %keydown% UP, Off
	}
}

; Move the mouse the specifed x and y distances, both scaled by the
; mouse acceleration factor calculated from the key repeat count.
Move( x, y ) {
	global repeat
	++repeat
	factor := Floor( ( repeat + 1 ) / 2 )
	x := x * factor
	y := y * factor
	MouseMove, x, y, 0, R
}

;ArrayJoin( sep, ary ) {
;    for index, value in ary
;		MsgBox % index
;        ;str .= value . sep
;	MsgBox % str
;    return SubStr( str, 1, -StrLen(sep) )
;}

; Handle the keydown for each of the mouse movement directions
; TODO: Maybe a way to simplify this?
MouseUp:
	Move( 0, -1 )
	return
MouseDown:
	Move( 0, 1 )
	return
MouseLeft:
	Move( -1, 0 )
	return
MouseRight:
	Move( 1, 0 )
	return
MouseUpLeft:
	Move( -1, -1 )
	return
MouseUpRight:
	Move( 1, -1 )
	return
MouseDownLeft:
	Move( -1, 1 )
	return
MouseDownRight:
	Move( 1, 1 )
	return

; Handle the keyup for all hotkeys
StopAcceleration:
	repeat = 0
	return

; Handle the About menu item
MenuAbout:
	MsgBox, 0x2040, JKLmouse by Geary Labs, JKLmouse version %version%`nAutoHotkey version %A_AhkVersion%
	return

; Handle the Website menu item
MenuWebsite:
	Run, http://www.jklmouse.com/
	return

MenuESDF:
	return

MenuWASD:
	return

MenuIJKL:
	return

MenuHJKL:
	return

; JKLmouse for AutoHotkey by Michael Geary
; http://www.jklmouse.com/ - documentation
; http://unlicense.org/ - public domain statement
; Version 0.1: 11/3/2011

#SingleInstance force

; Use either the embedded icon in a compiled .exe,
; or a separate .ico file when running the .ahk script.
iconPath := RegExReplace( A_ScriptFullPath, "i).ahk$", ".ico" )

keyMap := ""

keyMaps :=
(join
{
	Arrows: "Up~Up Down~Down Left~Left Right~Right",
	NumPad: "7~UpLeft 8~Up 9~UpRight 4~Left 5~Down 6~Right 1~DownLeft 2~Down 3~DownRight",
	IJKL: "U~UpLeft I~Up O~UpRight J~Left K~Down L~Right M~DownLeft ,~Down .~DownRight",
	HJKL: "H~Left J~Down K~Up L~Right",
	ESDF: "W~UpLeft E~Up R~UpRight S~Left D~Down F~Right X~DownLeft C~Down V~DownRight",
	WASD: "Q~UpLeft W~Up E~UpRight A~Left S~Down D~Right Z~DownLeft X~Down C~DownRight"
}
)

; Set up the tray icon and menu
Menu, Tray, Icon, %iconPath%
Menu, Tray, Tip, JKLmouse
Menu, Tray, Add
Menu, Tray, Add, Left Hand: ESDF, MenuESDF
Menu, Tray, Add, Left Hand: WASD, MenuWASD
Menu, Tray, Add
Menu, Tray, Add, Right Hand: IJKL, MenuIJKL
Menu, Tray, Add, Right Hand: HJKL, MenuHJKL
Menu, Tray, Add
Menu, Tray, Add, About JKLmouse, MenuAbout

Menu, Tray, Check, Left Hand: ESDF
Menu, Tray, Check, Right Hand: IJKL

; Display tray balloon
; TODO: more useful content?
; TODO: display this only during an install
TrayTip JKLmouse, The Automatic Keyboard Mouse

; Remove forced delay between triggered mouse events.
; TODO: experiment with this when accelerated
SetMouseDelay, -1

; Hotkey repeat count for acceleration
repeat := 0

SetKeyMap( "Arrows", "NumPad", "IJKL", "ESDF" )
;SetKeyMap( "Arrows", "NumPad", "HJKL", "WASD" )

;MsgBox % keyMap

SetAllKeys( true )

return

SetKeyMap( keys* ) {
	global keyMap, keyMaps
    for index, value in keys
        keyMap .= keyMaps[value] . " "
    return SubStr( str, 1, -StrLen(sep) )
}

SetAllKeys( on ) {
	; Each of these modifier keys enables the same set of JKLmouse hotkeys
	SetKeys( on, "CapsLock" )
	SetKeys( on, "~LButton" )
	SetKeys( on, "~RButton" )
	SetKeys( on, "~MButton" )
	SetKeys( on, "~XButton1" )
	SetKeys( on, "~XButton2" )
}

; Set up or remove all the hotkeys for a specific modifier key
SetKeys( on, mod ) {
	global keyMap
	Loop, Parse, keyMap, %A_Space%
	{
		StringSplit map, A_LoopField, ~
		SetKey( on, mod, map1, "Mouse" . map2 )
	}
}

; Set up or remove one hotkey by combining the modifier and key names.
; Take the specified action on key down,
; and always stop acceleration on key up.
SetKey( on, mod, key, action ) {
	keydown = %mod% & %key%
	if( on ) {
		Hotkey %keydown%, %action%
		Hotkey %keydown% UP, StopAcceleration
	}
	else {
		Hotkey %keydown%, Off
		Hotkey %keydown% UP, Off
	}
}

; Move the mouse the specifed x and y distances, both scaled by the
; mouse acceleration factor calculated from the key repeat count.
Move( x, y ) {
	global repeat
	++repeat
	factor := Floor( ( repeat + 1 ) / 2 )
	x := x * factor
	y := y * factor
	MouseMove, x, y, 0, R
}

;ArrayJoin( sep, ary ) {
;    for index, value in ary
;		MsgBox % index
;        ;str .= value . sep
;	MsgBox % str
;    return SubStr( str, 1, -StrLen(sep) )
;}

; Handle the keydown for each of the mouse movement directions
; TODO: Maybe a way to simplify this?
MouseUp:
	Move( 0, -1 )
	return
MouseDown:
	Move( 0, 1 )
	return
MouseLeft:
	Move( -1, 0 )
	return
MouseRight:
	Move( 1, 0 )
	return
MouseUpLeft:
	Move( -1, -1 )
	return
MouseUpRight:
	Move( 1, -1 )
	return
MouseDownLeft:
	Move( -1, 1 )
	return
MouseDownRight:
	Move( 1, 1 )
	return

; Handle the keyup for all hotkeys
StopAcceleration:
	repeat = 0
	return

; Handle the About menu item
MenuAbout:
	Run, http://www.jklmouse.com/
	return

MenuESDF:
	return

MenuWASD:
	return

MenuIJKL:
	return

MenuHJKL:
	return


Modified key mappings.

Modified key mappings.

; Autohotkey configuration file
; AHK Version v1.1.22.06
; Franklin Chou (franklin.chou@yahoo.com)
; 20 Nov. 2015

;------------------------------------------------------------------------------
; GLOSSARY OF COMMONLY USED KEY MODIFIERS
;
; # Windows key
; ! Alt key
; ^ Control key
; + Shift key
; < Use the Left key of a pair
; > Use the Right key of a pair
;------------------------------------------------------------------------------

#SingleInstance force

PrintScreen::AppsKey

; Print screen reassigned to Windows Key + PrintScreen
#PrintScreen::PrintScreen

;------------------------------------------------------------------------------
; COMMONLY USED SYMBOL KEYS

>+P::send
>+S::send
;------------------------------------------------------------------------------

#IfWinActive,, Microsoft Word
  PgUp::Home
  PgDn::End
  <!Up:: Send {PgUp}
  <!Down:: Send {PgDn}
#IfWinActive

; 3 lines omitted

#^R::Reload
#B::Run, "FireFox"
#W::Run, "Word"

; Autohotkey configuration file
; AHK Version v1.1.22.06
; Franklin Chou (franklin.chou@yahoo.com)
; 20 Nov. 2015

;------------------------------------------------------------------------------
; GLOSSARY OF COMMONLY USED KEY MODIFIERS
;
; # Windows key
; ! Alt key
; ^ Control key
; + Shift key
; < Use the Left key of a pair
; > Use the Right key of a pair
;------------------------------------------------------------------------------

#SingleInstance force

PrintScreen::AppsKey

; Print screen reassigned to Windows Key + PrintScreen
#PrintScreen::PrintScreen

;------------------------------------------------------------------------------
; COMMONLY USED SYMBOL KEYS

>+P::send
>+S::send
;------------------------------------------------------------------------------

#IfWinActive,, Microsoft Word
  PgUp::Home
  PgDn::End
  <!Up:: Send {PgUp}
  <!Down:: Send {PgDn}
#IfWinActive

; no-commit
FireFox := "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
Word	:= "C:\Program Files\Microsoft Office\Office15\WINWORD.EXE"
; no-commit-end

#^R::Reload
#B::Run, "FireFox"
#W::Run, "Word"


Cleanup

Cleanup

; JKLmouse for AutoHotkey by Michael Geary
; http://jklmouse.com/ - documentation
; http://unlicense.org/ - public domain statement
; Version 0.1: 11/3/2011

#SingleInstance force

repeat = 0

SetKeyDelay, -1
SetMouseDelay, -1

SetHotkeys( modifier ) {

	; TODO: refactor keydown and keyup

	; KEY DOWN

	; Left hand
	Hotkey, %modifier% & W, MouseLeftUp
	Hotkey, %modifier% & E, MouseUp
	Hotkey, %modifier% & R, MouseRightUp
	Hotkey, %modifier% & S, MouseLeft
	Hotkey, %modifier% & D, MouseDown
	Hotkey, %modifier% & F, MouseRight
	Hotkey, %modifier% & X, MouseLeftDown
	Hotkey, %modifier% & C, MouseDown
	Hotkey, %modifier% & V, MouseRightDown

	; Right hand
	Hotkey, %modifier% & U, MouseLeftUp
	Hotkey, %modifier% & I, MouseUp
	Hotkey, %modifier% & O, MouseRightUp
	Hotkey, %modifier% & J, MouseLeft
	Hotkey, %modifier% & K, MouseDown
	Hotkey, %modifier% & L, MouseRight
	Hotkey, %modifier% & M, MouseLeftDown
	Hotkey, %modifier% & `, , MouseDown
	Hotkey, %modifier% & `. , MouseRightDown

	; Numeric
	Hotkey, %modifier% & 7, MouseLeftUp
	Hotkey, %modifier% & 8, MouseUp
	Hotkey, %modifier% & 9, MouseRightUp
	Hotkey, %modifier% & 4, MouseLeft
	Hotkey, %modifier% & 5, MouseDown
	Hotkey, %modifier% & 6, MouseRight
	Hotkey, %modifier% & 1, MouseLeftDown
	Hotkey, %modifier% & 2, MouseDown
	Hotkey, %modifier% & 3, MouseRightDown

	; Arrows
	Hotkey, %modifier% & Up, MouseUp
	Hotkey, %modifier% & Down, MouseDown
	Hotkey, %modifier% & Left, MouseLeft
	Hotkey, %modifier% & Right, MouseRight

	; KEY UP

	; Left hand
	Hotkey, %modifier% & W UP, StopAcceleration
	Hotkey, %modifier% & E UP, StopAcceleration
	Hotkey, %modifier% & R UP, StopAcceleration
	Hotkey, %modifier% & S UP, StopAcceleration
	Hotkey, %modifier% & D UP, StopAcceleration
	Hotkey, %modifier% & F UP, StopAcceleration
	Hotkey, %modifier% & X UP, StopAcceleration
	Hotkey, %modifier% & C UP, StopAcceleration
	Hotkey, %modifier% & V UP, StopAcceleration

	; Right hand
	Hotkey, %modifier% & U UP, StopAcceleration
	Hotkey, %modifier% & I UP, StopAcceleration
	Hotkey, %modifier% & O UP, StopAcceleration
	Hotkey, %modifier% & J UP, StopAcceleration
	Hotkey, %modifier% & K UP, StopAcceleration
	Hotkey, %modifier% & L UP, StopAcceleration
	Hotkey, %modifier% & M UP, StopAcceleration
	Hotkey, %modifier% & `,  UP, StopAcceleration
	Hotkey, %modifier% & `.  UP, StopAcceleration

	; Numeric
	Hotkey, %modifier% & 7 UP, StopAcceleration
	Hotkey, %modifier% & 8 UP, StopAcceleration
	Hotkey, %modifier% & 9 UP, StopAcceleration
	Hotkey, %modifier% & 4 UP, StopAcceleration
	Hotkey, %modifier% & 5 UP, StopAcceleration
	Hotkey, %modifier% & 6 UP, StopAcceleration
	Hotkey, %modifier% & 1 UP, StopAcceleration
	Hotkey, %modifier% & 2 UP, StopAcceleration
	Hotkey, %modifier% & 3 UP, StopAcceleration

	; Arrows
	Hotkey, %modifier% & Up UP, StopAcceleration
	Hotkey, %modifier% & Down UP, StopAcceleration
	Hotkey, %modifier% & Left UP, StopAcceleration
	Hotkey, %modifier% & Right UP, StopAcceleration
}

SetHotkeys( "CapsLock" )
SetHotkeys( "~LButton" )
SetHotkeys( "~RButton" )
SetHotkeys( "~MButton" )
SetHotkeys( "~XButton1" )
SetHotkeys( "~XButton2" )

return

Move( x, y ) {
	global repeat
	++repeat
	factor := Floor( ( repeat + 1 ) / 2 )
	x := x * factor
	y := y * factor
	MouseMove, x, y, 0, R
}

MouseUp:
	Move( 0, -1 )
	return
MouseDown:
	Move( 0, 1 )
	return
MouseLeft:
	Move( -1, 0 )
	return
MouseRight:
	Move( 1, 0 )
	return
MouseLeftUp:
	Move( -1, -1 )
	return
MouseRightUp:
	Move( 1, -1 )
	return
MouseLeftDown:
	Move( -1, 1 )
	return
MouseRightDown:
	Move( 1, 1 )
	return

StopAcceleration:
	repeat = 0
	return

; Using Keyboard Numpad as a Mouse -- by deguix
; http://www.autohotkey.com

;START OF CONFIG SECTION

#SingleInstance force
#MaxHotkeysPerInterval 500

; Using the keyboard hook to implement the Numpad hotkeys prevents
; them from interfering with the generation of ANSI characters such
; as .  This is because AutoHotkey generates such characters
; by holding down ALT and sending a series of Numpad keystrokes.
; Hook hotkeys are smart enough to ignore such keystrokes.
#UseHook

;END OF CONFIG SECTION

;This is needed or key presses would faulty send their natural
;actions. Like NumPadDiv would send sometimes "/" to the
;screen.
#InstallKeybdHook

repeat = 0

SetKeyDelay, -1
SetMouseDelay, -1

SetHotkeys( modifier ) {

	; TODO: refactor

	; KEY DOWN

	; Left hand
	Hotkey, %modifier% & W, MouseLeftUp
	Hotkey, %modifier% & E, MouseUp
	Hotkey, %modifier% & R, MouseRightUp
	Hotkey, %modifier% & S, MouseLeft
	Hotkey, %modifier% & D, MouseDown
	Hotkey, %modifier% & F, MouseRight
	Hotkey, %modifier% & X, MouseLeftDown
	Hotkey, %modifier% & C, MouseDown
	Hotkey, %modifier% & V, MouseRightDown

	; Right hand
	Hotkey, %modifier% & U, MouseLeftUp
	Hotkey, %modifier% & I, MouseUp
	Hotkey, %modifier% & O, MouseRightUp
	Hotkey, %modifier% & J, MouseLeft
	Hotkey, %modifier% & K, MouseDown
	Hotkey, %modifier% & L, MouseRight
	Hotkey, %modifier% & M, MouseLeftDown
	Hotkey, %modifier% & `, , MouseDown
	Hotkey, %modifier% & `. , MouseRightDown

	; Numeric
	Hotkey, %modifier% & 7, MouseLeftUp
	Hotkey, %modifier% & 8, MouseUp
	Hotkey, %modifier% & 9, MouseRightUp
	Hotkey, %modifier% & 4, MouseLeft
	Hotkey, %modifier% & 5, MouseDown
	Hotkey, %modifier% & 6, MouseRight
	Hotkey, %modifier% & 1, MouseLeftDown
	Hotkey, %modifier% & 2, MouseDown
	Hotkey, %modifier% & 3, MouseRightDown

	; Arrows
	Hotkey, %modifier% & Up, MouseUp
	Hotkey, %modifier% & Down, MouseDown
	Hotkey, %modifier% & Left, MouseLeft
	Hotkey, %modifier% & Right, MouseRight

	; KEY UP

	; Left hand
	Hotkey, %modifier% & W UP, StopAcceleration
	Hotkey, %modifier% & E UP, StopAcceleration
	Hotkey, %modifier% & R UP, StopAcceleration
	Hotkey, %modifier% & S UP, StopAcceleration
	Hotkey, %modifier% & D UP, StopAcceleration
	Hotkey, %modifier% & F UP, StopAcceleration
	Hotkey, %modifier% & X UP, StopAcceleration
	Hotkey, %modifier% & C UP, StopAcceleration
	Hotkey, %modifier% & V UP, StopAcceleration

	; Right hand
	Hotkey, %modifier% & U UP, StopAcceleration
	Hotkey, %modifier% & I UP, StopAcceleration
	Hotkey, %modifier% & O UP, StopAcceleration
	Hotkey, %modifier% & J UP, StopAcceleration
	Hotkey, %modifier% & K UP, StopAcceleration
	Hotkey, %modifier% & L UP, StopAcceleration
	Hotkey, %modifier% & M UP, StopAcceleration
	Hotkey, %modifier% & `,  UP, StopAcceleration
	Hotkey, %modifier% & `.  UP, StopAcceleration

	; Numeric
	Hotkey, %modifier% & 7 UP, StopAcceleration
	Hotkey, %modifier% & 8 UP, StopAcceleration
	Hotkey, %modifier% & 9 UP, StopAcceleration
	Hotkey, %modifier% & 4 UP, StopAcceleration
	Hotkey, %modifier% & 5 UP, StopAcceleration
	Hotkey, %modifier% & 6 UP, StopAcceleration
	Hotkey, %modifier% & 1 UP, StopAcceleration
	Hotkey, %modifier% & 2 UP, StopAcceleration
	Hotkey, %modifier% & 3 UP, StopAcceleration

	; Arrows
	Hotkey, %modifier% & Up UP, StopAcceleration
	Hotkey, %modifier% & Down UP, StopAcceleration
	Hotkey, %modifier% & Left UP, StopAcceleration
	Hotkey, %modifier% & Right UP, StopAcceleration
}

SetHotkeys( "CapsLock" )
SetHotkeys( "~LButton" )
SetHotkeys( "~RButton" )
SetHotkeys( "~MButton" )
SetHotkeys( "~XButton1" )
SetHotkeys( "~XButton2" )

return

Move( x, y ) {
	global repeat
	++repeat
	factor := Floor( ( repeat + 1 ) / 2 )
	x := x * factor
	y := y * factor
	MouseMove, x, y, 0, R
}

MouseUp:
	Move( 0, -1 )
	return
MouseDown:
	Move( 0, 1 )
	return
MouseLeft:
	Move( -1, 0 )
	return
MouseRight:
	Move( 1, 0 )
	return
MouseLeftUp:
	Move( -1, -1 )
	return
MouseRightUp:
	Move( 1, -1 )
	return
MouseLeftDown:
	Move( -1, 1 )
	return
MouseRightDown:
	Move( 1, 1 )
	return

StopAcceleration:
	repeat = 0
	return


Make Numpad* go to the editor if the sample isn't open or if tests fail.

; AutoHotKey script for my own development convenience.
; See http://www.autohotkey.com/ to download AutoHotKey (freeware).
;
; This script provides the following keybindings:
;   Numpad -    Opens Git Gui if it's not already running, or switches to the
;               already-running instance and invokes "Rescan".
;   Numpad +    Opens Gitk (All Branch History) if it's not already running,
;               or switches to the running instance and invokes "Update".
;   Numpad *    Runs jake to build the sample project, then:
;               - If an instance of Google Chrome is open to the sample app,
;                 then activate that instance of Chrome and refresh the page;
;               - Otherwise, move focus to Sublime Text 2.
;   Numpad /    Moves focus to the Sublime Text 2 editor currently editing the
;               "Tyler" project.

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, RegEx

NumpadSub::
IfWinNotExist, Git Gui
  Run, git gui,, Hide
WinActivate, Git Gui
IfWinActive, Git Gui
{
  ControlGetPos, control_x, control_y,,, TkChild18, Git Gui
  CoordMode, Mouse, Screen
  MouseGetPos, mouse_x, mouse_y
  click_x := control_x + 5
  click_y := control_y + 5
  CoordMode, Mouse, Relative
  Click %click_x%, %click_y%
  CoordMode, Mouse, Screen
  MouseMove, %mouse_x%, %mouse_y%, 0

  Send, {F5}
}
return

NumpadAdd::
IfWinNotExist, gitk
  Run, cmd /c gitk --all
WinActivate, gitk
IfWinActive, gitk
  Send, {F5}
return

NumpadMult::
RunWait, %comspec% /c cd .. && jake || pause && exit /b 1
if ErrorLevel = 0
{
  WinActivate, Stupid Quest - Google Chrome
  IfWinActive, Stupid Quest - Google Chrome
    Send, {F5}
  else
    Gosub NumpadDiv
}
else
  Gosub NumpadDiv
return

NumpadDiv::
WinActivate, \(Tyler\) - Sublime Text 2
return

; AutoHotKey script for my own development convenience.
; See http://www.autohotkey.com/ to download AutoHotKey (freeware).
;
; This script provides the following keybindings:
;   Numpad -    Opens Git Gui if it's not already running, or switches to the
;               already-running instance and invokes "Rescan".
;   Numpad +    Opens Gitk (All Branch History) if it's not already running,
;               or switches to the running instance and invokes "Update".
;   Numpad *    Runs jake to build the sample project, then moves focus to an
;               existing instance of Google Chrome, switches to tab #4, and
;               invokes "Refresh".
;   Numpad /    Moves focus to the Sublime Text 2 editor currently editing the
;               "Tyler" project.

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, RegEx

NumpadSub::
IfWinNotExist, Git Gui
  Run, git gui,, Hide
WinActivate, Git Gui
IfWinActive, Git Gui
{
  ControlGetPos, control_x, control_y,,, TkChild18, Git Gui
  CoordMode, Mouse, Screen
  MouseGetPos, mouse_x, mouse_y
  click_x := control_x + 5
  click_y := control_y + 5
  CoordMode, Mouse, Relative
  Click %click_x%, %click_y%
  CoordMode, Mouse, Screen
  MouseMove, %mouse_x%, %mouse_y%, 0

  Send, {F5}
}
return

NumpadAdd::
IfWinNotExist, gitk
  Run, cmd /c gitk --all
WinActivate, gitk
IfWinActive, gitk
  Send, {F5}
return

NumpadMult::
RunWait, %comspec% /c cd .. && jake || pause && exit /b 1
if ErrorLevel = 0
{
  WinActivate, Google Chrome
  IfWinActive, Google Chrome
    Send, ^4{F5}
}
return

NumpadDiv::
WinActivate, \(Tyler\) - Sublime Text 2
return


Refactor hotkey setup

Refactor hotkey setup

; Using Keyboard Numpad as a Mouse -- by deguix
; http://www.autohotkey.com

;START OF CONFIG SECTION

#SingleInstance force
#MaxHotkeysPerInterval 500

; Using the keyboard hook to implement the Numpad hotkeys prevents
; them from interfering with the generation of ANSI characters such
; as .  This is because AutoHotkey generates such characters
; by holding down ALT and sending a series of Numpad keystrokes.
; Hook hotkeys are smart enough to ignore such keystrokes.
#UseHook

MouseSpeed = 1
MouseAccelerationSpeed = 1
MouseMaxSpeed = 5

;Mouse wheel speed is also set on Control Panel. As that
;will affect the normal mouse behavior, the real speed of
;these three below are times the normal mouse wheel speed.
MouseWheelSpeed = 1
MouseWheelAccelerationSpeed = 1
MouseWheelMaxSpeed = 5

;END OF CONFIG SECTION

;This is needed or key presses would faulty send their natural
;actions. Like NumPadDiv would send sometimes "/" to the
;screen.
#InstallKeybdHook

Temp = 0
Temp2 = 0

MouseCurrentAccelerationSpeed = 0
MouseCurrentSpeed = %MouseSpeed%

MouseWheelCurrentAccelerationSpeed = 0
MouseWheelCurrentSpeed = %MouseSpeed%

SetKeyDelay, -1
SetMouseDelay, -1

SetHotkeys( modifier ) {
	; Left hand
	Hotkey, %modifier% & W, MouseLeftUp
	Hotkey, %modifier% & E, MouseUp
	Hotkey, %modifier% & R, MouseRightUp
	Hotkey, %modifier% & S, MouseLeft
	Hotkey, %modifier% & D, MouseDown
	Hotkey, %modifier% & F, MouseRight
	Hotkey, %modifier% & X, MouseLeftDown
	Hotkey, %modifier% & C, MouseDown
	Hotkey, %modifier% & V, MouseRightDown

	; Right hand
	Hotkey, %modifier% & U, MouseLeftUp
	Hotkey, %modifier% & I, MouseUp
	Hotkey, %modifier% & O, MouseRightUp
	Hotkey, %modifier% & J, MouseLeft
	Hotkey, %modifier% & K, MouseDown
	Hotkey, %modifier% & L, MouseRight
	Hotkey, %modifier% & M, MouseLeftDown
	Hotkey, %modifier% & `, , MouseDown
	Hotkey, %modifier% & `. , MouseRightDown

	; Numeric
	Hotkey, %modifier% & 7, MouseLeftUp
	Hotkey, %modifier% & 8, MouseUp
	Hotkey, %modifier% & 9, MouseRightUp
	Hotkey, %modifier% & 4, MouseLeft
	Hotkey, %modifier% & 5, MouseDown
	Hotkey, %modifier% & 6, MouseRight
	Hotkey, %modifier% & 1, MouseLeftDown
	Hotkey, %modifier% & 2, MouseDown
	Hotkey, %modifier% & 3, MouseRightDown

	; Arrows
	Hotkey, %modifier% & Up, MouseUp
	Hotkey, %modifier% & Down, MouseDown
	Hotkey, %modifier% & Left, MouseLeft
	Hotkey, %modifier% & Right, MouseRight
}

SetHotkeys( "CapsLock" )
SetHotkeys( "~LButton" )
SetHotkeys( "~RButton" )
SetHotkeys( "~MButton" )
SetHotkeys( "~XButton1" )
SetHotkeys( "~XButton2" )

return

Move( x, y ) {
	MouseMove, x, y, 0, R
}

MouseUp:
	Move( 0, -1 )
	return
MouseDown:
	Move( 0, 1 )
	return
MouseLeft:
	Move( -1, 0 )
	return
MouseRight:
	Move( 1, 0 )
	return
MouseLeftUp:
	Move( -1, -1 )
	return
MouseRightUp:
	Move( 1, -1 )
	return
MouseLeftDown:
	Move( -1, 1 )
	return
MouseRightDown:
	Move( 1, 1 )
	return

If Action <> 0
{
	IfNotInString, A_ThisLabel, %Action%
	{
		MouseCurrentAccelerationSpeed = 0
		MouseCurrentSpeed = %MouseSpeed%
	}
}
StringReplace, Action, A_ThisLabel, *

ButtonAccelerationStart:
If MouseAccelerationSpeed >= 1
{
	If MouseMaxSpeed > %MouseCurrentSpeed%
	{
		Temp = 0.001
		Temp *= %MouseAccelerationSpeed%
		MouseCurrentAccelerationSpeed += %Temp%
		MouseCurrentSpeed += %MouseCurrentAccelerationSpeed%
	}
}

MouseCurrentSpeedToDirection = 1

MouseCurrentSpeedToSide = 0

MouseCurrentSpeedToDirection *= %MouseCurrentSpeed%
MouseCurrentSpeedToSide *= %MouseCurrentSpeed%

Temp = 0

If Action = MouseUp
{
	MouseCurrentSpeedToDirection *= -1
	MouseMove, %MouseCurrentSpeedToSide%, %MouseCurrentSpeedToDirection%, 0, R
}
else if Action = MouseDown
{
	MouseCurrentSpeedToSide *= -1
	MouseMove, %MouseCurrentSpeedToSide%, %MouseCurrentSpeedToDirection%, 0, R
}
else if Action = MouseLeft
{
	MouseCurrentSpeedToSide *= -1
	MouseCurrentSpeedToDirection *= -1

	MouseMove, %MouseCurrentSpeedToDirection%, %MouseCurrentSpeedToSide%, 0, R
}
else if Action = MouseRight
{
	MouseMove, %MouseCurrentSpeedToDirection%, %MouseCurrentSpeedToSide%, 0, R
}
else if Action = MouseLeftUp
{
	Temp = %MouseCurrentSpeedToDirection%
	Temp -= %MouseCurrentSpeedToSide%
	Temp *= -1
	Temp2 = %MouseCurrentSpeedToDirection%
	Temp2 += %MouseCurrentSpeedToSide%
	Temp2 *= -1
	MouseMove, %Temp%, %Temp2%, 0, R
}
else if Action = MouseRightUp
{
	Temp = %MouseCurrentSpeedToDirection%
	Temp += %MouseCurrentSpeedToSide%
	Temp2 = %MouseCurrentSpeedToDirection%
	Temp2 -= %MouseCurrentSpeedToSide%
	Temp2 *= -1
	MouseMove, %Temp%, %Temp2%, 0, R
}
else if Action = MouseLeftDown
{
	Temp = %MouseCurrentSpeedToDirection%
	Temp += %MouseCurrentSpeedToSide%
	Temp *= -1
	Temp2 = %MouseCurrentSpeedToDirection%
	Temp2 -= %MouseCurrentSpeedToSide%
	MouseMove, %Temp%, %Temp2%, 0, R
}
else if Action = MouseRightDown
{
	Temp = %MouseCurrentSpeedToDirection%
	Temp -= %MouseCurrentSpeedToSide%
	Temp2 *= -1
	Temp2 = %MouseCurrentSpeedToDirection%
	Temp2 += %MouseCurrentSpeedToSide%
	MouseMove, %Temp%, %Temp2%, 0, R
}

SetTimer, ButtonAccelerationEnd, 10
return

ButtonAccelerationEnd:
GetKeyState, kstate, %Action%, P
if kstate = D
	Goto ButtonAccelerationStart

SetTimer, ButtonAccelerationEnd, off
MouseCurrentAccelerationSpeed = 0
MouseCurrentSpeed = %MouseSpeed%
Action = 0
return

; Using Keyboard Numpad as a Mouse -- by deguix
; http://www.autohotkey.com

;START OF CONFIG SECTION

#SingleInstance force
#MaxHotkeysPerInterval 500

; Using the keyboard hook to implement the Numpad hotkeys prevents
; them from interfering with the generation of ANSI characters such
; as .  This is because AutoHotkey generates such characters
; by holding down ALT and sending a series of Numpad keystrokes.
; Hook hotkeys are smart enough to ignore such keystrokes.
#UseHook

MouseSpeed = 1
MouseAccelerationSpeed = 1
MouseMaxSpeed = 5

;Mouse wheel speed is also set on Control Panel. As that
;will affect the normal mouse behavior, the real speed of
;these three below are times the normal mouse wheel speed.
MouseWheelSpeed = 1
MouseWheelAccelerationSpeed = 1
MouseWheelMaxSpeed = 5

;END OF CONFIG SECTION

;This is needed or key presses would faulty send their natural
;actions. Like NumPadDiv would send sometimes "/" to the
;screen.
#InstallKeybdHook

Temp = 0
Temp2 = 0

MouseCurrentAccelerationSpeed = 0
MouseCurrentSpeed = %MouseSpeed%

MouseWheelCurrentAccelerationSpeed = 0
MouseWheelCurrentSpeed = %MouseSpeed%

SetKeyDelay, -1
SetMouseDelay, -1

; CAPS LOCK KEYS

; Left hand
Hotkey, CapsLock & W, MouseLeftUp
Hotkey, CapsLock & E, MouseUp
Hotkey, CapsLock & R, MouseRightUp
Hotkey, CapsLock & S, MouseLeft
Hotkey, CapsLock & D, MouseDown
Hotkey, CapsLock & F, MouseRight
Hotkey, CapsLock & X, MouseLeftDown
Hotkey, CapsLock & C, MouseDown
Hotkey, CapsLock & V, MouseRightDown

; Right hand
Hotkey, CapsLock & U, MouseLeftUp
Hotkey, CapsLock & I, MouseUp
Hotkey, CapsLock & O, MouseRightUp
Hotkey, CapsLock & J, MouseLeft
Hotkey, CapsLock & K, MouseDown
Hotkey, CapsLock & L, MouseRight
Hotkey, CapsLock & M, MouseLeftDown
Hotkey, CapsLock & `, , MouseDown
Hotkey, CapsLock & `. , MouseRightDown

; Numeric
Hotkey, CapsLock & 7, MouseLeftUp
Hotkey, CapsLock & 8, MouseUp
Hotkey, CapsLock & 9, MouseRightUp
Hotkey, CapsLock & 4, MouseLeft
Hotkey, CapsLock & 5, MouseDown
Hotkey, CapsLock & 6, MouseRight
Hotkey, CapsLock & 1, MouseLeftDown
Hotkey, CapsLock & 2, MouseDown
Hotkey, CapsLock & 3, MouseRightDown

; Arrows
Hotkey, CapsLock & Up, MouseUp
Hotkey, CapsLock & Down, MouseDown
Hotkey, CapsLock & Left, MouseLeft
Hotkey, CapsLock & Right, MouseRight

; LEFT BUTTON KEYS

; Left hand
Hotkey, ~LButton & W, MouseLeftUp
Hotkey, ~LButton & E, MouseUp
Hotkey, ~LButton & R, MouseRightUp
Hotkey, ~LButton & S, MouseLeft
Hotkey, ~LButton & D, MouseDown
Hotkey, ~LButton & F, MouseRight
Hotkey, ~LButton & X, MouseLeftDown
Hotkey, ~LButton & C, MouseDown
Hotkey, ~LButton & V, MouseRightDown

; Right hand
Hotkey, ~LButton & U, MouseLeftUp
Hotkey, ~LButton & I, MouseUp
Hotkey, ~LButton & O, MouseRightUp
Hotkey, ~LButton & J, MouseLeft
Hotkey, ~LButton & K, MouseDown
Hotkey, ~LButton & L, MouseRight
Hotkey, ~LButton & M, MouseLeftDown
Hotkey, ~LButton & `, , MouseDown
Hotkey, ~LButton & `. , MouseRightDown

; Numeric
Hotkey, ~LButton & 7, MouseLeftUp
Hotkey, ~LButton & 8, MouseUp
Hotkey, ~LButton & 9, MouseRightUp
Hotkey, ~LButton & 4, MouseLeft
Hotkey, ~LButton & 5, MouseDown
Hotkey, ~LButton & 6, MouseRight
Hotkey, ~LButton & 1, MouseLeftDown
Hotkey, ~LButton & 2, MouseDown
Hotkey, ~LButton & 3, MouseRightDown

; Arrows
Hotkey, ~LButton & Up, MouseUp
Hotkey, ~LButton & Down, MouseDown
Hotkey, ~LButton & Left, MouseLeft
Hotkey, ~LButton & Right, MouseRight

; RIGHT BUTTON KEYS

; Left hand
Hotkey, ~RButton & W, MouseLeftUp
Hotkey, ~RButton & E, MouseUp
Hotkey, ~RButton & R, MouseRightUp
Hotkey, ~RButton & S, MouseLeft
Hotkey, ~RButton & D, MouseDown
Hotkey, ~RButton & F, MouseRight
Hotkey, ~RButton & X, MouseLeftDown
Hotkey, ~RButton & C, MouseDown
Hotkey, ~RButton & V, MouseRightDown

; Right hand
Hotkey, ~RButton & U, MouseLeftUp
Hotkey, ~RButton & I, MouseUp
Hotkey, ~RButton & O, MouseRightUp
Hotkey, ~RButton & J, MouseLeft
Hotkey, ~RButton & K, MouseDown
Hotkey, ~RButton & L, MouseRight
Hotkey, ~RButton & M, MouseLeftDown
Hotkey, ~RButton & `, , MouseDown
Hotkey, ~RButton & `. , MouseRightDown

; Numeric
Hotkey, ~RButton & 7, MouseLeftUp
Hotkey, ~RButton & 8, MouseUp
Hotkey, ~RButton & 9, MouseRightUp
Hotkey, ~RButton & 4, MouseLeft
Hotkey, ~RButton & 5, MouseDown
Hotkey, ~RButton & 6, MouseRight
Hotkey, ~RButton & 1, MouseLeftDown
Hotkey, ~RButton & 2, MouseDown
Hotkey, ~RButton & 3, MouseRightDown

; Arrows
Hotkey, ~RButton & Up, MouseUp
Hotkey, ~RButton & Down, MouseDown
Hotkey, ~RButton & Left, MouseLeft
Hotkey, ~RButton & Right, MouseRight

; MIDDLE BUTTON KEYS

; Left hand
Hotkey, ~MButton & W, MouseLeftUp
Hotkey, ~MButton & E, MouseUp
Hotkey, ~MButton & R, MouseRightUp
Hotkey, ~MButton & S, MouseLeft
Hotkey, ~MButton & D, MouseDown
Hotkey, ~MButton & F, MouseRight
Hotkey, ~MButton & X, MouseLeftDown
Hotkey, ~MButton & C, MouseDown
Hotkey, ~MButton & V, MouseRightDown

; Right hand
Hotkey, ~MButton & U, MouseLeftUp
Hotkey, ~MButton & I, MouseUp
Hotkey, ~MButton & O, MouseRightUp
Hotkey, ~MButton & J, MouseLeft
Hotkey, ~MButton & K, MouseDown
Hotkey, ~MButton & L, MouseRight
Hotkey, ~MButton & M, MouseLeftDown
Hotkey, ~MButton & `, , MouseDown
Hotkey, ~MButton & `. , MouseRightDown

; Numeric
Hotkey, ~MButton & 7, MouseLeftUp
Hotkey, ~MButton & 8, MouseUp
Hotkey, ~MButton & 9, MouseRightUp
Hotkey, ~MButton & 4, MouseLeft
Hotkey, ~MButton & 5, MouseDown
Hotkey, ~MButton & 6, MouseRight
Hotkey, ~MButton & 1, MouseLeftDown
Hotkey, ~MButton & 2, MouseDown
Hotkey, ~MButton & 3, MouseRightDown

; Arrows
Hotkey, ~MButton & Up, MouseUp
Hotkey, ~MButton & Down, MouseDown
Hotkey, ~MButton & Left, MouseLeft
Hotkey, ~MButton & Right, MouseRight

; EXTRA BUTTON 1 KEYS

; Left hand
Hotkey, ~XButton1 & W, MouseLeftUp
Hotkey, ~XButton1 & E, MouseUp
Hotkey, ~XButton1 & R, MouseRightUp
Hotkey, ~XButton1 & S, MouseLeft
Hotkey, ~XButton1 & D, MouseDown
Hotkey, ~XButton1 & F, MouseRight
Hotkey, ~XButton1 & X, MouseLeftDown
Hotkey, ~XButton1 & C, MouseDown
Hotkey, ~XButton1 & V, MouseRightDown

; Right hand
Hotkey, ~XButton1 & U, MouseLeftUp
Hotkey, ~XButton1 & I, MouseUp
Hotkey, ~XButton1 & O, MouseRightUp
Hotkey, ~XButton1 & J, MouseLeft
Hotkey, ~XButton1 & K, MouseDown
Hotkey, ~XButton1 & L, MouseRight
Hotkey, ~XButton1 & M, MouseLeftDown
Hotkey, ~XButton1 & `, , MouseDown
Hotkey, ~XButton1 & `. , MouseRightDown

; Numeric
Hotkey, ~XButton1 & 7, MouseLeftUp
Hotkey, ~XButton1 & 8, MouseUp
Hotkey, ~XButton1 & 9, MouseRightUp
Hotkey, ~XButton1 & 4, MouseLeft
Hotkey, ~XButton1 & 5, MouseDown
Hotkey, ~XButton1 & 6, MouseRight
Hotkey, ~XButton1 & 1, MouseLeftDown
Hotkey, ~XButton1 & 2, MouseDown
Hotkey, ~XButton1 & 3, MouseRightDown

; Arrows
Hotkey, ~XButton1 & Up, MouseUp
Hotkey, ~XButton1 & Down, MouseDown
Hotkey, ~XButton1 & Left, MouseLeft
Hotkey, ~XButton1 & Right, MouseRight

; EXTRA BUTTON 2 KEYS

; Left hand
Hotkey, ~XButton2 & W, MouseLeftUp
Hotkey, ~XButton2 & E, MouseUp
Hotkey, ~XButton2 & R, MouseRightUp
Hotkey, ~XButton2 & S, MouseLeft
Hotkey, ~XButton2 & D, MouseDown
Hotkey, ~XButton2 & F, MouseRight
Hotkey, ~XButton2 & X, MouseLeftDown
Hotkey, ~XButton2 & C, MouseDown
Hotkey, ~XButton2 & V, MouseRightDown

; Right hand
Hotkey, ~XButton2 & U, MouseLeftUp
Hotkey, ~XButton2 & I, MouseUp
Hotkey, ~XButton2 & O, MouseRightUp
Hotkey, ~XButton2 & J, MouseLeft
Hotkey, ~XButton2 & K, MouseDown
Hotkey, ~XButton2 & L, MouseRight
Hotkey, ~XButton2 & M, MouseLeftDown
Hotkey, ~XButton2 & `, , MouseDown
Hotkey, ~XButton2 & `. , MouseRightDown

; Numeric
Hotkey, ~XButton2 & 7, MouseLeftUp
Hotkey, ~XButton2 & 8, MouseUp
Hotkey, ~XButton2 & 9, MouseRightUp
Hotkey, ~XButton2 & 4, MouseLeft
Hotkey, ~XButton2 & 5, MouseDown
Hotkey, ~XButton2 & 6, MouseRight
Hotkey, ~XButton2 & 1, MouseLeftDown
Hotkey, ~XButton2 & 2, MouseDown
Hotkey, ~XButton2 & 3, MouseRightDown

; Arrows
Hotkey, ~XButton2 & Up, MouseUp
Hotkey, ~XButton2 & Down, MouseDown
Hotkey, ~XButton2 & Left, MouseLeft
Hotkey, ~XButton2 & Right, MouseRight

return

Move( x, y ) {
	MouseMove, x, y, 0, R
}

MouseUp:
	Move( 0, -1 )
	return
MouseDown:
	Move( 0, 1 )
	return
MouseLeft:
	Move( -1, 0 )
	return
MouseRight:
	Move( 1, 0 )
	return
MouseLeftUp:
	Move( -1, -1 )
	return
MouseRightUp:
	Move( 1, -1 )
	return
MouseLeftDown:
	Move( -1, 1 )
	return
MouseRightDown:
	Move( 1, 1 )
	return

If Action <> 0
{
	IfNotInString, A_ThisLabel, %Action%
	{
		MouseCurrentAccelerationSpeed = 0
		MouseCurrentSpeed = %MouseSpeed%
	}
}
StringReplace, Action, A_ThisLabel, *

ButtonAccelerationStart:
If MouseAccelerationSpeed >= 1
{
	If MouseMaxSpeed > %MouseCurrentSpeed%
	{
		Temp = 0.001
		Temp *= %MouseAccelerationSpeed%
		MouseCurrentAccelerationSpeed += %Temp%
		MouseCurrentSpeed += %MouseCurrentAccelerationSpeed%
	}
}

MouseCurrentSpeedToDirection = 1

MouseCurrentSpeedToSide = 0

MouseCurrentSpeedToDirection *= %MouseCurrentSpeed%
MouseCurrentSpeedToSide *= %MouseCurrentSpeed%

Temp = 0

If Action = MouseUp
{
	MouseCurrentSpeedToDirection *= -1
	MouseMove, %MouseCurrentSpeedToSide%, %MouseCurrentSpeedToDirection%, 0, R
}
else if Action = MouseDown
{
	MouseCurrentSpeedToSide *= -1
	MouseMove, %MouseCurrentSpeedToSide%, %MouseCurrentSpeedToDirection%, 0, R
}
else if Action = MouseLeft
{
	MouseCurrentSpeedToSide *= -1
	MouseCurrentSpeedToDirection *= -1

	MouseMove, %MouseCurrentSpeedToDirection%, %MouseCurrentSpeedToSide%, 0, R
}
else if Action = MouseRight
{
	MouseMove, %MouseCurrentSpeedToDirection%, %MouseCurrentSpeedToSide%, 0, R
}
else if Action = MouseLeftUp
{
	Temp = %MouseCurrentSpeedToDirection%
	Temp -= %MouseCurrentSpeedToSide%
	Temp *= -1
	Temp2 = %MouseCurrentSpeedToDirection%
	Temp2 += %MouseCurrentSpeedToSide%
	Temp2 *= -1
	MouseMove, %Temp%, %Temp2%, 0, R
}
else if Action = MouseRightUp
{
	Temp = %MouseCurrentSpeedToDirection%
	Temp += %MouseCurrentSpeedToSide%
	Temp2 = %MouseCurrentSpeedToDirection%
	Temp2 -= %MouseCurrentSpeedToSide%
	Temp2 *= -1
	MouseMove, %Temp%, %Temp2%, 0, R
}
else if Action = MouseLeftDown
{
	Temp = %MouseCurrentSpeedToDirection%
	Temp += %MouseCurrentSpeedToSide%
	Temp *= -1
	Temp2 = %MouseCurrentSpeedToDirection%
	Temp2 -= %MouseCurrentSpeedToSide%
	MouseMove, %Temp%, %Temp2%, 0, R
}
else if Action = MouseRightDown
{
	Temp = %MouseCurrentSpeedToDirection%
	Temp -= %MouseCurrentSpeedToSide%
	Temp2 *= -1
	Temp2 = %MouseCurrentSpeedToDirection%
	Temp2 += %MouseCurrentSpeedToSide%
	MouseMove, %Temp%, %Temp2%, 0, R
}

SetTimer, ButtonAccelerationEnd, 10
return

ButtonAccelerationEnd:
GetKeyState, kstate, %Action%, P
if kstate = D
	Goto ButtonAccelerationStart

SetTimer, ButtonAccelerationEnd, off
MouseCurrentAccelerationSpeed = 0
MouseCurrentSpeed = %MouseSpeed%
Action = 0
return


single instance force

single instance force

; win: #, ctrl: ^, alt: !, shift: +
;#SingleInstance ignore
#SingleInstance force
; test code
;Msgbox hello

#z::
!z::
+z::
temp_txt = %home%\selected_word.txt
tempClipboard = %ClipboardAll%
Clipboard =
Send, ^c
ClipWait, 1
FileDelete, %temp_txt%
if (Clipboard != "") {
    FileAppend, %Clipboard%, %temp_txt%
}
Clipboard = %tempClipboard%  ; ClipboardAll no allowed as an output variable
tempClipboard =
return

; win: #, ctrl: ^, alt: !, shift: +
#z::
!z::
+z::
temp_txt = %home%\selected_word.txt
tempClipboard = %ClipboardAll%
Clipboard =
Send, ^c
ClipWait, 1
FileDelete, %temp_txt%
if (Clipboard != "") {
    FileAppend, %Clipboard%, %temp_txt%
}
Clipboard = %tempClipboard%  ; ClipboardAll no allowed as an output variable
tempClipboard =
return


Fix comma and period

Fix comma and period

; JKLmouse for AutoHotkey by Michael Geary
; http://www.jklmouse.com/ - documentation
; http://unlicense.org/ - public domain statement
; Version 0.1: 11/3/2011

#SingleInstance force

SetKeyDelay, -1
SetMouseDelay, -1

repeat = 0

SetKey( mod, key, action ) {
	keydown = %mod% & %key%
	Hotkey %keydown%, %action%
	Hotkey %keydown% UP, StopAcceleration
}

SetKeys( mod ) {

	; Left hand
	SetKey( mod, "W", "MouseLeftUp" )
	SetKey( mod, "E", "MouseUp" )
	SetKey( mod, "R", "MouseRightUp" )
	SetKey( mod, "S", "MouseLeft" )
	SetKey( mod, "D", "MouseDown" )
	SetKey( mod, "F", "MouseRight" )
	SetKey( mod, "X", "MouseLeftDown" )
	SetKey( mod, "C", "MouseDown" )
	SetKey( mod, "V", "MouseRightDown" )

	; Right hand
	SetKey( mod, "U", "MouseLeftUp" )
	SetKey( mod, "I", "MouseUp" )
	SetKey( mod, "O", "MouseRightUp" )
	SetKey( mod, "J", "MouseLeft" )
	SetKey( mod, "K", "MouseDown" )
	SetKey( mod, "L", "MouseRight" )
	SetKey( mod, "M", "MouseLeftDown" )
	SetKey( mod, "`,","MouseDown" )
	SetKey( mod, "`.","MouseRightDown" )

	; Numeric
	SetKey( mod, "7", "MouseLeftUp" )
	SetKey( mod, "8", "MouseUp" )
	SetKey( mod, "9", "MouseRightUp" )
	SetKey( mod, "4", "MouseLeft" )
	SetKey( mod, "5", "MouseDown" )
	SetKey( mod, "6", "MouseRight" )
	SetKey( mod, "1", "MouseLeftDown" )
	SetKey( mod, "2", "MouseDown" )
	SetKey( mod, "3", "MouseRightDown" )

	; Arrows
	SetKey( mod, "Up", "MouseUp" )
	SetKey( mod, "Down", "MouseDown" )
	SetKey( mod, "Left", "MouseLeft" )
	SetKey( mod, "Right", "MouseRight" )

}

SetKeys( "CapsLock" )
SetKeys( "~LButton" )
SetKeys( "~RButton" )
SetKeys( "~MButton" )
SetKeys( "~XButton1" )
SetKeys( "~XButton2" )

return

Move( x, y ) {
	global repeat
	++repeat
	factor := Floor( ( repeat + 1 ) / 2 )
	x := x * factor
	y := y * factor
	MouseMove, x, y, 0, R
}

MouseUp:
	Move( 0, -1 )
	return
MouseDown:
	Move( 0, 1 )
	return
MouseLeft:
	Move( -1, 0 )
	return
MouseRight:
	Move( 1, 0 )
	return
MouseLeftUp:
	Move( -1, -1 )
	return
MouseRightUp:
	Move( 1, -1 )
	return
MouseLeftDown:
	Move( -1, 1 )
	return
MouseRightDown:
	Move( 1, 1 )
	return

StopAcceleration:
	repeat = 0
	return

; JKLmouse for AutoHotkey by Michael Geary
; http://www.jklmouse.com/ - documentation
; http://unlicense.org/ - public domain statement
; Version 0.1: 11/3/2011

#SingleInstance force

SetKeyDelay, -1
SetMouseDelay, -1

repeat = 0

SetKey( mod, key, action ) {
	keydown = %mod% & %key%
	Hotkey %keydown%, %action%
	Hotkey %keydown% UP, StopAcceleration
}

SetKeys( mod ) {

	; Left hand
	SetKey( mod, "W", "MouseLeftUp" )
	SetKey( mod, "E", "MouseUp" )
	SetKey( mod, "R", "MouseRightUp" )
	SetKey( mod, "S", "MouseLeft" )
	SetKey( mod, "D", "MouseDown" )
	SetKey( mod, "F", "MouseRight" )
	SetKey( mod, "X", "MouseLeftDown" )
	SetKey( mod, "C", "MouseDown" )
	SetKey( mod, "V", "MouseRightDown" )

	; Right hand
	SetKey( mod, "U", "MouseLeftUp" )
	SetKey( mod, "I", "MouseUp" )
	SetKey( mod, "O", "MouseRightUp" )
	SetKey( mod, "J", "MouseLeft" )
	SetKey( mod, "K", "MouseDown" )
	SetKey( mod, "L", "MouseRight" )
	SetKey( mod, "M", "MouseLeftDown" )
;	SetKey( mod", "`, "," MoveDown )
;	SetKey( mod", "`. "," MoveRightDown )

	; Numeric
	SetKey( mod, "7", "MouseLeftUp" )
	SetKey( mod, "8", "MouseUp" )
	SetKey( mod, "9", "MouseRightUp" )
	SetKey( mod, "4", "MouseLeft" )
	SetKey( mod, "5", "MouseDown" )
	SetKey( mod, "6", "MouseRight" )
	SetKey( mod, "1", "MouseLeftDown" )
	SetKey( mod, "2", "MouseDown" )
	SetKey( mod, "3", "MouseRightDown" )

	; Arrows
	SetKey( mod, "Up", "MouseUp" )
	SetKey( mod, "Down", "MouseDown" )
	SetKey( mod, "Left", "MouseLeft" )
	SetKey( mod, "Right", "MouseRight" )

}

SetKeys( "CapsLock" )
SetKeys( "~LButton" )
SetKeys( "~RButton" )
SetKeys( "~MButton" )
SetKeys( "~XButton1" )
SetKeys( "~XButton2" )

return

Move( x, y ) {
	global repeat
	++repeat
	factor := Floor( ( repeat + 1 ) / 2 )
	x := x * factor
	y := y * factor
	MouseMove, x, y, 0, R
}

MouseUp:
	Move( 0, -1 )
	return
MouseDown:
	Move( 0, 1 )
	return
MouseLeft:
	Move( -1, 0 )
	return
MouseRight:
	Move( 1, 0 )
	return
MouseLeftUp:
	Move( -1, -1 )
	return
MouseRightUp:
	Move( 1, -1 )
	return
MouseLeftDown:
	Move( -1, 1 )
	return
MouseRightDown:
	Move( 1, 1 )
	return

StopAcceleration:
	repeat = 0
	return


fix bug in Rgui.ahk

fix bug in Rgui.ahk

; save current window ID to return here later
WinGet stID, ID, A

WinGet, RprocID, ID, ahk_class Rgui
if (RprocID == "")
{
    WinGet, RprocID, ID, ahk_class Rgui Workspace
}

if (RprocID == "")
{
    Rguiexe = %1%
    if (Rguiexe = 1) {
        RegRead, Rhome, HKEY_LOCAL_MACHINE,SOFTWARE\R-core\R, InstallPath
        Rguiexe := Rhome . "\bin\x64\Rgui.exe"
    }
    else if (Rguiexe = 0){
        RegRead, Rhome, HKEY_LOCAL_MACHINE,SOFTWARE\R-core\R, InstallPath
        Rguiexe := Rhome . "\bin\i386\Rgui.exe"
    }
    else if 0=0
    {
        ; debug
        RegRead, Rhome, HKEY_LOCAL_MACHINE,SOFTWARE\R-core\R, InstallPath
        Rguiexe := Rhome . "\bin\i386\Rgui.exe"
    }
    OutputDebug Rhome from registry is %Rhome%
    Outputdebug % dstring . "R not found"

    run %Rguiexe% --sdi
    WinWait ,ahk_class Rgui,, 2
    WinGet RprocID, ID, ahk_class Rgui
}

Outputdebug % dstring . "RprocID=" . RprocID

oldclipboard = %clipboard%

if 0=2
{
    cmd = %2%
    cmd := RegExReplace(cmd, "^\n", "")
    newline = `n
    clipboard := cmd . newline
}
else {
    ; for debug
    clipboard = proc.time()`n
}
WinMenuSelectItem ahk_id %RprocID%,,2&,2& ;edit->paste
WinActivate ahk_id %stID%
clipboard := oldclipboard

; save current window ID to return here later
WinGet stID, ID, A

WinGet, RprocID, ID, ahk_class Rgui
if (RprocID == "")
{
    WinGet, RprocID, ID, ahk_class Rgui Workspace
}

if (RprocID == "")
{
    Rguiexe = %1%
    if (Rguiexe = 1) {
        RegRead, Rhome, HKEY_LOCAL_MACHINE,SOFTWARE\R-core\R, InstallPath
        Rguiexe := Rhome . "\bin\x64\Rgui.exe"
    }
    else if (Rguiexe = 0){
        RegRead, Rhome, HKEY_LOCAL_MACHINE,SOFTWARE\R-core\R, InstallPath
        Rguiexe := Rhome . "\bin\i386\Rgui.exe"
    }
    else if (0=0)
    {
        ; debug
        RegRead, Rhome, HKEY_LOCAL_MACHINE,SOFTWARE\R-core\R, InstallPath
        Rguiexe := Rhome . "\bin\i386\Rgui.exe"
    }
    OutputDebug Rhome from registry is %Rhome%
    Outputdebug % dstring . "R not found"

    run %Rguiexe% --sdi
    WinWait ,ahk_class Rgui,, 2
    WinGet RprocID, ID, ahk_class Rgui
}

Outputdebug % dstring . "RprocID=" . RprocID

oldclipboard = %clipboard%

if 0=2
{
    cmd = %2%
    cmd := RegExReplace(cmd, "^\n", "")
    newline = `n
    clipboard := cmd . newline
}
else {
    ; for debug
    clipboard = proc.time()`n
}
WinMenuSelectItem ahk_id %RprocID%,,2&,2& ;edit->paste
WinActivate ahk_id %stID%
clipboard := oldclipboard


EmptyRecycle 清空回收站功能，按取消则管理回收站中文件

EmptyRecycle 清空回收站功能，按取消则管理回收站中文件

; RunZ:System
; 操作系统相关功能

System:
    @("Clip", "显示剪切板内容")
    @("ClearClipboardFormat", "清除剪切板中文字的格式")
    @("EmptyRecycle", "清空回收站")
    @("Logoff", "注销 登出")
    @("RestartMachine", "重启")
    @("ShutdownMachine", "关机")
    @("SuspendMachine", "挂起 睡眠 待机")
    @("HibernateMachine", "休眠")
    @("TurnMonitorOff", "关闭显示器")
    @("ListProcess", "列出进程 ps")
    @("DiskSpace", "查看磁盘空间 df")
    @("IncreaseVolume", "提高音量")
    @("DecreaseVolume", "降低音量")
    @("SystemState", "系统状态 top")
    @("KillProcess", "杀死进程")
    @("SendToClip", "发送到剪切板")
    @("ListWindow", "窗口列表")
    @("ActivateWindow", "激活窗口")
    @("ListRunningService", "列出运行的服务")
    @("ListAllService", "列出所有的服务")
    @("ShowService", "显示服务详情")
    @("ShowProcess", "显示进程详情")
return

Clip:
    GoSub, ActivateRunZ
    DisplayResult("剪切板内容长度 " . StrLen(clipboard) . " ：`n`n" . clipboard)
return

ClearClipboardFormat:
    clipboard := clipboard
return

Logoff:
    MsgBox, 4, , 将要注销，是否执行？
    IfMsgBox Yes
    {
        Shutdown, 0
    }
return

ShutdownMachine:
    MsgBox, 4, , 将要关机，是否执行？
    IfMsgBox Yes
    {
        Shutdown, 1
    }
return

RestartMachine:
    MsgBox, 4, , 将要重启机器，是否执行？
    IfMsgBox Yes
    {
        Shutdown, 2
    }
return

HibernateMachine:
    MsgBox, 4, , 将要休眠，是否执行？
    IfMsgBox Yes
    {
        ; 参数 #1: 使用 1 代替 0 来进行休眠而不是挂起。
        ; 参数 #2: 使用 1 代替 0 来立即挂起而不询问每个应用程序以获得许可。
        ; 参数 #3: 使用 1 而不是 0 来禁止所有的唤醒事件。
        DllCall("PowrProf\SetSuspendState", "int", 1, "int", 0, "int", 0)
    }
return

SuspendMachine:
    MsgBox, 4, , 将要待机，是否执行？
    IfMsgBox Yes
    {
        DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)
    }
return

TurnMonitorOff:
    ; 关闭显示器:
    Sleep, 200
    SendMessage, 0x112, 0xF170, 2, , Program Manager
    ; 0x112 is WM_SYSCOMMAND, 0xF170 is SC_MONITORPOWER.
    ; 对上面命令的注释: 使用 -1 代替 2 来打开显示器.
    ; 使用 1 代替 2 来激活显示器的节能模式.
return

EmptyRecycle:
    Text := "回收站中内容（取消可以管理回收站文件）：`n`n"
    For F in ComObjCreate("Shell.Application").Namespace(10).Items()
        Text .= F.Name . " （" . (F.IsFolder == 0 ? F.Size . " 字节）" : "目录）") . "`n"

    MsgBox, 3, , % Text . "`n将要清空回收站，是否执行？"

    IfMsgBox Yes
    {
        FileRecycleEmpty
        return
    }

    IfMsgBox Cancel
    {
        Run, explorer.exe ::{645ff040-5081-101b-9f08-00aa002f954e}
    }
return

ListProcess:
    result := ""

    for process in ComObjGet("winmgmts:").ExecQuery("select * from Win32_Process")
    {
        result .= "* | 进程 | " process.Name " | " process.CommandLine "`n"
    }
    Sort, result

    SetCommandFilter("KillProcess|ShowProcess|CountNumber")
    DisplayResult(FilterResult(AlignText(result), Arg))
    TurnOnResultFilter()
return

DiskSpace:
    result := ""

    DriveGet, list, list
    Loop, Parse, list
    {
        drive := A_LoopField ":"
        DriveGet, label, label, %drive%
        DriveGet, cap, capacity, %drive%
        DrivespaceFree, free, %drive%
        SetFormat, float, 5.2
        percent := 100 * (cap - free) / cap
        SetFormat, float, 6.2
        cap /= 1024.0
        free /= 1024.0
        result = %result%* | %drive% | 总共: %cap% G  可用: %free% G | 已使用：%percent%`%  卷标: %label%`n
    }

    DisplayResult(AlignText(result))
return

IncreaseVolume:
    SoundSet, +5
return

DecreaseVolume:
    SoundSet, -5
return

SystemState:
    if (!SetExecInterval(1))
    {
        return
    }

    GMSEx := GlobalMemoryStatusEx()
    result := "* | 状态 | 运行时间 | " Round(A_TickCount / 1000 / 3600, 3) " 小时`n"
    result .= "* | 状态 | CPU 占用 | " CPULoad() "% `n"
    result .= "* | 状态 | 内存占用 | " Round(100 * (GMSEx[2] - GMSEx[3]) / GMSEx[2], 2) "% `n"
    result .= "* | 状态 | 进程总数 | " GetProcessCount() "`n"
    result .= "* | 状态 | 内存总量 | " Round(GMSEx[2] / 1024**2, 2) "MB `n"
    result .= "* | 状态 | 可用内存 | " Round(GMSEx[3] / 1024**2, 2) "MB `n"
    DisplayResult(AlignText(result))
return

KillProcess:
    args := StrSplit(Arg, " ")
    for index, argument in args
    {
        Process, Close, %argument%
    }

    DisplayResult("已尝试杀死 " Arg " 进程")
return

SendToClip:
    clipboard := Arg
    GoSub, Clip
return

ListWindow:
    result := ""

    WinGet, id, list, , , Program Manager
    Loop, %id%
    {
        thisId := id%A_Index%
        WinGetTitle, title, ahk_id %thisId%
        WinGet, name, ProcessName, ahk_id %thisId%
        if (title == "")
        {
            continue
        }
        result .= "* | 窗口 | " name " | " title "`n"
    }

    SetCommandFilter("ActivateWindow|KillProcess")
    DisplayResult(AlignText(result))
    TurnOnResultFilter()
return

ActivateWindow:
    DisplayResult()
    ClearInput()

    if (FullPipeArg != "")
    {
        Loop, Parse, FullPipeArg, `n, `r
        {
            if (A_LoopField == "")
            {
                return
            }
            splitedLine := StrSplit(A_LoopField, " | ")
            WinActivate, % Trim(splitedLine[4])
        }
    }
    else
    {
        for index, argument in StrSplit(Arg, " ")
        {
            WinActivate, ahk_exe %argument%
        }
    }
return

ListAllService:
    result :=
    for service in ComObjGet("winmgmts:").ExecQuery("select * from Win32_Service")
    {
        result .= "* | 服务 | " service.Name " | " service.DisplayName "`n"
    }
    Sort, result

    SetCommandFilter("CountNumber|ShowService")
    DisplayResult(FilterResult(AlignText(result), Arg))
    TurnOnResultFilter()
return

ListRunningService:
    result :=
    for service in ComObjGet("winmgmts:").ExecQuery("select * from Win32_Service")
    {
        if (service.Started != 0)
        {
            result .= "* | 服务 | " service.Name " | " service.DisplayName "`n"
        }
    }
    Sort, result

    SetCommandFilter("CountNumber|ShowService")
    DisplayResult(FilterResult(AlignText(result), Arg))
    TurnOnResultFilter()
return

ShowService:
    result :=
    ; 暂时只支持一个，选得多了查起来太慢
    for service in ComObjGet("winmgmts:")
        .ExecQuery("select * from Win32_Service where Name = '" StrSplit(Arg, " ")[1] "'")
    {
        ; https://msdn.microsoft.com/en-us/library/windows/desktop/aa394418%28v=vs.85%29.aspx
        result .= "* | 服务 | 名称 | " service.Name "`n"
        result .= "* | 服务 | 描述 | " service.Description "`n"
        result .= "* | 服务 | 是否在运行 | " service.Started "`n"
        result .= "* | 服务 | 路径 | " service.PathName "`n"
        result .= "* | 服务 | 进程 ID | " service.ProcessId "`n"
        result .= "* | 服务 | 类型 | " service.ServiceType "`n"
        break
    }

    DisplayResult(AlignText(result))
return

ShowProcess:
    result :=
    ; 暂时只支持一个，选得多了查起来太慢
    for process in ComObjGet("winmgmts:")
        .ExecQuery("select * from Win32_Process where Name = '" StrSplit(Arg, " ")[1] "'")
    {
        ; https://msdn.microsoft.com/en-us/library/windows/desktop/aa394372%28v=vs.85%29.aspx
        result .= "* | 服务 | 名称 | " process.Name "`n"
        result .= "* | 服务 | 描述 | " process.Description "`n"
        result .= "* | 服务 | 命令行 | " process.CommandLine "`n"
        result .= "* | 服务 | 启动时间 | " process.CreationDate "`n"
        result .= "* | 服务 | ID | " process.ProcessId "`n"
        break
    }

    DisplayResult(AlignText(result))
return

; RunZ:System
; 操作系统相关功能

System:
    @("Clip", "显示剪切板内容")
    @("ClearClipboardFormat", "清除剪切板中文字的格式")
    @("EmptyRecycle", "清空回收站")
    @("Logoff", "注销 登出")
    @("RestartMachine", "重启")
    @("ShutdownMachine", "关机")
    @("SuspendMachine", "挂起 睡眠 待机")
    @("HibernateMachine", "休眠")
    @("TurnMonitorOff", "关闭显示器")
    @("ListProcess", "列出进程 ps")
    @("DiskSpace", "查看磁盘空间 df")
    @("IncreaseVolume", "提高音量")
    @("DecreaseVolume", "降低音量")
    @("SystemState", "系统状态 top")
    @("KillProcess", "杀死进程")
    @("SendToClip", "发送到剪切板")
    @("ListWindow", "窗口列表")
    @("ActivateWindow", "激活窗口")
    @("ListRunningService", "列出运行的服务")
    @("ListAllService", "列出所有的服务")
    @("ShowService", "显示服务详情")
    @("ShowProcess", "显示进程详情")
return

Clip:
    GoSub, ActivateRunZ
    DisplayResult("剪切板内容长度 " . StrLen(clipboard) . " ：`n`n" . clipboard)
return

ClearClipboardFormat:
    clipboard := clipboard
return

Logoff:
    MsgBox, 4, , 将要注销，是否执行？
    IfMsgBox Yes
    {
        Shutdown, 0
    }
return

ShutdownMachine:
    MsgBox, 4, , 将要关机，是否执行？
    IfMsgBox Yes
    {
        Shutdown, 1
    }
return

RestartMachine:
    MsgBox, 4, , 将要重启机器，是否执行？
    IfMsgBox Yes
    {
        Shutdown, 2
    }
return

HibernateMachine:
    MsgBox, 4, , 将要休眠，是否执行？
    IfMsgBox Yes
    {
        ; 参数 #1: 使用 1 代替 0 来进行休眠而不是挂起。
        ; 参数 #2: 使用 1 代替 0 来立即挂起而不询问每个应用程序以获得许可。
        ; 参数 #3: 使用 1 而不是 0 来禁止所有的唤醒事件。
        DllCall("PowrProf\SetSuspendState", "int", 1, "int", 0, "int", 0)
    }
return

SuspendMachine:
    MsgBox, 4, , 将要待机，是否执行？
    IfMsgBox Yes
    {
        DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)
    }
return

TurnMonitorOff:
    ; 关闭显示器:
    Sleep, 200
    SendMessage, 0x112, 0xF170, 2, , Program Manager
    ; 0x112 is WM_SYSCOMMAND, 0xF170 is SC_MONITORPOWER.
    ; 对上面命令的注释: 使用 -1 代替 2 来打开显示器.
    ; 使用 1 代替 2 来激活显示器的节能模式.
return

EmptyRecycle:
    Text := "回收站中内容：`n`n"
    For F in ComObjCreate("Shell.Application").Namespace(10).Items()
        Text .= F.Name . " （" . (F.IsFolder == 0 ? F.Size . " 字节）" : "目录）") . "`n"

    MsgBox, 4, , % Text . "`n将要清空回收站，是否执行？"
    IfMsgBox Yes
    {
        FileRecycleEmpty
    }
return

ListProcess:
    result := ""

    for process in ComObjGet("winmgmts:").ExecQuery("select * from Win32_Process")
    {
        result .= "* | 进程 | " process.Name " | " process.CommandLine "`n"
    }
    Sort, result

    SetCommandFilter("KillProcess|ShowProcess|CountNumber")
    DisplayResult(FilterResult(AlignText(result), Arg))
    TurnOnResultFilter()
return

DiskSpace:
    result := ""

    DriveGet, list, list
    Loop, Parse, list
    {
        drive := A_LoopField ":"
        DriveGet, label, label, %drive%
        DriveGet, cap, capacity, %drive%
        DrivespaceFree, free, %drive%
        SetFormat, float, 5.2
        percent := 100 * (cap - free) / cap
        SetFormat, float, 6.2
        cap /= 1024.0
        free /= 1024.0
        result = %result%* | %drive% | 总共: %cap% G  可用: %free% G | 已使用：%percent%`%  卷标: %label%`n
    }

    DisplayResult(AlignText(result))
return

IncreaseVolume:
    SoundSet, +5
return

DecreaseVolume:
    SoundSet, -5
return

SystemState:
    if (!SetExecInterval(1))
    {
        return
    }

    GMSEx := GlobalMemoryStatusEx()
    result := "* | 状态 | 运行时间 | " Round(A_TickCount / 1000 / 3600, 3) " 小时`n"
    result .= "* | 状态 | CPU 占用 | " CPULoad() "% `n"
    result .= "* | 状态 | 内存占用 | " Round(100 * (GMSEx[2] - GMSEx[3]) / GMSEx[2], 2) "% `n"
    result .= "* | 状态 | 进程总数 | " GetProcessCount() "`n"
    result .= "* | 状态 | 内存总量 | " Round(GMSEx[2] / 1024**2, 2) "MB `n"
    result .= "* | 状态 | 可用内存 | " Round(GMSEx[3] / 1024**2, 2) "MB `n"
    DisplayResult(AlignText(result))
return

KillProcess:
    args := StrSplit(Arg, " ")
    for index, argument in args
    {
        Process, Close, %argument%
    }

    DisplayResult("已尝试杀死 " Arg " 进程")
return

SendToClip:
    clipboard := Arg
    GoSub, Clip
return

ListWindow:
    result := ""

    WinGet, id, list, , , Program Manager
    Loop, %id%
    {
        thisId := id%A_Index%
        WinGetTitle, title, ahk_id %thisId%
        WinGet, name, ProcessName, ahk_id %thisId%
        if (title == "")
        {
            continue
        }
        result .= "* | 窗口 | " name " | " title "`n"
    }

    SetCommandFilter("ActivateWindow|KillProcess")
    DisplayResult(AlignText(result))
    TurnOnResultFilter()
return

ActivateWindow:
    DisplayResult()
    ClearInput()

    if (FullPipeArg != "")
    {
        Loop, Parse, FullPipeArg, `n, `r
        {
            if (A_LoopField == "")
            {
                return
            }
            splitedLine := StrSplit(A_LoopField, " | ")
            WinActivate, % Trim(splitedLine[4])
        }
    }
    else
    {
        for index, argument in StrSplit(Arg, " ")
        {
            WinActivate, ahk_exe %argument%
        }
    }
return

ListAllService:
    result :=
    for service in ComObjGet("winmgmts:").ExecQuery("select * from Win32_Service")
    {
        result .= "* | 服务 | " service.Name " | " service.DisplayName "`n"
    }
    Sort, result

    SetCommandFilter("CountNumber|ShowService")
    DisplayResult(FilterResult(AlignText(result), Arg))
    TurnOnResultFilter()
return

ListRunningService:
    result :=
    for service in ComObjGet("winmgmts:").ExecQuery("select * from Win32_Service")
    {
        if (service.Started != 0)
        {
            result .= "* | 服务 | " service.Name " | " service.DisplayName "`n"
        }
    }
    Sort, result

    SetCommandFilter("CountNumber|ShowService")
    DisplayResult(FilterResult(AlignText(result), Arg))
    TurnOnResultFilter()
return

ShowService:
    result :=
    ; 暂时只支持一个，选得多了查起来太慢
    for service in ComObjGet("winmgmts:")
        .ExecQuery("select * from Win32_Service where Name = '" StrSplit(Arg, " ")[1] "'")
    {
        ; https://msdn.microsoft.com/en-us/library/windows/desktop/aa394418%28v=vs.85%29.aspx
        result .= "* | 服务 | 名称 | " service.Name "`n"
        result .= "* | 服务 | 描述 | " service.Description "`n"
        result .= "* | 服务 | 是否在运行 | " service.Started "`n"
        result .= "* | 服务 | 路径 | " service.PathName "`n"
        result .= "* | 服务 | 进程 ID | " service.ProcessId "`n"
        result .= "* | 服务 | 类型 | " service.ServiceType "`n"
        break
    }

    DisplayResult(AlignText(result))
return

ShowProcess:
    result :=
    ; 暂时只支持一个，选得多了查起来太慢
    for process in ComObjGet("winmgmts:")
        .ExecQuery("select * from Win32_Process where Name = '" StrSplit(Arg, " ")[1] "'")
    {
        ; https://msdn.microsoft.com/en-us/library/windows/desktop/aa394372%28v=vs.85%29.aspx
        result .= "* | 服务 | 名称 | " process.Name "`n"
        result .= "* | 服务 | 描述 | " process.Description "`n"
        result .= "* | 服务 | 命令行 | " process.CommandLine "`n"
        result .= "* | 服务 | 启动时间 | " process.CreationDate "`n"
        result .= "* | 服务 | ID | " process.ProcessId "`n"
        break
    }

    DisplayResult(AlignText(result))
return


use Ctrl-Alt-y/o to move to the left/right viertual desktop. somehow Ctrl-Alt-Shift-y or h does not work well (can move, but launch Office start app, too)

; Tips {{{
; #: win
; !: alt
; ^: ctrl
; +: shift
; &: and
; <: only left, >: only right
; *: wildecard
; ~: pass through
; }}}

; Auto execute section is the region before any return/hotkey {{{
; Windows size
TMargin := 5
BMargin := 5
LMargin := 5
RMargin := 5 ; sidebar = 150px
MinSize := 0.7

; For Terminal/Vim
GroupAdd Terminal, ahk_class PuTTY
GroupAdd Terminal, ahk_class mintty ; cygwin
GroupAdd Terminal, ahk_class TMobaXtermForm
GroupAdd Terminal, ahk_class TFormDetachedTab
GroupAdd Terminal, ahk_class ConsoleWindowClass
GroupAdd Terminal, ahk_exe Hyper.exe
GroupAdd Terminal, ahk_exe powershell.exe
GroupAdd Terminal, ahk_exe vim.exe
GroupAdd TerminalVim, ahk_group Terminal
GroupAdd TerminalVim, ahk_class Vim
GroupAdd TerminalVim, ahk_class mintty
GroupAdd TerminalVim, ahk_class CASCADIA_HOSTING_WINDOW_CLASS
GroupAdd TerminalVim, ahk_exe WindowsTerminal.exe

; For browsers
GroupAdd, Browser, ahk_exe chrome.exe
GroupAdd, Browser, ahk_exe firefox.exe
GroupAdd, Browser, ahk_exe msedge.exe

; External files (Only 1 file, at last of Auto execute section"
#Include %A_LineFile%\..\submodules\vim_ahk\vim.ahk

Return
; }}}

; External files w/o Auto execute section
#Include %A_LineFile%\..\AutoCorrect.ahk

;; Basic Settings, HotKeys, Functions {{{
; Settings

#UseHook On ; Make it a bit slow, but can avoid infinitude loop
            ; Same as "$" for each hotkey
#InstallKeybdHook ; For checking key history
                  ; Use ~500kB memory?

#HotkeyInterval 1000 ; Hotkey inteval (default 2000 milliseconds).
#MaxHotkeysPerInterval 100 ; Max hotkeys perinterval (default 50).

; For HHKB
;vkFFsc079::RCtrl
;vkFFsc07b::LCtrl
; }}}

; Terminal/Vim {{{
; ESC + IME
#IfWInActive, ahk_group TerminalVim
; Use ESC as ` or ESC with long push, especially for HHKB
;Esc:: ; Just send Esc at converting.
;  if(VIM_IME_GET(A)){
;    if(VIM_IME_GetConverting(A)){
;      Send, {Esc}
;    }else{
;      VIM_IME_SET()
;    }
;  }else{
;    Send, {Esc}
;  }
;Return

^[:: ; Go to Normal mode (for vim) with IME off even at converting.
  if(VIM_IME_GetConverting(A)){
    Send, {Esc}
    Sleep 1 ; wait 1 ms (Need to stop converting)
    VIM_IME_SET()
    Send, {Esc}
  }else if(VIM_IME_GET(A)){
    VIM_IME_SET()
    Send, {Esc}
  }else{
    Send, {Esc}
  }
Return

^m::Send, ^m ; Use Ctrl-m as is

; Paste
#IfWInActive, ahk_group Terminal
!v::
  ;StringSplit, strout, clipboard, `n
  ;If(strout0>1 or InStr(clipboard, "sudo")>0){
  ;  MsgBox, 308, Clipboard, %clipboard%`n`n Do you want to paste?
  ;  IfMsgBox, No
  ;  {
  ;    Return
  ;  }
  ;}
  ;SendInput %clipboard%
  ;Return
  Sleep,200
  MouseClick, Right, 50, 50, 1
Return

#IfWInActive, ahk_class Vim
!v::Send, {Alt}ep

; Other than Terminal/Vim
#IfWInNotActive, ahk_group TerminalVim
^[::Send, {Esc}             ; Always C-[ to ESC, like vim
^d::Send, {Del}             ; Always Delete with C-d
; }}} Terminal/Vim

; Power Point {{{
#IfWInActive, ahk_class PP12FrameClass
; Subscript/Superscript
^=::Send, ^tb{Enter}
^+=::Send, ^tp{Enter}
; For JP keyboards
;^-::Send, ^tb{Enter}
;^+-::Send, ^tp{Enter}

; Fonts
^!+s::Send, ^tfsymbol{Enter}
^!+a::Send, ^tfarial{Enter}
^!+h::Send, ^tfhelvetica{Enter}
; }}} Power Point

; Word {{{
#IfWInActive, ahk_class OpusApp
^=::Send, ^tb{Enter}
^+=::Send, ^tp{Enter}
; for JP keyboards
;^-::Send, ^tb{Enter}
;^+-::Send, ^tp{Enter}
; }}} Word

; Explorer {{{
#IfWInActive, ahk_class CabinetWClass
; Next/Previous page
^i::Send, !{Right}
^o::Send, !{Left}
; }}} Explorer

; CLCL {{{
#IfWInActive, ahk_exe CLCL.exe ; does not work...
j::
  Send, {Down}
Return

k::Send, {Up}
; }}} CLCL

; Everthing {{{
#IfWinActive, ahk_class EVERYTHING
Return::
  Send, {Enter}
  Sleep, 200
  IfWinActive, ahk_class EVERYTHING
  {
    Send,{Enter}
    Sleep, 500
  }
  WinActivate, ahk_class EVERYTHING
  Sleep, 200
  Send, {Esc}
Return
; }}} Everything

; Firefox/Chrome/Edge {{{
#IfWinActive, ahk_group Browser
^WheelDown::Send, {WheelDown}
^WheelUp::Send, {WheelUp}
; }}} Firefox/Chrome/Edge

; Global Settings {{{
#if
; Basic Settings {{{

; Suspend
;Esc & Tab::
;  Suspend, Toggle
;  Return
; For Alt-Ctrl Swap (swapped by KeySwap)
; To assign ^Tab, need to add < or > to choose left or right
<^Tab::AltTab
;<+<^Tab::ShiftAltTab ; can not assigned...
;LCtrl & Tab::
;  if GetKeyState("Shift","P"){
;    Send, {ShiftAltTab}
;  }else{
;    Send, {AltTab}
;  }
;Return
;Alt & Tab::
;  if GetKeyState("Shift","P"){
;    Send, ^+{taB}
;  }else{
;    Send, ^{Tab}
;  }
;Return
!Tab::Send, ^{Tab}
!+Tab::Send, ^+{Tab}

;!m::Send, ^m
;^m::Send, !m
;>^m::Send, !m
;Ctrl & Left::Send, !{Left}
;Ctrl & Right::Send, !{Right}

; Cortana
!^f::Send, #s

; CLCL
#c::Send, !c

; Other basic settings
!Space::Send, {vkF3sc029} ; IME by A-Space
^Space::Send, {vkF3sc029} ; IME by C-Space
;{vkF3sc029}               ; 変換
;{vk1Dsc07B}               ; 無変換
!^a::Send, !{Space}n       ; Minimize window
!4::Send, !{F4}           ; Close window
^4::Send, !{F4}           ; Close window
!d::Send, {Del}           ; Always Delete with A-d
;^o::Send,!{Left}          ; Go to previous page
;^i::Send,!{Right}         ; Go to nexe page
^Space::!`                ; IME

^h::Send, {BS}            ; Always BS with C-h
;^h::
;  While GetKeyState("h","p"){
;    Send {BS}
;    TrayTip,Start:,%n%,10,,
;    Sleep 50
;  }
;  return

;^j::Send,{Enter}      ; C-j to Enter

; For HHKB
; ESC to ` like normal keyboard (ESC is placed on the left of 1 in HHKB)
Esc::
  KeyWait, Esc, T0.3
  If (ErrorLevel){
    Send, {Esc}
    KeyWait, Esc
  }else{
    Send, ``
    KeyWait, Esc
  }
Return

; Disable alt to menu
Alt::KeyWait, Alt
LAlt Up::Return
; }}} Basic Settings

; Cursor, Mouse, Window move/size {{{
; Cursor {{{
!^h::Send, {Left}
!^j::Send, {Down}
!^k::Send, {Up}
!^l::Send, {Right}
; }}} Cursor

; Mouse {{{
; Mouse Move
^+h::MouseMove, -10, 0, 0, R
^+j::MouseMove, 0, 10, 0, R
^+k::MouseMove, 0, -10, 0, R
^+l::MouseMove, 10, 0, 0, R

; Click
^+n::MouseClick, Left
^+p::MouseClick, Right
; Right click on current window

; Mouse wheel
!^m::MouseClick, WheelDown, , , 2
!^,::MouseClick, WheelUp, , , 2
; }}} Mouse

; Window move {{{

; Move a little
^+y::
  WinGetPos, X, Y, , , A ;A for Active Window
  WinMove, A, ,X-20, Y,
Return

^+u::
  WinGetPos, X, Y, , , A
  WinMove, A, , X, Y+20
Return

^+i::
  WinGetPos, X, Y, , , A
  WinMove, A, , X, Y-20
Return

^+o::
  WinGetPos, X, Y, , , A
  WinMove, A, , X+20, Y
Return

; Move to a different screen
!^+y:: Send, #^{Left}
!^+u:: Send, #^{Down}
!^+i:: Send, #^{Up}
!^+o:: Send, #^{Right}

; }}} Window move

; Virtual desktop {{{
^!y::Send, #^{Left}
^!o::Send, #^{Right}
; }}} Virtual desktop

; Window size {{{

; Almost full
^!Enter::
!+Enter::
  ;WinGetPos, X, Y, W, H, Program Manager ; Full Desktop
  ;Msgbox, Pos At %X% %Y% %W% %H%
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  ;Msgbox, %MWALeft% %MWATop% %MWARight% %MWABottom%
  WinMove, A, , MWALeft+LMargin, MWATop+TMargin
    , MWARight-MWALeft-LMargin-RMargin
    , MWABottom-MWATop-TMargin-BMargin
Return

; Minsize
^!+Enter::
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  WinMove, A, , MWALeft+LMargin, MWATop+TMargin
    , (MWARight-MWALeft-LMargin-RMargin)*Minsize
    , (MWABottom-MWATop-TMargin-BMargin)*Minsize
Return

; Half size
!+h::
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  WinMove, A, , MWALeft+LMargin, MWATop+TMargin
    , (MWARight-MWALeft-LMargin-RMargin)*0.5
    , MWABottom-MWATop-TMargin-BMargin
Return

!+j::
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  WinMove, A, , MWALeft+LMargin
    , MWATop+(MWABottom-MWATop)*0.5
    , MWARight-MWALeft-LMargin-RMargin
    , (MWABottom-MWATop-TMargin-BMargin)*0.5
Return

!+k::
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  WinMove, A, , MWALeft+LMargin, MWATop+TMargin
    , MWARight-MWALeft-LMargin-RMargin
    , (MWABottom-MWATop-TMargin-BMargin)*0.5
Return

!+l::
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  WinMove, A, , MWALeft+(MWARight-MWALeft)*0.5
    , MWATop+TMargin
    , (MWARight-MWALeft-LMargin-RMargin)*0.5
    , MWABottom-MWATop-TMargin-BMargin
Return

; Resize
!+y::
  WinGetPos, X, Y, W, H, A
  WinMove, A, ,X, Y, W-20, H
Return

!+u::
  WinGetPos, X, Y, W, H, A
  WinMove, A, ,X, Y, W, H+20
Return

!+i::
  WinGetPos, X, Y, W, H, A
  WinMove, A, ,X, Y, W, H-20
Return

!+o::
  WinGetPos, X, Y, W, H, A
  WinMove, A, ,X, Y, W+20, H
Return

; }}} Window size
; }}} Cursor, Mouse, Window move
; }}} Global Settings

; Tips {{{
; #: win
; !: alt
; ^: ctrl
; +: shift
; &: and
; <: only left, >: only right
; *: wildecard
; ~: pass through
; }}}

; Auto execute section is the region before any return/hotkey {{{
; Windows size
TMargin := 5
BMargin := 5
LMargin := 5
RMargin := 5 ; sidebar = 150px
MinSize := 0.7

; For Terminal/Vim
GroupAdd Terminal, ahk_class PuTTY
GroupAdd Terminal, ahk_class mintty ; cygwin
GroupAdd Terminal, ahk_class TMobaXtermForm
GroupAdd Terminal, ahk_class TFormDetachedTab
GroupAdd Terminal, ahk_class ConsoleWindowClass
GroupAdd Terminal, ahk_exe Hyper.exe
GroupAdd Terminal, ahk_exe powershell.exe
GroupAdd Terminal, ahk_exe vim.exe
GroupAdd TerminalVim, ahk_group Terminal
GroupAdd TerminalVim, ahk_class Vim
GroupAdd TerminalVim, ahk_class mintty
GroupAdd TerminalVim, ahk_class CASCADIA_HOSTING_WINDOW_CLASS
GroupAdd TerminalVim, ahk_exe WindowsTerminal.exe

; For browsers
GroupAdd, Browser, ahk_exe chrome.exe
GroupAdd, Browser, ahk_exe firefox.exe
GroupAdd, Browser, ahk_exe msedge.exe

; External files (Only 1 file, at last of Auto execute section"
#Include %A_LineFile%\..\submodules\vim_ahk\vim.ahk

Return
; }}}

; External files w/o Auto execute section
#Include %A_LineFile%\..\AutoCorrect.ahk

;; Basic Settings, HotKeys, Functions {{{
; Settings

#UseHook On ; Make it a bit slow, but can avoid infinitude loop
            ; Same as "$" for each hotkey
#InstallKeybdHook ; For checking key history
                  ; Use ~500kB memory?

#HotkeyInterval 1000 ; Hotkey inteval (default 2000 milliseconds).
#MaxHotkeysPerInterval 100 ; Max hotkeys perinterval (default 50).

; For HHKB
;vkFFsc079::RCtrl
;vkFFsc07b::LCtrl
; }}}

; Terminal/Vim {{{
; ESC + IME
#IfWInActive, ahk_group TerminalVim
; Use ESC as ` or ESC with long push, especially for HHKB
;Esc:: ; Just send Esc at converting.
;  if(VIM_IME_GET(A)){
;    if(VIM_IME_GetConverting(A)){
;      Send, {Esc}
;    }else{
;      VIM_IME_SET()
;    }
;  }else{
;    Send, {Esc}
;  }
;Return

^[:: ; Go to Normal mode (for vim) with IME off even at converting.
  if(VIM_IME_GetConverting(A)){
    Send, {Esc}
    Sleep 1 ; wait 1 ms (Need to stop converting)
    VIM_IME_SET()
    Send, {Esc}
  }else if(VIM_IME_GET(A)){
    VIM_IME_SET()
    Send, {Esc}
  }else{
    Send, {Esc}
  }
Return

^m::Send, ^m ; Use Ctrl-m as is

; Paste
#IfWInActive, ahk_group Terminal
!v::
  ;StringSplit, strout, clipboard, `n
  ;If(strout0>1 or InStr(clipboard, "sudo")>0){
  ;  MsgBox, 308, Clipboard, %clipboard%`n`n Do you want to paste?
  ;  IfMsgBox, No
  ;  {
  ;    Return
  ;  }
  ;}
  ;SendInput %clipboard%
  ;Return
  Sleep,200
  MouseClick, Right, 50, 50, 1
Return

#IfWInActive, ahk_class Vim
!v::Send, {Alt}ep

; Other than Terminal/Vim
#IfWInNotActive, ahk_group TerminalVim
^[::Send, {Esc}             ; Always C-[ to ESC, like vim
^d::Send, {Del}             ; Always Delete with C-d
; }}} Terminal/Vim

; Power Point {{{
#IfWInActive, ahk_class PP12FrameClass
; Subscript/Superscript
^=::Send, ^tb{Enter}
^+=::Send, ^tp{Enter}
; For JP keyboards
;^-::Send, ^tb{Enter}
;^+-::Send, ^tp{Enter}

; Fonts
^!+s::Send, ^tfsymbol{Enter}
^!+a::Send, ^tfarial{Enter}
^!+h::Send, ^tfhelvetica{Enter}
; }}} Power Point

; Word {{{
#IfWInActive, ahk_class OpusApp
^=::Send, ^tb{Enter}
^+=::Send, ^tp{Enter}
; for JP keyboards
;^-::Send, ^tb{Enter}
;^+-::Send, ^tp{Enter}
; }}} Word

; Explorer {{{
#IfWInActive, ahk_class CabinetWClass
; Next/Previous page
^i::Send, !{Right}
^o::Send, !{Left}
; }}} Explorer

; CLCL {{{
#IfWInActive, ahk_exe CLCL.exe ; does not work...
j::
  Send, {Down}
Return

k::Send, {Up}
; }}} CLCL

; Everthing {{{
#IfWinActive, ahk_class EVERYTHING
Return::
  Send, {Enter}
  Sleep, 200
  IfWinActive, ahk_class EVERYTHING
  {
    Send,{Enter}
    Sleep, 500
  }
  WinActivate, ahk_class EVERYTHING
  Sleep, 200
  Send, {Esc}
Return
; }}} Everything

; Firefox/Chrome/Edge {{{
#IfWinActive, ahk_group Browser
^WheelDown::Send, {WheelDown}
^WheelUp::Send, {WheelUp}
; }}} Firefox/Chrome/Edge

; Global Settings {{{
#if
; Basic Settings {{{

; Suspend
;Esc & Tab::
;  Suspend, Toggle
;  Return
; For Alt-Ctrl Swap (swapped by KeySwap)
; To assign ^Tab, need to add < or > to choose left or right
<^Tab::AltTab
;<+<^Tab::ShiftAltTab ; can not assigned...
;LCtrl & Tab::
;  if GetKeyState("Shift","P"){
;    Send, {ShiftAltTab}
;  }else{
;    Send, {AltTab}
;  }
;Return
;Alt & Tab::
;  if GetKeyState("Shift","P"){
;    Send, ^+{taB}
;  }else{
;    Send, ^{Tab}
;  }
;Return
!Tab::Send, ^{Tab}
!+Tab::Send, ^+{Tab}

;!m::Send, ^m
;^m::Send, !m
;>^m::Send, !m
;Ctrl & Left::Send, !{Left}
;Ctrl & Right::Send, !{Right}

; Virtual desktop
^!+h::Send, #^{Left}
^!+l::Send, #^{Right}

; Cortana
!^f::Send, #s

; CLCL
#c::Send, !c

; Other basic settings
!Space::Send, {vkF3sc029} ; IME by A-Space
^Space::Send, {vkF3sc029} ; IME by C-Space
;{vkF3sc029}               ; 変換
;{vk1Dsc07B}               ; 無変換
!^a::Send, !{Space}n       ; Minimize window
!4::Send, !{F4}           ; Close window
^4::Send, !{F4}           ; Close window
!d::Send, {Del}           ; Always Delete with A-d
;^o::Send,!{Left}          ; Go to previous page
;^i::Send,!{Right}         ; Go to nexe page
^Space::!`                ; IME

^h::Send, {BS}            ; Always BS with C-h
;^h::
;  While GetKeyState("h","p"){
;    Send {BS}
;    TrayTip,Start:,%n%,10,,
;    Sleep 50
;  }
;  return

;^j::Send,{Enter}      ; C-j to Enter

; For HHKB
; ESC to ` like normal keyboard (ESC is placed on the left of 1 in HHKB)
Esc::
  KeyWait, Esc, T0.3
  If (ErrorLevel){
    Send, {Esc}
    KeyWait, Esc
  }else{
    Send, ``
    KeyWait, Esc
  }
Return

; Disable alt to menu
Alt::KeyWait, Alt
LAlt Up::Return
; }}} Basic Settings

; Cursor, Mouse, Window move/size {{{
; Cursor {{{
!^h::Send, {Left}
!^j::Send, {Down}
!^k::Send, {Up}
!^l::Send, {Right}
; }}} Cursor

; Mouse {{{
; Mouse Move
^+h::MouseMove, -10, 0, 0, R
^+j::MouseMove, 0, 10, 0, R
^+k::MouseMove, 0, -10, 0, R
^+l::MouseMove, 10, 0, 0, R

; Click
^+n::MouseClick, Left
^+p::MouseClick, Right
; Right click on current window

; Mouse wheel
!^m::MouseClick, WheelDown, , , 2
!^,::MouseClick, WheelUp, , , 2
; }}} Mouse

; Window move {{{

; Move a little
^+y::
  WinGetPos, X, Y, , , A ;A for Active Window
  WinMove, A, ,X-20, Y,
Return

^+u::
  WinGetPos, X, Y, , , A
  WinMove, A, , X, Y+20
Return

^+i::
  WinGetPos, X, Y, , , A
  WinMove, A, , X, Y-20
Return

^+o::
  WinGetPos, X, Y, , , A
  WinMove, A, , X+20, Y
Return

; Move to a different screen
!^+y:: Send, #^{Left}
!^+u:: Send, #^{Down}
!^+i:: Send, #^{Up}
!^+o:: Send, #^{Right}

; }}} Window move

; Window size {{{

; Almost full
^!Enter::
!+Enter::
  ;WinGetPos, X, Y, W, H, Program Manager ; Full Desktop
  ;Msgbox, Pos At %X% %Y% %W% %H%
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  ;Msgbox, %MWALeft% %MWATop% %MWARight% %MWABottom%
  WinMove, A, , MWALeft+LMargin, MWATop+TMargin
    , MWARight-MWALeft-LMargin-RMargin
    , MWABottom-MWATop-TMargin-BMargin
Return

; Minsize
^!+Enter::
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  WinMove, A, , MWALeft+LMargin, MWATop+TMargin
    , (MWARight-MWALeft-LMargin-RMargin)*Minsize
    , (MWABottom-MWATop-TMargin-BMargin)*Minsize
Return

; Half size
!+h::
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  WinMove, A, , MWALeft+LMargin, MWATop+TMargin
    , (MWARight-MWALeft-LMargin-RMargin)*0.5
    , MWABottom-MWATop-TMargin-BMargin
Return

!+j::
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  WinMove, A, , MWALeft+LMargin
    , MWATop+(MWABottom-MWATop)*0.5
    , MWARight-MWALeft-LMargin-RMargin
    , (MWABottom-MWATop-TMargin-BMargin)*0.5
Return

!+k::
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  WinMove, A, , MWALeft+LMargin, MWATop+TMargin
    , MWARight-MWALeft-LMargin-RMargin
    , (MWABottom-MWATop-TMargin-BMargin)*0.5
Return

!+l::
  SysGet, MWA, MonitorWorkArea ; w/o Taskbar
  WinMove, A, , MWALeft+(MWARight-MWALeft)*0.5
    , MWATop+TMargin
    , (MWARight-MWALeft-LMargin-RMargin)*0.5
    , MWABottom-MWATop-TMargin-BMargin
Return

; Resize
!+y::
  WinGetPos, X, Y, W, H, A
  WinMove, A, ,X, Y, W-20, H
Return

!+u::
  WinGetPos, X, Y, W, H, A
  WinMove, A, ,X, Y, W, H+20
Return

!+i::
  WinGetPos, X, Y, W, H, A
  WinMove, A, ,X, Y, W, H-20
Return

!+o::
  WinGetPos, X, Y, W, H, A
  WinMove, A, ,X, Y, W+20, H
Return

; }}} Window size
; }}} Cursor, Mouse, Window move
; }}} Global Settings


userprofile -> home

userprofile -> home

; win: #, ctrl: ^, alt: !, shift: +
#z::
!z::
+z::
temp_txt = %home%\selected_word.txt
tempClipboard = %ClipboardAll%
Clipboard =
Send, ^c
ClipWait, 1
FileDelete, %temp_txt%
if (Clipboard != "") {
    FileAppend, %Clipboard%, %temp_txt%
}
Clipboard = %tempClipboard%  ; ClipboardAll no allowed as an output variable
tempClipboard =
return

; win: #, ctrl: ^, alt: !, shift: +
#z::
!z::
+z::
temp_txt = %userprofile%\selected_word.txt
tempClipboard = %ClipboardAll%
Clipboard =
Send, ^c
ClipWait, 1
FileDelete, %temp_txt%
if (Clipboard != "") {
    FileAppend, %Clipboard%, %temp_txt%
}
Clipboard = %tempClipboard%  ; ClipboardAll no allowed as an output variable
tempClipboard =
return


Fixes overlay hiding code so that it doesn't suppress normal Win key shortcut

; Uncomment if you don't want this script appearing in your system tray
; #NoTrayIcon
#SingleInstance Force
#Persistent
MsgNum := DllCall("RegisterWindowMessage", Str, "VIRTUALDESKTOPGRIDSWITCHER_COMMAND")

exeName := "VirtualDesktopGridSwitcher.exe"

; Launch VirtualDesktopGridManager if it's not already running.
DetectHiddenWindows, On
If !WinExist("ahk_exe " . exeName) {
    Run "../VirtualDesktopGridSwitcher.exe"
}

OnExit, % OnExitFn

overlayVisible := 0

; All commands
GO_UP := 1
GO_LEFT := 2
GO_RIGHT := 3
GO_DOWN := 4
MOVE_UP := 5
MOVE_LEFT := 6
MOVE_RIGHT := 7
MOVE_DOWN := 8
TOGGLE_STICKY := 10
DEBUG_SHOW_CURRENT_WINDOW_HWND := 11
SET_HWND_MESSAGE_TARGET := 12
SWITCHED_DESKTOP := 13
QUIT := 14

OnMessage(MsgNum, "ReceiveMessage")
myHwnd := HexToDec(A_ScriptHwnd)
SendCommand(SET_HWND_MESSAGE_TARGET, myHwnd)

desktopName := Object()
desktopName[0] := "Main"
desktopName[1] := "Work"
desktopName[2] := ""
desktopName[3] := "Chat"
desktopName[4] := ""
desktopName[5] := ""
desktopName[6] := ""
desktopName[7] := "BF"
desktopName[8] := "Music"
return

; Return an HWND that will receive our commands.
GetTargetHwnd() {
    global exeName
    DetectHiddenWindows, On
    WinGet, a, List, ahk_exe %exeName%
    Loop, %a% {
        id := a%A_Index%
        WinGetClass, cls, ahk_id %id%
        ; Skip the "GDI+" window
        If(RegExMatch(cls, "^GDI") = 0) {
            return id
        }
    }
}

; Send a command to VirtualDesktopGridSwitcher
SendCommand(cmd, value) {
    ; All variables are global unless declared to be local
    global
    local id
    id := GetTargetHwnd()
    PostMessage, %MsgNum%, %cmd%, %value%, , ahk_id %id%
}

; Called when VirtualDesktopGridSwitcher sends us a message
ReceiveMessage(cmd, value, msg, hwnd) {
    ; All variables are global unless declared to be local
    global
	local num
	if (cmd = SWITCHED_DESKTOP) {
	    num := value + 1
	    ShowOverlay("Desktop " + num, desktopName[value])
	} else {
	    MsgBox, %cmd%, %value%
	}
}

HexToDec(hex) {
	result := hex + 0
	; result .= ""
	return result
}

ShowOverlay(title, message) {
    global overlayVisible
    overlayVisible := 1
    SysGet, primary, MonitorPrimary
    SysGet, monitor, Monitor, %primary%
	width := 200
	height := 50
	padding := 100
	x := monitorLeft + ((monitorRight - monitorLeft) / 2) - (width / 2)
	y := monitorBottom - height - padding
    SplashImage, Icons/1.ico, BX%x%Y%y%W%width%H%height%, %message%, %title%, ,
}

HideOverlay() {
    global overlayVisible
    overlayVisible := 0
    SplashImage, Off
}

ToggleAlwaysOnTop(hwnd := "") {
    if(hwnd == "") {
        hwnd := WinExist("A")
    }
    WinSet, AlwaysOnTop, Toggle, ahk_id %hwnd%
    ;WinGet, ExStyle, ExStyle, ahk_id %hwnd%
    ;if(ExStyle & 0x8) {
    ;    message := "Always on Top Enabled"
    ;} else {
    ;    message := "Always on Top Disabled"
    ;}
    ;TrayTip, , %message%, 1, 0x10
}

OnExitFn() {
    ; TODO kill the .exe
}

}

;;;;;;;
; Hotkeys.  Customize these to your liking.

^#Left::SendCommand(GO_LEFT, 0)
^#Right::SendCommand(GO_RIGHT, 0)
^#Down::SendCommand(GO_DOWN, 0)
^#Up::SendCommand(GO_UP, 0)
#!Left::SendCommand(MOVE_LEFT, 0)
#!Right::SendCommand(MOVE_RIGHT, 0)
#!Down::SendCommand(MOVE_DOWN, 0)
#!Up::SendCommand(MOVE_UP, 0)
^#S::SendCommand(TOGGLE_STICKY, 0)
^#D::SendCommand(DEBUG_SHOW_CURRENT_WINDOW_HWND, 0)
^#A::ToggleAlwaysOnTop()
^#F::
    MouseGetPos,,,id
    MsgBox, %id%
return
#If overlayVisible
; When either Ctrl or Win is released, the overlay is hidden.
~*Ctrl Up::HideOverlay()
~*LWin Up::HideOverlay()
#If

; Uncomment if you don't want this script appearing in your system tray
; #NoTrayIcon
#SingleInstance Force
#Persistent
MsgNum := DllCall("RegisterWindowMessage", Str, "VIRTUALDESKTOPGRIDSWITCHER_COMMAND")

exeName := "VirtualDesktopGridSwitcher.exe"

; Launch VirtualDesktopGridManager if it's not already running.
DetectHiddenWindows, On
If !WinExist("ahk_exe " . exeName) {
    Run "../VirtualDesktopGridSwitcher.exe"
}

OnExit, % OnExitFn

; All commands
GO_UP := 1
GO_LEFT := 2
GO_RIGHT := 3
GO_DOWN := 4
MOVE_UP := 5
MOVE_LEFT := 6
MOVE_RIGHT := 7
MOVE_DOWN := 8
TOGGLE_STICKY := 10
DEBUG_SHOW_CURRENT_WINDOW_HWND := 11
SET_HWND_MESSAGE_TARGET := 12
SWITCHED_DESKTOP := 13
QUIT := 14

OnMessage(MsgNum, "ReceiveMessage")
myHwnd := HexToDec(A_ScriptHwnd)
SendCommand(SET_HWND_MESSAGE_TARGET, myHwnd)

desktopName := Object()
desktopName[0] := "Main"
desktopName[1] := "Work"
desktopName[2] := ""
desktopName[3] := "Chat"
desktopName[4] := ""
desktopName[5] := ""
desktopName[6] := ""
desktopName[7] := "BF"
desktopName[8] := "Music"
return

; Return an HWND that will receive our commands.
GetTargetHwnd() {
    global exeName
    DetectHiddenWindows, On
    WinGet, a, List, ahk_exe %exeName%
    Loop, %a% {
        id := a%A_Index%
        WinGetClass, cls, ahk_id %id%
        ; Skip the "GDI+" window
        If(RegExMatch(cls, "^GDI") = 0) {
            return id
        }
    }
}

; Send a command to VirtualDesktopGridSwitcher
SendCommand(cmd, value) {
    ; All variables are global unless declared to be local
    global
    local id
    id := GetTargetHwnd()
    PostMessage, %MsgNum%, %cmd%, %value%, , ahk_id %id%
}

; Called when VirtualDesktopGridSwitcher sends us a message
ReceiveMessage(cmd, value, msg, hwnd) {
    ; All variables are global unless declared to be local
    global
	local num
	if (cmd = SWITCHED_DESKTOP) {
	    num := value + 1
	    ShowOverlay("Desktop " + num, desktopName[value])
	} else {
	    MsgBox, %cmd%, %value%
	}
}

HexToDec(hex) {
	result := hex + 0
	; result .= ""
	return result
}

ShowOverlay(title, message) {
    SysGet, primary, MonitorPrimary
    SysGet, monitor, Monitor, %primary%
	width := 200
	height := 50
	padding := 100
	x := monitorLeft + ((monitorRight - monitorLeft) / 2) - (width / 2)
	y := monitorBottom - height - padding
    SplashImage, Icons/1.ico, BX%x%Y%y%W%width%H%height%, %message%, %title%, ,
}

HideOverlay() {
    SplashImage, Off
}

ShouldHideOverlay() {
	if(GetKeyState("Ctrl", "P") = 0 && GetKeyState("LWin", "P") = 0) {
	    return 1
	} else {
	    return 0
	}
}

CheckHideOverlay() {
    if(ShouldHideOverlay() = 1) {
	    HideOverlay()
	}
ToggleAlwaysOnTop(hwnd := "") {
    if(hwnd == "") {
        hwnd := WinExist("A")
    }
    WinSet, AlwaysOnTop, Toggle, ahk_id %hwnd%
    ;WinGet, ExStyle, ExStyle, ahk_id %hwnd%
    ;if(ExStyle & 0x8) {
    ;    message := "Always on Top Enabled"
    ;} else {
    ;    message := "Always on Top Disabled"
    ;}
    ;TrayTip, , %message%, 1, 0x10
}

OnExitFn() {
    ; TODO kill the .exe
}

}

;;;;;;;
; Hotkeys.  Customize these to your liking.

^#Left::SendCommand(GO_LEFT, 0)
^#Right::SendCommand(GO_RIGHT, 0)
^#Down::SendCommand(GO_DOWN, 0)
^#Up::SendCommand(GO_UP, 0)
#!Left::SendCommand(MOVE_LEFT, 0)
#!Right::SendCommand(MOVE_RIGHT, 0)
#!Down::SendCommand(MOVE_DOWN, 0)
#!Up::SendCommand(MOVE_UP, 0)
^#S::SendCommand(TOGGLE_STICKY, 0)
^#D::SendCommand(DEBUG_SHOW_CURRENT_WINDOW_HWND, 0)
^#A::ToggleAlwaysOnTop()
^#F::
    MouseGetPos,,,id
    MsgBox, %id%
return
~*Ctrl Up::CheckHideOverlay()
~*LWin Up::CheckHideOverlay()