$$\newcommand{\eqdef}{\overset{def}{=}}$$

My Technical Notes

Monday, 19 November 2012

AutoHotkey scripts

The following are my AutoHotkey scripts. They are being used to make programming easier.

Because I am having to program both on the local machine and on a remote machine, I need to have a controller.ahk which will shutdown the local instance so it does not interfere with the script.ahk running on the remote server:

controller.ahk


Run "autohotkey" "script.ahk", , , ScriptPID

#Persistent
SetTimer, QuitOnRDPMaximized, 500
return

QuitOnRDPMaximized:
If WinActive("ahk_class TscShellContainerClass")
{
 WinGet, maxOrMin, MinMax, ahk_class TscShellContainerClass

 if (maxOrMin = 0) {
  WinGetPos, PosX, PosY, WinWidth, WinHeight, ahk_class TscShellContainerClass

  if (PosY = 0) {
   ; it is fully maximized therefore end "script.ahk"
   DetectHiddenWindows, On 
   SetTitleMatchMode, 2
   WinClose, script.ahk ahk_class AutoHotkey
   ; Process, Close, %ScriptPID%
   
   ; wait until window gets deactivated so you don't reload it agin
   WinWaitNotActive, ahk_class TscShellContainerClass
   Run "autohotkey" "script.ahk", , , ScriptPID
  }
 }
}
return

script.ahk


#SingleInstance force
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Recommended for catching common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

;;  Character Meaning
;; ^   Control
;; !   Alt
;; +   Shift

;; see http://www.autohotkey.com/docs/Hotkeys.htm
SetScrollLockState, AlwaysOff
SetCapsLockState, AlwaysOff

SendInput_Preserve_Modifiers(input)
{
 SendInputString = %input%
 if (GetKeyState("Shift") = 1) 
 {
  SendInputString = {Shift Down}%SendInputString%{Shift Up}
 }
 
 if (GetKeyState("Control") = 1) 
 {
  SendInputString = {Control Down}%SendInputString%{Control Up}
 }
 
 SendInput, %SendInputString%
}

:O:pcc::
SendRaw <# TODO:  #>
Loop 3
{
 SendInput {Left}
}
return


:O:cc::
SendInput /*   */
Loop 3
{
 SendInput {Left}
}
return

:O:ccc::
SendInput /* TODO:  */
Loop 3
{
 SendInput {Left}
}
return

:O:aa::
SendInput <`%
SendInput --
SendInput {Right}
SendInput --
Loop 3
{
 SendInput {Left}
}
return

:O:aac::
SendInput <`%
SendInput -- TODO:
SendInput {Right}
SendInput --
Loop 3
{
 SendInput {Left}
}
return

:O:hh::
SendRaw <!--  -->
Loop 4
{
 SendInput {Left}
}
return

:O:aac::
SendRaw <!-- TODO:  -->
Loop 4
{
 SendInput {Left}
}
return

;; TODO: combine this with \css
:O:\cs::
SendInput public object Method1(object input)
SendInput {Enter}{{}{Enter}{}}{Up}{Enter}
SendInput return null;
return

;; TODO: combine this with \cs
:O:\css::
SendInput public static object Method1(object input)
SendInput {Enter}{{}{Enter}{}}{Up}{Enter}
SendInput return null;
return

:O:iff::
SendInput if{SPACE}(true){ENTER}{{}{ENTER}{ENTER}{}}{ENTER}else{ENTER}{ENTER}{{}{ENTER}{ENTER}{}}{UP}{UP}{UP}{UP}{UP}
return

;; convert some of the below to use a space instead of a pinkie

ScrollLock::
if (GetKeyState("CapsLock", "T") = 0)
{
 SetCapsLockState, AlwaysOn
}
else
{
 SetCapsLockState, AlwaysOff
}
return

;; We should not have to move our left left pinkie of the CapsLock key in order to 
;; Cut, Copy or Paste
;; This will be used when we have selected our text using CapsLock navigation
;; We do not have to 
;; Copy can be done as {Cut}{Paste} and then {Paste} it where you want it

;; make this mistake sometimes when typing the brackets eg. MyMethod()
CapsLock & 9:: SendInput, (
CapsLock & 0:: SendInput, )

;; next and before line opening / creation (might be removed if I don't see a point in having them.)
;; next and before line opening / creation (might be removed if I don't see a point in having them.)
CapsLock & b:: SendInput_Preserve_Modifiers("{Home}{Enter}{Up}")
CapsLock & n:: SendInput_Preserve_Modifiers("{End}{Enter}")

;; delete button may not be needed
CapsLock & d:: SendInput_Preserve_Modifiers("{Control Down}{Delete}{Control Up}")

;; the navigation keys, up, down, left, right and forward word and backwards word
CapsLock & u:: SendInput_Preserve_Modifiers("{Left}")
CapsLock & o:: SendInput_Preserve_Modifiers("{Right}")
CapsLock & h:: SendInput_Preserve_Modifiers("{Home}")
CapsLock & `;:: SendInput_Preserve_Modifiers("{End}")
CapsLock & i:: SendInput_Preserve_Modifiers("{Up}")
CapsLock & k:: SendInput_Preserve_Modifiers("{Down}")
CapsLock & j:: SendInput_Preserve_Modifiers("{Control Down}{Left}{Control Up}")
CapsLock & l:: SendInput_Preserve_Modifiers("{Control Down}{Right}{Control Up}")
CapsLock & BackSpace:: SendInput, {Control Down}{Delete}{Control Up}

CapsLock & [::
 SendInput {Enter}{{}{Enter}{Enter}{}}{Up}
return

;; alt t IS A TEST FUNCTION
!t::
 Msgbox, tahir
return

CapsLock & m:: SendEvent {Enter}
CapsLock & v:: SendInput ^v
CapsLock & f:: SendInput ^c
CapsLock & g:: SendInput ^v

^!+l::
Run "excel" "H:\WorkLogged\WorkLogged.xlsx"
return

:O:dtt::
SendInput %A_DD%/%A_MM%/%A_YYYY% %A_Hour%:%A_Min% 
return

Pause::
 Suspend
 SetCapsLockState Off
return

No comments: