AHK Scripts

Here are some AutoHotKey (ahk) scripts that i have used in the past for various reasons, usually to expand existing features or in some cases where i couldnt find a utility that what accomplish what i was looking to do. They might be useful to someone.


DOpus_ImageViewer.ahk - Allows you to use additional keys and mouse buttons to navigate images previewed within Directory Opus

; Directory Opus Arrow Key Navigation & MouseWheel Zoom In Image Viewer
; fearless 2013 @ www.LetTheLight.In
#IfWinActive, ahk_class dopus.viewpicframe
	Left::Send {PgUp}
	Up::Send {PgUp}
	Right::Send {PgDn}
	Down::Send {PgDn}
	WheelUp::Send {NumpadAdd}
	WheelDown::Send {NumpadSub}

HashToSlashKey.ahk - Change # key to \ on US logitech keyboard

; replace # key output on logitech slim keyboard to \ (Alt 092)
SendInput {\}

SendFolderToSentTo.ahk - Adds selected folder to the SendTo special folders, allowing you to right click on files and copy them to the target folder by selecting Send To->{Selected Folder} Requires _ShellFolder.au3

; SendFolderToSendTo
;#include '_SendTo.au3'
#include "_ShellFolder.au3"

If $CmdLine[0] = 1 Then
   If $CmdLine[1] = "/install" Then
   ElseIf $CmdLine[1] = "/uninstall" Then
      MsgBox(4096, '', 'SendFolderToSendTo Uninstalled.')
      ;$Dat = $CmdLine[1] & '\'
      ;$sFullPath1 = "\folder1\folder2\folder3\foldern\"
     ; $sLastFolder1 = StringRegExpReplace($Dat, ".*\\(.*)\\\z", "$1")
     ; MsgBox(0, "Last Folder", $sLastFolder1)
      DoSendToShortCut($CmdLine[1] & '\')
   ;MsgBox(4096, '', 'SendFolderToSendTo Installed.')

Func DoInstall()
   _ShellFolder_Install('Send Folder To SendTo') ; Add the running EXE to the Shell ContextMenu. This will only display when selecting a drive and folder.

Func DoUninstall()
   _ShellFolder_Uninstall() ; Remove the running EXE from the Shell ContextMenu.

Func DoSendToShortCut($sFilePath)
   Local Const $bCSIDL_SENDTO = 0x0009
   Local $sSendTo = __SendTo_ShellGetSpecialFolderPath($bCSIDL_SENDTO)
   Local $sCmdLine = ''
   ;Local $sName = $sFilePath
   Local $sName = StringRegExpReplace($sFilePath, ".*\\(.*)\\\z", "$1")
   ;MsgBox(0, "Last Folder", $sLastFolder)   
   ;MsgBox(0, "File Path", $sFilePath)
   MsgBox(0, 'SendFolderToSendTo', 'Shortcut To Folder Created: ' & $sName)
   Return FileCreateShortcut($sFilePath, $sSendTo & '\' & $sName & '.lnk', $sSendTo, $sCmdLine)
   ;MsgBox(4096, '', $CmdLine[1]) ; Retrieve the first file.
  ; _SendTo_Install($CmdLine[1], $CmdLine[1],) ; Add the current folder to the SendTo Folder.

Func DeleteExistingShortCutIfExists($sFilePath)
    Local Const $bCSIDL_SENDTO = 0x0009
    Local $aFileGetShortcut = 0, $sFileName = ''
    Local $sName = StringRegExpReplace($sFilePath, ".*\\(.*)\\\z", "$1")
    If FileExists($sFilePath) = 0 Then
       Return SetError(1, 0, 0)
    Local $iStringLen = StringLen($sName), $sSendTo = __SendTo_ShellGetSpecialFolderPath($bCSIDL_SENDTO)
    Local $hSearch = FileFindFirstFile($sSendTo & '\' & '*.lnk')
    If $hSearch = -1 Then
        Return SetError(1, 0, 0)

    While 1
        $sFileName = FileFindNextFile($hSearch)
        If @error Then
        If StringLeft($sFileName, $iStringLen) = $sName Then
            $aFileGetShortcut = FileGetShortcut($sSendTo & '\' & $sFileName)
            If @error Then
            If $aFileGetShortcut[0] = $sFilePath Then
                FileDelete($sSendTo & '\' & $sFileName)
    Return FileClose($hSearch)

; #FUNCTION# ====================================================================================================================
; Name...........: __SendTo_ShellGetSpecialFolderPath renamed from _WinAPI_ShellGetSpecialFolderPath
; Description....: Retrieves the path of a special folder.
; Syntax.........: __SendTo_ShellGetSpecialFolderPath($CSIDL [, $fCreate = 0])
; Parameters.....: $CSIDL   - The CSIDL ($CSIDL_*) that identifies the folder of interest.
;                  $fCreate - Specifies whether the folder should be created if it does not already exist, valid values:
;                  |TRUE    - The folder is created.
;                  |FALSE   - The folder is not created. (Default)
; Return values..: Success  - The full path of a special folder.
;                  Failure  - Empty string and sets the @error flag to non-zero.
; Author.........: Yashied
; Modified.......:
; Remarks........: WinAPIEx.au3 - http://www.autoitscript.com/forum/topic/98712-winapiex-udf
; Related........:
; Link...........: @@MsdnLink@@ SHGetSpecialFolderPath
; Example........: Yes
; ===============================================================================================================================
Func __SendTo_ShellGetSpecialFolderPath($CSIDL, $fCreate = 0)
    Local $tPath = DllStructCreate('wchar[1024]')
    Local $aReturn = DllCall('shell32.dll', 'int', 'SHGetSpecialFolderPathW', 'hwnd', 0, 'ptr', DllStructGetPtr($tPath), 'int', $CSIDL, 'int', $fCreate)

    If (@error) Or (Not $aReturn[0]) Then
        Return SetError(1, 0, '')
    Return DllStructGetData($tPath, 1)
EndFunc   ;==>__SendTo_ShellGetSpecialFolderPath

ToggleSound.ahk - Switches current default sound output from speakers to headset or vice versa. headset.ico and speaker.ico are standard 32x32x24 icons placed in the root of the system drive to show in the traybar icon which one is currently activated.

; ToggleSound
#NoTrayIcon MsgN := DllCall( "RegisterWindowMessage", Str,"TaskbarCreated" ) OnMessage( MsgN, "WM_TASKBAR_CREATED" ) Global T #noenv #singleinstance, force DetectHiddenWindows, On onexit, Exit Gui, +lastfound hwnd_gui1 := winexist() ;~ Gui, Color, CC0000 ; There is no need for this line because we are changing the background color anyway. ;hInst := DllCall("GetModuleHandle", "str", "z:\windows\system32\mmres.dll") ;hIcon := DllCall("LoadImage", "Uint", hInst, "Uint", 1, "Uint", 1, "int", 48, "int", 48, "Uint", 0x8000) global tray_icon_headset := ".\headset.ico" global tray_icon_speaker := ".\speaker.ico" Gui, Font, s22 bold, Segoe UI Gui, Add, Text, w700 vUpdateText, Gui, -Border +AlwaysOnTop ; Creating NOTIFYICONDATA : http://msdn.microsoft.com/en-us/library/aa930660.aspx ; Thanks Lexikos : http://www.autohotkey.com/forum/viewtopic.php?p=162175#162175 PID := DllCall("GetCurrentProcessId"), VarSetCapacity( NID,444,0 ), NumPut( 444,NID ) DetectHiddenWindows, On NumPut( WinExist( A_ScriptFullPath " ahk_class AutoHotkey ahk_pid " PID),NID,4 ) ;DetectHiddenWindows, Off NumPut( 1028,NID,8 ), NumPut( 2,NID,12 ), NumPut( hIcon,NID,20 ) Menu, Tray, Icon ; Shows the default Tray icon DllCall( "shell32\Shell_NotifyIcon", UInt,0x1, UInt,&NID ) ; and we immediately modify it. Menu, Tray, Icon, %tray_icon_speaker% Menu, Tray, Tip, ToggleSound: ALT + `` To Toggle Between Headset & Speaker ;ChangeSound(2) ;T := !!T ; Toggle variable return !`:: ; ` Changes between devices T := !T ; Toggle variable If (T) { ChangeSound(1) Menu, Tray, Icon, %tray_icon_headset% Menu, Tray, Tip, ToggleSound: Logitech USB headset ;DllCall( "shell32\Shell_NotifyIcon", UInt,0x1, UInt,&NID ) ;Font color Change Gui, Font, cBlue ; Use a new line for font information GuiControl, Font, UpdateText ; Put the above font into effect for a control. Gui, Color, 999999 ;CC0000 GuiControl,, UpdateText, Default audio device set to Logitech USB headset Gui, Show, Autosize NoActivate } else { ChangeSound(2) Menu, Tray, Icon, %tray_icon_speaker% Menu, Tray, Tip, ToggleSound: Realtek Speakers ;DllCall( "shell32\Shell_NotifyIcon", UInt,0x1, UInt,&NID ) ;Font color Change Gui, Font, cGreen ; Use a new line for font information GuiControl, Font, UpdateText ; Put the above font into effect for a control. Gui, Color, 999999 ;0000CC GuiControl,, UpdateText, Default audio device set to Realtek Speakers Gui, Show, Autosize NoActivate } Settimer, GuiOff, -1000 ; Turns off the tooltip in 3 seconds by executing the ToolTipOff label once (once because the number of milliseconds on the timer is negative) return GuiOff: ; Turns off the gui when executed by the settimer Gui, Hide return ChangeSound(DeviceNum) { ;Run rundll32.exe shell32.dll`,Control_RunDLL "mmsys.cpl",, Hide, PID ;winwait, ahk_pid %pid% ;hwnd := WinExist("ahk_pid " . PID) ;Set_Parent(hwnd_gui1, hwnd) ;Return Run, mmsys.cpl,,hide ; Run the sound device window WinWaitActive, Sound ahk_class #32770 ; wait for it to be active ControlSend, SysListView321,{Down %DeviceNum%}, Sound ahk_class #32770 ; Send the down key to highlight our device ControlClick, Button2, Sound ahk_class #32770 ; Click button 2 which is the 'Set Default' button WinClose, Sound ahk_class #32770 ; Close the window } WM_TASKBAR_CREATED() { Global NID WinWait ahk_class Shell_TrayWnd DllCall( "shell32\Shell_NotifyIcon", UInt,0x1, UInt,&NID ) ;ChangeSound(2) } Exit: Process, Close, %pid% ExitApp Set_Parent(Parent_hwmd, Child_hwnd) { Return DllCall("SetParent", "uint", Child_hwnd, "uint", Parent_hwmd) }

Login Form