Home Page
  • May 22, 2024, 02:43:29 pm *
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  


Official site launch very soon, hurrah!

Author Topic: AutoHotKey Scripts  (Read 10953 times)


  • Programmer Person
  • Administrator
  • Hero Member
  • *****
  • Posts: 537
    • View Profile
    • Dakusan's Domain
AutoHotKey Scripts
« on: December 01, 2015, 09:29:01 pm »

Original post for AutoHotKey Scripts can be found at https://www.castledragmire.com/Posts/AutoHotKey_Scripts.
Originally posted on: 12/01/15

In lieu of using my own custom C++ background services to take care of hot key tasks in Windows, I started using AutoHotKey a while back. While it’s not perfect, and it is missing a lot of Win32 API functionality, I am still able to mostly accomplish what I want in it. I was thinking I should add some of the simple scripts I use here.

Center a string within padding characters and output as key-strokes
  • PadText = ~*
  • Length = 43
  • Text = Example Text
  • Result = ~*~*~*~*~*~*~*~*Example Text~*~*~*~*~*~*~*~

;Get the last values
IniRead,TheString,%IniPath%,CenterString,TheString,The String

;Get the input
InputBox,PadText,Center String,Pad Character,,,,,,,,%PadText%
InputBox,NewLength,Center String,New Length,,,,,,,,%NewLength%
InputBox,TheString,Center String,String To Center,,,,,,,,%TheString%

;Cancel on blank pad or invalid number
if StrLen(PadText)==0
   MsgBox,Pad text cannot be blank
if NewLength is not integer
   MsgBox,New length must be an integer

;Save the last values

;Initial padding
   if StrLen(NewString)>=Ceil(PadLen/2)

;Truncate initial padding to at least half
NewString:=Substr(NewString, 1, Ceil(PadLen/2))

;Add the string

;Final padding
   if StrLen(NewString)>=NewLength

;Truncate to proper length
NewString:=Substr(NewString, 1, NewLength)

;Output to console
Send %NewString%

Format rich clipboard text to plain text

clipboard = %clipboard%

Force window to borderless full screen
Description: This takes the active window, removes all window dressing (titlebar, borders, etc), sets its resolution as 1920x1080, and positions the window at 0x0. In other words, this makes your current window take up the entirety of your primary monitor (assuming it has a resolution of 1920x1080).

WinGetActiveTitle, WinTitle
WinSet, Style, -0xC40000, %WinTitle%
WinMove, %WinTitle%, , 0, 0, 1920, 1080

Continually press key on current window
Description: Saves the currently active window (by its title) and focused control object within the window; asks the user for a keypress interval and the key to press; starts to continually press the requested key at the requested interval in the original control (or top level window if an active control is not found); stops via the F11 key.
Note: I had created this to help me get through the LISA intro multiple times.

;Get the current window and control
WinGetActiveTitle, TheTitle
ControlGetFocus FocusedControl, %TheTitle%

;Get the pause interval
InputBox,IntervalTime,Starting script with window '%TheTitle%',Enter pause interval in milliseconds. After submitted`, hold down the key to repeat,,,,,,,,200
if(ErrorLevel || IntervalTime=="") ;Cancel action if blank or cancelled
IntervalTime := IntervalTime+0

;Get the key to keep pressing - Unfortunately, there is no other way I can find to get the currently pressed keycode besides polling all 255 of them
Sleep 500 ;Barrier to make sure one of the initialization keys is not grabbed
Loop {
   TestKey := 0
   Loop {
      SetFormat, INTEGER, H
      HexTextKey := TestKey
      SetFormat, INTEGER, D
      VirtKey = % "vk" . SubStr(HexTextKey, 3)
      if(GetKeyState(VirtKey)=1 || TestKey>255)
   Sleep 500
VirtKey := GetKeyName(VirtKey)

;If a direction key, remap to the actual key
if(TestKey>=0x25 && TestKey<=0x28)
   VirtKey := SubStr(VirtKey, 7)

;Let the user know their key
MsgBox Received key: '%VirtKey%'. You may now let go of the key. Hold F11 to stop the script.

;Continually send the key at the requested interval
SetKeyDelay %KeyDelay% #Interval between up/down keys
Loop {
   ;Press the key
   ControlSend, %FocusedControl%, {%VirtKey% Up}{%VirtKey% Down}, %TheTitle%

   ;Check for the cancel key

   ;Wait the requested interval to press the key again
   Sleep, %IntervalTime%

;Let the user know the script has ended
MsgBox Ending script with window '%TheTitle%'